fix water shader switching bug

new-script-api
Miloslav Číž 7 years ago
parent 8a1e0e74fd
commit a7cad65aab

@ -1548,14 +1548,19 @@ void SkyManager::update(float duration)
{ {
if (!mEnabled) if (!mEnabled)
{ {
mRainIntensityUniform->set((float) 0.0); if (mRainIntensityUniform)
mRainIntensityUniform->set((float) 0.0);
return; return;
} }
if (mIsStorm || (!hasRain() && !mParticleNode)) if (mRainIntensityUniform)
mRainIntensityUniform->set((float) 0.0); {
else if (mIsStorm || (!hasRain() && !mParticleNode))
mRainIntensityUniform->set((float) mWeatherAlpha); mRainIntensityUniform->set((float) 0.0);
else
mRainIntensityUniform->set((float) mWeatherAlpha);
}
if (mIsStorm) if (mIsStorm)
{ {

@ -416,13 +416,14 @@ Water::Water(osg::Group *parent, osg::Group* sceneRoot, Resource::ResourceSystem
setHeight(mTop); setHeight(mTop);
mRainIntensityUniform = NULL;
updateWaterMaterial(); updateWaterMaterial();
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
} }
osg::Uniform *Water::getRainIntensityUniform() osg::Uniform *Water::getRainIntensityUniform()
{ {
return mRainIntensityUniform; return mRainIntensityUniform.get();
} }
void Water::updateWaterMaterial() void Water::updateWaterMaterial()
@ -556,7 +557,6 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R
program->addShader(fragmentShader); program->addShader(fragmentShader);
shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON); shaderStateset->setAttributeAndModes(program, osg::StateAttribute::ON);
mRainIntensityUniform = new osg::Uniform("rainIntensity",(float) 0.0);
shaderStateset->addUniform(mRainIntensityUniform); shaderStateset->addUniform(mRainIntensityUniform);
node->setStateSet(shaderStateset); node->setStateSet(shaderStateset);

@ -51,7 +51,7 @@ namespace MWRender
{ {
static const int CELL_SIZE = 8192; static const int CELL_SIZE = 8192;
osg::Uniform* mRainIntensityUniform; osg::ref_ptr<osg::Uniform> mRainIntensityUniform;
osg::ref_ptr<osg::Group> mParent; osg::ref_ptr<osg::Group> mParent;
osg::ref_ptr<osg::Group> mSceneRoot; osg::ref_ptr<osg::Group> mSceneRoot;

Loading…
Cancel
Save