diff --git a/apps/openmw/mwrender/renderingmanager.cpp b/apps/openmw/mwrender/renderingmanager.cpp index cdf4ed16a..aa5240618 100644 --- a/apps/openmw/mwrender/renderingmanager.cpp +++ b/apps/openmw/mwrender/renderingmanager.cpp @@ -210,7 +210,7 @@ namespace MWRender settings->setReceivesShadowTraversalMask(~0u); //settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::PERSPECTIVE_SHADOW_MAP); - settings->setBaseShadowTextureUnit(1); + settings->setBaseShadowTextureUnit(7); //settings->setMinimumShadowMapNearFarRatio(0); //settings->setNumShadowMapsPerLight(1); //settings->setShadowMapProjectionHint(osgShadow::ShadowSettings::ORTHOGRAPHIC_SHADOW_MAP); diff --git a/apps/openmw/mwrender/shadow.cpp b/apps/openmw/mwrender/shadow.cpp index 915979bac..347952b4c 100644 --- a/apps/openmw/mwrender/shadow.cpp +++ b/apps/openmw/mwrender/shadow.cpp @@ -51,7 +51,7 @@ namespace MWRender "} \n"; - MWShadow::MWShadow() : debugCamera(new osg::Camera), debugProgram(new osg::Program), testTex(new osg::Texture2D) + MWShadow::MWShadow() : debugCamera(new osg::Camera), debugProgram(new osg::Program), debugTextureUnit(0) { debugCamera->setViewport(0, 0, 200, 200); debugCamera->setRenderOrder(osg::Camera::POST_RENDER); @@ -67,13 +67,9 @@ namespace MWRender debugCamera->addChild(debugGeometry); osg::ref_ptr stateSet = debugGeometry->getOrCreateStateSet(); stateSet->setAttributeAndModes(debugProgram, osg::StateAttribute::ON); - osg::ref_ptr textureUniform = new osg::Uniform("texture", 0); + osg::ref_ptr textureUniform = new osg::Uniform("texture", debugTextureUnit); //textureUniform->setType(osg::Uniform::SAMPLER_2D); stateSet->addUniform(textureUniform.get()); - - testTex->setDataVariance(osg::Object::DYNAMIC); - osg::ref_ptr testImage = osgDB::readRefImageFile("resources/mygui/openmw.png"); - testTex->setImage(testImage); } class VDSMCameraCullCallback : public osg::NodeCallback @@ -560,10 +556,7 @@ namespace MWRender { osg::ref_ptr texture = sd->_texture; osg::ref_ptr stateSet = debugGeometry->getOrCreateStateSet(); - if (true) - stateSet->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); - else - stateSet->setTextureAttributeAndModes(0, testTex, osg::StateAttribute::ON); + stateSet->setTextureAttributeAndModes(debugTextureUnit, texture, osg::StateAttribute::ON); unsigned int traversalMask = cv.getTraversalMask(); cv.setTraversalMask(debugGeometry->getNodeMask()); diff --git a/apps/openmw/mwrender/shadow.hpp b/apps/openmw/mwrender/shadow.hpp index 4a4e8b8a5..a941f9c2e 100644 --- a/apps/openmw/mwrender/shadow.hpp +++ b/apps/openmw/mwrender/shadow.hpp @@ -12,13 +12,13 @@ namespace MWRender virtual void cull(osgUtil::CullVisitor& cv); protected: + const int debugTextureUnit; + osg::ref_ptr debugCamera; osg::ref_ptr debugProgram; osg::ref_ptr debugGeometry; - - osg::ref_ptr testTex; }; } diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index 42949dccb..4046386dd 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -46,6 +46,7 @@ varying vec4 passColor; varying vec3 passViewPos; varying vec3 passNormal; +uniform int shadowTextureUnit0; varying vec4 shadowSpaceCoords; #include "lighting.glsl" @@ -104,6 +105,6 @@ void main(void) passNormal = gl_Normal.xyz; // This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner. - mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]); + mat4 eyePlaneMat = mat4(gl_EyePlaneS[shadowTextureUnit0], gl_EyePlaneT[shadowTextureUnit0], gl_EyePlaneR[shadowTextureUnit0], gl_EyePlaneQ[shadowTextureUnit0]); shadowSpaceCoords = viewPos * eyePlaneMat; } diff --git a/files/shaders/terrain_vertex.glsl b/files/shaders/terrain_vertex.glsl index 89a2307a1..17a9c436e 100644 --- a/files/shaders/terrain_vertex.glsl +++ b/files/shaders/terrain_vertex.glsl @@ -14,6 +14,7 @@ varying vec4 passColor; varying vec3 passViewPos; varying vec3 passNormal; +uniform int shadowTextureUnit0; varying vec4 shadowSpaceCoords; #include "lighting.glsl" @@ -38,6 +39,6 @@ void main(void) uv = gl_MultiTexCoord0.xy; // This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner. - mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]); + mat4 eyePlaneMat = mat4(gl_EyePlaneS[shadowTextureUnit0], gl_EyePlaneT[shadowTextureUnit0], gl_EyePlaneR[shadowTextureUnit0], gl_EyePlaneQ[shadowTextureUnit0]); shadowSpaceCoords = viewPos * eyePlaneMat; } diff --git a/files/shaders/water_vertex.glsl b/files/shaders/water_vertex.glsl index 513edc730..6aaa0537c 100644 --- a/files/shaders/water_vertex.glsl +++ b/files/shaders/water_vertex.glsl @@ -4,6 +4,7 @@ varying vec3 screenCoordsPassthrough; varying vec4 position; varying float depthPassthrough; +uniform int shadowTextureUnit0; varying vec4 shadowSpaceCoords; void main(void) @@ -23,6 +24,6 @@ void main(void) depthPassthrough = gl_Position.z; // This matrix has the opposite handedness to the others used here, so multiplication must have the vector to the left. Alternatively it could be transposed after construction, but that's extra work for the GPU just to make the code look a tiny bit cleaner. - mat4 eyePlaneMat = mat4(gl_EyePlaneS[1], gl_EyePlaneT[1], gl_EyePlaneR[1], gl_EyePlaneQ[1]); + mat4 eyePlaneMat = mat4(gl_EyePlaneS[shadowTextureUnit0], gl_EyePlaneT[shadowTextureUnit0], gl_EyePlaneR[shadowTextureUnit0], gl_EyePlaneQ[shadowTextureUnit0]); shadowSpaceCoords = (gl_ModelViewMatrix * gl_Vertex) * eyePlaneMat; }