From fddf7b4dd059eae8c0b0a536d8914471d7869642 Mon Sep 17 00:00:00 2001 From: scrawl Date: Thu, 1 Mar 2012 14:35:39 +0100 Subject: [PATCH] terrain material now supports point lights --- apps/openmw/mwrender/terrain.cpp | 10 +-- apps/openmw/mwrender/terrainmaterial.cpp | 93 ++++++++++++++++++++---- apps/openmw/mwrender/terrainmaterial.hpp | 2 + 3 files changed, 84 insertions(+), 21 deletions(-) diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp index 30e0823f94..df5bba7c46 100644 --- a/apps/openmw/mwrender/terrain.cpp +++ b/apps/openmw/mwrender/terrain.cpp @@ -29,10 +29,10 @@ namespace MWRender static_cast(activeProfile); mTerrainGlobals->setMaxPixelError(8); - //mTerrainGlobals->setLayerBlendMapSize(SPLIT_TERRAIN ? 256 : 1024); - //mTerrainGlobals->setLightMapSize(SPLIT_TERRAIN ? 256 : 1024); - //mTerrainGlobals->setCompositeMapSize(SPLIT_TERRAIN ? 256 : 1024); - //mTerrainGlobals->setDefaultGlobalColourMapSize(256); + mTerrainGlobals->setLayerBlendMapSize(SPLIT_TERRAIN ? 256 : 1024); + mTerrainGlobals->setLightMapSize(SPLIT_TERRAIN ? 256 : 1024); + mTerrainGlobals->setCompositeMapSize(SPLIT_TERRAIN ? 256 : 1024); + mTerrainGlobals->setDefaultGlobalColourMapSize(256); //10 (default) didn't seem to be quite enough mTerrainGlobals->setSkirtSize(128); @@ -266,7 +266,7 @@ namespace MWRender Ogre::TexturePtr normDisp = getNormalDisp("textures\\" + texture); - //terrainData->layerList[position].worldSize = 256; + terrainData->layerList[position].worldSize = 256; terrainData->layerList[position].textureNames.push_back("textures\\" + texture); //Normal map. This should be removed but it would require alterations to diff --git a/apps/openmw/mwrender/terrainmaterial.cpp b/apps/openmw/mwrender/terrainmaterial.cpp index 8985fc8ae2..9121da793b 100644 --- a/apps/openmw/mwrender/terrainmaterial.cpp +++ b/apps/openmw/mwrender/terrainmaterial.cpp @@ -36,6 +36,8 @@ THE SOFTWARE. #include "OgreHardwarePixelBuffer.h" #include "OgreShadowCameraSetupPSSM.h" +#define POINTLIGHTS + namespace Ogre { //--------------------------------------------------------------------- @@ -218,6 +220,22 @@ namespace Ogre } + int TerrainMaterialGeneratorB::SM2Profile::getNumberOfLightsSupported() const + { + #ifndef POINTLIGHTS + return 1; + #else + // number of supported lights depends on the number of available constant registers, + // which in turn depends on the shader profile used + if (GpuProgramManager::getSingleton().isSyntaxSupported("ps_3_0") + || GpuProgramManager::getSingleton().isSyntaxSupported("ps_4_0") + || GpuProgramManager::getSingleton().isSyntaxSupported("fp40") + ) + return 32; + else + return 8; + #endif + } //--------------------------------------------------------------------- MaterialPtr TerrainMaterialGeneratorB::SM2Profile::generate(const Terrain* terrain) { @@ -542,9 +560,15 @@ namespace Ogre params->setIgnoreMissingParams(true); params->setNamedAutoConstant("ambient", GpuProgramParameters::ACT_AMBIENT_LIGHT_COLOUR); - params->setNamedAutoConstant("lightPosObjSpace", GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, 0); - params->setNamedAutoConstant("lightDiffuseColour", GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, 0); - //params->setNamedAutoConstant("lightSpecularColour", GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, 0); + + for (int i=0; igetNumberOfLightsSupported(); ++i) + { + params->setNamedAutoConstant("lightPosObjSpace"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_POSITION_OBJECT_SPACE, i); + params->setNamedAutoConstant("lightDiffuseColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_DIFFUSE_COLOUR, i); + params->setNamedAutoConstant("lightAttenuation"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_ATTENUATION, i); + //params->setNamedAutoConstant("lightSpecularColour"+StringConverter::toString(i), GpuProgramParameters::ACT_LIGHT_SPECULAR_COLOUR, i); + } + params->setNamedAutoConstant("eyePosObjSpace", GpuProgramParameters::ACT_CAMERA_POSITION_OBJECT_SPACE); params->setNamedAutoConstant("fogColour", GpuProgramParameters::ACT_FOG_COLOUR); @@ -945,10 +969,25 @@ namespace Ogre outStream << // Only 1 light supported in this version // deferred shading profile / generator later, ok? :) - "uniform float3 ambient,\n" - "uniform float4 lightPosObjSpace,\n" - "uniform float3 lightDiffuseColour,\n" - //"uniform float3 lightSpecularColour,\n" + "uniform float3 ambient,\n"; + + + for (int i=0; igetNumberOfLightsSupported(); ++i) + { + outStream << + "uniform float4 lightPosObjSpace"<getNumberOfLightsSupported(); ++i) + outStream << + " float3 lightDir"<getNumberOfLightsSupported(); ++i) + { + outStream << " float3 halfAngle"<getNumberOfLightsSupported(); ++i) + outStream << " outputCol.rgb += litRes"<isLayerSpecularMappingEnabled()) diff --git a/apps/openmw/mwrender/terrainmaterial.hpp b/apps/openmw/mwrender/terrainmaterial.hpp index eaa5572ee7..7c0b87ce46 100644 --- a/apps/openmw/mwrender/terrainmaterial.hpp +++ b/apps/openmw/mwrender/terrainmaterial.hpp @@ -142,6 +142,8 @@ namespace Ogre */ bool getReceiveDynamicShadowsLowLod() const { return mLowLodShadows; } + int getNumberOfLightsSupported() const; + /// Internal bool _isSM3Available() const { return mSM3Available; }