From cf95226d795ca9acd40b99a22e398fb373cb5bb3 Mon Sep 17 00:00:00 2001 From: torcs-ng Date: Tue, 30 Apr 2013 19:51:44 +0000 Subject: [PATCH] update SDRender git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@5421 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 3c4304deb20514cf7376dbf38256246389600a89 Former-commit-id: f9d430d268049a782808423fae4f35bb16851306 --- src/modules/graphic/osggraph/OsgRender.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/modules/graphic/osggraph/OsgRender.cpp b/src/modules/graphic/osggraph/OsgRender.cpp index 67c19cc33..82daad579 100644 --- a/src/modules/graphic/osggraph/OsgRender.cpp +++ b/src/modules/graphic/osggraph/OsgRender.cpp @@ -227,9 +227,9 @@ osg::ref_ptr SDRender::Init(osg::Group *m_sceneroot, tTrack *track) stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON); osg::Material* material = new osg::Material; - material->setColorMode(osg::Material::OFF); // switch glColor usage off - stateSet->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); - stateSet->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); + //material->setColorMode(osg::Material::OFF); // switch glColor usage off + stateSet->setAttributeAndModes(material, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); + stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); osg::LightSource* lightSource = new osg::LightSource; lightSource->getLight()->setDataVariance(osg::Object::DYNAMIC); @@ -256,8 +256,10 @@ osg::ref_ptr SDRender::Init(osg::Group *m_sceneroot, tTrack *track) sunLight->setStateSetModes(*stateSet,osg::StateAttribute::ON); osg::Vec3f sun_position = thesky->sunposition(); - osg::Vec4f position(sun_position, 0); + osg::Vec3f sun_direction = -sun_position; + osg::Vec4f position(sun_position, 1.0f); sunLight->getLight()->setPosition(position); + sunLight->getLight()->setDirection(sun_direction); osg::Group* skyGroup = new osg::Group; osg::StateSet* skySS = skyGroup->getOrCreateStateSet(); @@ -265,9 +267,10 @@ osg::ref_ptr SDRender::Init(osg::Group *m_sceneroot, tTrack *track) skyGroup->addChild(thesky->getPreRoot()); sunLight->addChild(skyGroup); mRoot->addChild(sceneGroup); + mRoot->setStateSet(setFogState().get()); mRoot->addChild(sunLight); //mRoot->addChild(lightSource); - mRoot->setStateSet(setFogState().get()); + // Clouds are added to the scene graph later stateSet = mRoot->getOrCreateStateSet(); @@ -395,11 +398,12 @@ osg::ref_ptr< osg::StateSet> SDRender::setFogState() osg::ref_ptr fog = new osg::Fog(); //The fog object fog->setMode(osg::Fog::EXP2); //Fog type fog->setDensity(fog_exp2_density); //Fog density - fog->setEnd(thesky->get_visibility()); fog->setColor(SceneFog); //Fog color + fog->setFogCoordinateSource(osg::Fog::FRAGMENT_DEPTH); osg::ref_ptr< osg::StateSet> fogState (new osg::StateSet); - fogState->setAttributeAndModes(fog.get(),osg::StateAttribute::ON); - fogState->setMode(GL_FOG,osg::StateAttribute::ON); + fogState->setAttributeAndModes(fog.get(), osg::StateAttribute::ON); + + fogState->setMode(GL_FOG, osg::StateAttribute::ON); return fogState;