1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-21 12:09:41 +00:00

Use diffuse alpha to fade Sun

This commit is contained in:
slothlife 2015-08-05 21:03:21 -05:00
parent ea2f88a355
commit f2e51b0579

View file

@ -321,12 +321,12 @@ private:
int mMeshType; int mMeshType;
}; };
// A base class for the sun and moons. Must be stored in an osg::ref_ptr due to being /// A base class for the sun and moons.
// derived from osg::Referenced. /// \note Must be stored in an osg::ref_ptr due to being derived from osg::Referenced.
class CelestialBody : public SceneUtil::StateSetUpdater class CelestialBody : public SceneUtil::StateSetUpdater
{ {
public: public:
CelestialBody(osg::Group* parentNode, float scaleFactor = 1.f, int numUvSets=1) CelestialBody(osg::Group* parentNode, float scaleFactor, int numUvSets)
{ {
mGeode = new osg::Geode; mGeode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(numUvSets); osg::ref_ptr<osg::Geometry> geom = createTexturedQuad(numUvSets);
@ -365,35 +365,26 @@ class Sun : public CelestialBody
public: public:
Sun(osg::Group* parentNode, Resource::TextureManager& textureManager) Sun(osg::Group* parentNode, Resource::TextureManager& textureManager)
: CelestialBody(parentNode, 1.0f, 1) : CelestialBody(parentNode, 1.0f, 1)
, mColor(1.0f, 1.0f, 1.0f, 1.0f) , mTextureManager(textureManager)
, mDummyTexture(textureManager.getWarningTexture()) , mColor(0.0f, 0.0f, 0.0f, 1.0f)
{ {
osg::ref_ptr<osg::Texture2D> tex = textureManager.getTexture2D("textures/tx_sun_05.dds",
osg::Texture::CLAMP,
osg::Texture::CLAMP);
mTransform->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
mTransform->getOrCreateStateSet()->setAttributeAndModes(createUnlitMaterial(), osg::StateAttribute::ON);
} }
virtual void setDefaults(osg::StateSet* stateset) virtual void setDefaults(osg::StateSet* stateset)
{ {
osg::ref_ptr<osg::TexEnvCombine> texEnv(new osg::TexEnvCombine); osg::ref_ptr<osg::Texture2D> tex = mTextureManager.getTexture2D("textures/tx_sun_05.dds",
texEnv->setCombine_Alpha(osg::TexEnvCombine::MODULATE); osg::Texture::CLAMP,
texEnv->setSource0_Alpha(osg::TexEnvCombine::PREVIOUS); osg::Texture::CLAMP);
texEnv->setSource1_Alpha(osg::TexEnvCombine::CONSTANT);
texEnv->setCombine_RGB(osg::TexEnvCombine::REPLACE);
texEnv->setSource0_RGB(osg::TexEnvCombine::PREVIOUS);
texEnv->setConstantColor(osg::Vec4f(1.0f, 1.0f, 1.0f, 1.0f));
stateset->setTextureAttributeAndModes(1, mDummyTexture, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); stateset->setTextureAttributeAndModes(0, tex, osg::StateAttribute::ON);
stateset->setTextureAttributeAndModes(1, texEnv, osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE); stateset->setAttributeAndModes(createAlphaTrackingUnlitMaterial(),
osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE);
} }
virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*) virtual void apply(osg::StateSet* stateset, osg::NodeVisitor*)
{ {
osg::TexEnvCombine* texEnv = static_cast<osg::TexEnvCombine*>(stateset->getTextureAttribute(1, osg::StateAttribute::TEXENV)); osg::Material* mat = static_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
texEnv->setConstantColor(mColor); mat->setDiffuse(osg::Material::FRONT_AND_BACK, mColor);
} }
virtual void adjustTransparency(const float ratio) virtual void adjustTransparency(const float ratio)
@ -412,9 +403,8 @@ public:
} }
private: private:
Resource::TextureManager& mTextureManager;
osg::Vec4f mColor; osg::Vec4f mColor;
osg::ref_ptr<osg::Texture2D> mDummyTexture;
}; };
class Moon : public CelestialBody class Moon : public CelestialBody
@ -522,7 +512,6 @@ public:
} }
private: private:
Resource::TextureManager& mTextureManager; Resource::TextureManager& mTextureManager;
Type mType; Type mType;
MoonState::Phase mPhase; MoonState::Phase mPhase;