mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-05 22:45:33 +00:00
Correct moon blending
This commit is contained in:
parent
0c4ebee6b3
commit
e0dfc1425e
2 changed files with 64 additions and 47 deletions
|
@ -288,10 +288,11 @@ public:
|
||||||
|
|
||||||
void setDirection(const osg::Vec3f& direction)
|
void setDirection(const osg::Vec3f& direction)
|
||||||
{
|
{
|
||||||
mTransform->setPosition(direction*1000.f);
|
osg::Vec3f normalizedDirection = direction / direction.length();
|
||||||
|
mTransform->setPosition(normalizedDirection*1000.f);
|
||||||
|
|
||||||
osg::Quat quat;
|
osg::Quat quat;
|
||||||
quat.makeRotate(osg::Vec3f(0,0,1), direction);
|
quat.makeRotate(osg::Vec3f(0,0,1), normalizedDirection);
|
||||||
mTransform->setAttitude(quat);
|
mTransform->setAttitude(quat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,36 +357,13 @@ public:
|
||||||
|
|
||||||
void setTextures(const std::string& phaseTex, const std::string& circleTex)
|
void setTextures(const std::string& phaseTex, const std::string& circleTex)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
|
osg::ref_ptr<osg::Texture2D> phaseTexPtr = mSceneManager->getTextureManager()->getTexture2D(phaseTex,
|
||||||
|
|
||||||
osg::ref_ptr<osg::Texture2D> moonTex = mSceneManager->getTextureManager()->getTexture2D(circleTex,
|
|
||||||
osg::Texture::CLAMP, osg::Texture::CLAMP);
|
osg::Texture::CLAMP, osg::Texture::CLAMP);
|
||||||
|
|
||||||
// stage 0: render the moon circle in atmosphere color
|
osg::ref_ptr<osg::Texture2D> circleTexPtr = mSceneManager->getTextureManager()->getTexture2D(circleTex,
|
||||||
stateset->setTextureAttributeAndModes(0, moonTex, osg::StateAttribute::ON);
|
|
||||||
|
|
||||||
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
|
|
||||||
texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT);
|
|
||||||
texEnv->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // atmospherecolor
|
|
||||||
|
|
||||||
stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON);
|
|
||||||
|
|
||||||
// stage 1: render the "lit" side of the moon blended over the circle
|
|
||||||
osg::ref_ptr<osg::Texture2D> moonTex2 = mSceneManager->getTextureManager()->getTexture2D(phaseTex,
|
|
||||||
osg::Texture::CLAMP, osg::Texture::CLAMP);
|
osg::Texture::CLAMP, osg::Texture::CLAMP);
|
||||||
|
|
||||||
stateset->setTextureAttributeAndModes(1, moonTex2, osg::StateAttribute::ON);
|
mUpdater->setTextures(phaseTexPtr, circleTexPtr);
|
||||||
|
|
||||||
osg::ref_ptr<osg::TexEnvCombine> texEnv2 = new osg::TexEnvCombine;
|
|
||||||
texEnv2->setCombine_RGB(osg::TexEnvCombine::INTERPOLATE);
|
|
||||||
texEnv2->setCombine_Alpha(osg::TexEnvCombine::MODULATE);
|
|
||||||
texEnv2->setSource0_Alpha(osg::TexEnvCombine::CONSTANT);
|
|
||||||
texEnv2->setConstantColor(osg::Vec4f(1.f, 1.f, 1.f, 1.f));
|
|
||||||
texEnv2->setSource2_RGB(osg::TexEnvCombine::TEXTURE);
|
|
||||||
|
|
||||||
stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON);
|
|
||||||
|
|
||||||
mTransform->setStateSet(stateset);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPhase(const Phase& phase)
|
void setPhase(const Phase& phase)
|
||||||
|
@ -425,43 +403,75 @@ public:
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MoonUpdater()
|
MoonUpdater()
|
||||||
: mAlpha(1.f)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setDefaults(osg::StateSet *stateset)
|
virtual void setDefaults(osg::StateSet *stateset)
|
||||||
{
|
{
|
||||||
|
stateset->setTextureAttributeAndModes(0, mPhaseTex, osg::StateAttribute::ON);
|
||||||
|
osg::ref_ptr<osg::TexEnvCombine> texEnv = new osg::TexEnvCombine;
|
||||||
|
texEnv->setCombine_RGB(osg::TexEnvCombine::MODULATE);
|
||||||
|
texEnv->setSource0_RGB(osg::TexEnvCombine::CONSTANT);
|
||||||
|
texEnv->setSource1_RGB(osg::TexEnvCombine::TEXTURE);
|
||||||
|
texEnv->setConstantColor(osg::Vec4f(1.f, 0.f, 0.f, 1.f)); // fade * MoonRedColor
|
||||||
|
stateset->setTextureAttributeAndModes(0, texEnv, osg::StateAttribute::ON);
|
||||||
|
|
||||||
|
stateset->setTextureAttributeAndModes(1, mCircleTex, osg::StateAttribute::ON);
|
||||||
|
osg::ref_ptr<osg::TexEnvCombine> texEnv2 = new osg::TexEnvCombine;
|
||||||
|
texEnv2->setCombine_RGB(osg::TexEnvCombine::ADD);
|
||||||
|
texEnv2->setCombine_Alpha(osg::TexEnvCombine::REPLACE);
|
||||||
|
texEnv2->setSource0_Alpha(osg::TexEnvCombine::TEXTURE);
|
||||||
|
texEnv2->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
|
||||||
|
texEnv2->setSource1_RGB(osg::TexEnvCombine::CONSTANT);
|
||||||
|
texEnv2->setConstantColor(osg::Vec4f(0.f, 0.f, 0.f, 1.f)); // atmospherecolor
|
||||||
|
stateset->setTextureAttributeAndModes(1, texEnv2, osg::StateAttribute::ON);
|
||||||
|
|
||||||
stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
stateset->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*)
|
virtual void apply(osg::StateSet *stateset, osg::NodeVisitor*)
|
||||||
{
|
{
|
||||||
osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
|
osg::TexEnvCombine* texEnv = static_cast<osg::TexEnvCombine*>(stateset->getTextureAttribute(0, osg::StateAttribute::TEXENV));
|
||||||
mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, mAlpha));
|
texEnv->setConstantColor(mMoonColor);
|
||||||
|
|
||||||
|
osg::TexEnvCombine* texEnv2 = static_cast<osg::TexEnvCombine*>(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV));
|
||||||
|
texEnv2->setConstantColor(mAtmosphereColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setAlpha(float alpha)
|
|
||||||
|
void setAtmosphereColor(const osg::Vec4f& color)
|
||||||
{
|
{
|
||||||
mAlpha = alpha;
|
mAtmosphereColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setMoonColor(const osg::Vec4f& color)
|
||||||
|
{
|
||||||
|
mMoonColor = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextures(osg::ref_ptr<osg::Texture2D> phaseTex, osg::ref_ptr<osg::Texture2D> circleTex)
|
||||||
|
{
|
||||||
|
mPhaseTex = phaseTex;
|
||||||
|
mCircleTex = circleTex;
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float mAlpha;
|
osg::Vec4f mAtmosphereColor;
|
||||||
|
osg::Vec4f mMoonColor;
|
||||||
|
osg::ref_ptr<osg::Texture2D> mPhaseTex;
|
||||||
|
osg::ref_ptr<osg::Texture2D> mCircleTex;
|
||||||
};
|
};
|
||||||
|
|
||||||
void setAlpha(float alpha)
|
|
||||||
{
|
|
||||||
mUpdater->setAlpha(alpha);
|
|
||||||
}
|
|
||||||
|
|
||||||
void setAtmosphereColor(const osg::Vec4f& color)
|
void setAtmosphereColor(const osg::Vec4f& color)
|
||||||
{
|
{
|
||||||
// TODO
|
mUpdater->setAtmosphereColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setColor(const osg::Vec4f& color)
|
void setColor(const osg::Vec4f& color)
|
||||||
{
|
{
|
||||||
// TODO
|
mUpdater->setMoonColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getPhaseInt() const
|
unsigned int getPhaseInt() const
|
||||||
|
@ -508,6 +518,8 @@ SkyManager::SkyManager(osg::Group* parentNode, Resource::SceneManager* sceneMana
|
||||||
, mRainFrequency(1)
|
, mRainFrequency(1)
|
||||||
, mEnabled(true)
|
, mEnabled(true)
|
||||||
, mSunEnabled(true)
|
, mSunEnabled(true)
|
||||||
|
, mMasserFade(0.f)
|
||||||
|
, mSecundaFade(0.f)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<CameraRelativeTransform> skyroot (new CameraRelativeTransform);
|
osg::ref_ptr<CameraRelativeTransform> skyroot (new CameraRelativeTransform);
|
||||||
skyroot->setNodeMask(Mask_Sky);
|
skyroot->setNodeMask(Mask_Sky);
|
||||||
|
@ -568,6 +580,8 @@ void SkyManager::create()
|
||||||
mRootNode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
|
mRootNode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
|
||||||
mRootNode->getOrCreateStateSet()->setMode(GL_FOG, osg::StateAttribute::OFF);
|
mRootNode->getOrCreateStateSet()->setMode(GL_FOG, osg::StateAttribute::OFF);
|
||||||
|
|
||||||
|
mMoonScriptColor = fallback->getFallbackColour("Moons_Script_Color");
|
||||||
|
|
||||||
mCreated = true;
|
mCreated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -628,9 +642,8 @@ void SkyManager::update(float duration)
|
||||||
mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
|
mMasser->setPhase( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
|
||||||
mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
|
mSecunda->setPhase ( static_cast<Moon::Phase>( (int) ((mDay % 32)/4.f)) );
|
||||||
|
|
||||||
//const MWWorld::Fallback* fallback=MWBase::Environment::get().getWorld()->getFallback();
|
mMasser->setColor(osg::Vec4f(mMasserFade,mMasserFade,mMasserFade,1));
|
||||||
//mSecunda->setColour ( mMoonRed ? fallback->getFallbackColour("Moons_Script_Color") : ColourValue(1,1,1,1));
|
mSecunda->setColor(mMoonRed ? (mMoonScriptColor * mSecundaFade) : osg::Vec4f(mSecundaFade,mSecundaFade,mSecundaFade,1));
|
||||||
//mMasser->setColour (ColourValue(1,1,1,1));
|
|
||||||
|
|
||||||
if (mSunEnabled)
|
if (mSunEnabled)
|
||||||
{
|
{
|
||||||
|
@ -766,6 +779,8 @@ void SkyManager::setWeather(const MWWorld::WeatherResult& weather)
|
||||||
mSkyColour = weather.mSkyColor;
|
mSkyColour = weather.mSkyColor;
|
||||||
|
|
||||||
mAtmosphereUpdater->setEmissionColor(mSkyColour);
|
mAtmosphereUpdater->setEmissionColor(mSkyColour);
|
||||||
|
mMasser->setAtmosphereColor(mSkyColour);
|
||||||
|
mSecunda->setAtmosphereColor(mSkyColour);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mFogColour != weather.mFogColor)
|
if (mFogColour != weather.mFogColor)
|
||||||
|
@ -900,14 +915,12 @@ void SkyManager::setLightningStrength(const float factor)
|
||||||
|
|
||||||
void SkyManager::setMasserFade(const float fade)
|
void SkyManager::setMasserFade(const float fade)
|
||||||
{
|
{
|
||||||
if (!mCreated) return;
|
mMasserFade = fade;
|
||||||
mMasser->setAlpha(fade);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyManager::setSecundaFade(const float fade)
|
void SkyManager::setSecundaFade(const float fade)
|
||||||
{
|
{
|
||||||
if (!mCreated) return;
|
mSecundaFade = fade;
|
||||||
mSecunda->setAlpha(fade);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkyManager::setDate(int day, int month)
|
void SkyManager::setDate(int day, int month)
|
||||||
|
|
|
@ -154,6 +154,10 @@ namespace MWRender
|
||||||
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
bool mSunEnabled;
|
bool mSunEnabled;
|
||||||
|
|
||||||
|
osg::Vec4f mMoonScriptColor;
|
||||||
|
float mMasserFade;
|
||||||
|
float mSecundaFade;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue