Merge pull request #1519 from drummyfish/rainfix

fix rain ripple regression (bug #4169)
pull/324/head
scrawl 7 years ago committed by GitHub
commit 4437a72e47

@ -252,6 +252,7 @@ namespace MWRender
sceneRoot->setName("Scene Root"); sceneRoot->setName("Scene Root");
mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager())); mSky.reset(new SkyManager(sceneRoot, resourceSystem->getSceneManager()));
mSky->setCamera(mViewer->getCamera()); mSky->setCamera(mViewer->getCamera());
mSky->setRainIntensityUniform(mWater->getRainIntensityUniform()); mSky->setRainIntensityUniform(mWater->getRainIntensityUniform());

@ -416,9 +416,9 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
setHeight(mTop); setHeight(mTop);
updateWaterMaterial();
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0); mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
updateWaterMaterial();
} }
osg::Uniform *Water::getRainIntensityUniform() osg::Uniform *Water::getRainIntensityUniform()
@ -517,6 +517,7 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
osg::ref_ptr<osg::Shader> fragmentShader (shaderMgr.getShader("water_fragment.glsl", defineMap, osg::Shader::FRAGMENT)); osg::ref_ptr<osg::Shader> fragmentShader (shaderMgr.getShader("water_fragment.glsl", defineMap, osg::Shader::FRAGMENT));
osg::ref_ptr<osg::Texture2D> normalMap (new osg::Texture2D(readPngImage(mResourcePath + "/shaders/water_nm.png"))); osg::ref_ptr<osg::Texture2D> normalMap (new osg::Texture2D(readPngImage(mResourcePath + "/shaders/water_nm.png")));
if (normalMap->getImage()) if (normalMap->getImage())
normalMap->getImage()->flipVertical(); normalMap->getImage()->flipVertical();
normalMap->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT); normalMap->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
@ -531,6 +532,7 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
shaderStateset->setTextureAttributeAndModes(0, normalMap, osg::StateAttribute::ON); shaderStateset->setTextureAttributeAndModes(0, normalMap, osg::StateAttribute::ON);
shaderStateset->setTextureAttributeAndModes(1, reflection->getReflectionTexture(), osg::StateAttribute::ON); shaderStateset->setTextureAttributeAndModes(1, reflection->getReflectionTexture(), osg::StateAttribute::ON);
if (refraction) if (refraction)
{ {
shaderStateset->setTextureAttributeAndModes(2, refraction->getRefractionTexture(), osg::StateAttribute::ON); shaderStateset->setTextureAttributeAndModes(2, refraction->getRefractionTexture(), osg::StateAttribute::ON);
@ -552,13 +554,13 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
shaderStateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF); shaderStateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
shaderStateset->addUniform(mRainIntensityUniform.get());
osg::ref_ptr<osg::Program> program (new osg::Program); osg::ref_ptr<osg::Program> program (new osg::Program);
program->addShader(vertexShader); program->addShader(vertexShader);
program->addShader(fragmentShader); program->addShader(fragmentShader);
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON); shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
shaderStateset->addUniform(mRainIntensityUniform);
node->setStateSet(shaderStateset); node->setStateSet(shaderStateset);
node->setUpdateCallback(NULL); node->setUpdateCallback(NULL);
} }

Loading…
Cancel
Save