Re: [osg-users] osg::Light Simple Question ?
Hi, isnt there missing a *setMode*( GL_LIGHT1, osg::StateAttribute::ON ); for your terrain group? (or did I miss something?) Peter http://osghelp.com On Sat, Jul 19, 2008 at 12:39 AM, Ümit Uzun [EMAIL PROTECTED] wrote: Hi All, I have an simple question about light the terrain model problem. I have added two sphere(osg::Sphere) and one terrain(JoeDirt.flt) to the scene. I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get success on the terrain model. What can I do to effect the terrain with green light? I have tried this code block; -- *int main() { osgViewer::Viewer viewer; osg::ref_ptrosg::Group root (new osg::Group); osg::ref_ptrosg::MatrixTransform terrainScaleMAT (new osg::MatrixTransform); osg::Matrix terrainScaleMatrix; terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f); //Lighting code osg::ref_ptrosg::Group lightGroup (new osg::Group); osg::ref_ptrosg::StateSet lightSS (root-getOrCreateStateSet()); osg::ref_ptrosg::LightSource lightSource1 = new osg::LightSource; // create a local light. osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f)); osg::ref_ptrosg::Light myLight = new osg::Light; myLight-setLightNum(1); myLight-setPosition(lightPosition); myLight-setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); myLight-setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f)); myLight-setConstantAttenuation(1.0f); lightSource1-setLight(myLight.get()); lightSource1-setLocalStateSetModes(osg::StateAttribute::ON); lightSource1-setStateSetModes(*lightSS,osg::StateAttribute::ON); lightGroup-addChild(lightSource1.get()); //Light markers: small spheres osg::ref_ptrosg::Geode lightMarkerGeode (new osg::Geode); lightMarkerGeode-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(-5.0f,-2.0f,3.0f),0.5f))); //lightMarkerGeode-getOrCreateStateSet()-setMode(GL_LIGHTING,osg::StateAttribute::OFF); //Second light marker lightMarkerGeode-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(2.0f,-1.0f,3.0f),0.5f))); //Loading the terrain node osg::ref_ptrosg::Node terrainnode (osgDB::readNodeFile(JoeDirt.flt)); terrainScaleMAT-addChild(terrainnode.get()); terrainScaleMAT-setMatrix(terrainScaleMatrix); //adding the terrain node to the root node root-addChild(terrainScaleMAT.get()); //lighting code root-addChild(lightGroup.get()); //Adding the light marker geode root-addChild(lightMarkerGeode.get()); // add the state manipulator viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()-getOrCreateStateSet()) ); viewer.setSceneData( root.get() ); return (viewer.run()); }* -- ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- Regards, Peter Wraae Marino www.osghelp.com - OpenSceneGraph support site ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Light Simple Question ?
Thanks for reply, I have converted terrain model to osg and opened it with text editor. osg file format like below; -- Group { name db nodeMask 0x cullingActive TRUE num_children 1 Geode { DataVariance STATIC name p1_437 nodeMask 0x cullingActive TRUE StateSet { UniqueID StateSet_0 DataVariance STATIC rendering_hint DEFAULT_BIN renderBinMode INHERIT GL_CULL_FACE ON GL_LIGHTING OFF Material { ColorMode OFF ambientColor 0.722 0.722 0.729 1 diffuseColor 0.918 0.918 0.918 1 specularColor 0.137 0.137 0.137 1 emissionColor 0 0 0 1 shininess 10 } CullFace { UniqueID CullFace_1 mode BACK } textureUnit 0 { GL_TEXTURE_2D ON Texture2D { file Cell 23.rgb wrap_s REPEAT wrap_t REPEAT wrap_r CLAMP min_filter LINEAR mag_filter LINEAR maxAnisotropy 1 borderColor 0 0 0 0 borderWidth 0 useHardwareMipMapGeneration TRUE unRefImageDataAfterApply TRUE internalFormatMode USE_IMAGE_DATA_FORMAT resizeNonPowerOfTwo TRUE } TexEnv { mode MODULATE } } } num_drawables 1 Geometry { DataVariance STATIC useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 1 { DrawArrays QUADS 0 1600 } .. . .. etc. -- The TexEnv configuration have MODULATE mode. And I have changed it to GL_MODULATE and GL_LIGHTING OFF to ON but there is no light effect on terrain too. Then I deleted the TexEnv code block from the osg file format then lighting not effect too. Peter, I added lightSS-setMode(GL_LIGHTING,osg::StateAttribute::ON); pattern to my code but there is no change on the state of terrain too. Jean, if I write a node visitor for TexEnv, I thing there won't be any change too, because of I have removed the TexEnv pattern from osg file format but there wasn't any change on terrain. Any idea for lightiing the terrain like other components. Thanks for all advices. Best Regards. Ümit UZUN 2008/7/19 Peter Wraae Marino [EMAIL PROTECTED]: Hi, isnt there missing a *setMode*( GL_LIGHT1, osg::StateAttribute::ON ); for your terrain group? (or did I miss something?) Peter http://osghelp.com On Sat, Jul 19, 2008 at 12:39 AM, Ümit Uzun [EMAIL PROTECTED] wrote: Hi All, I have an simple question about light the terrain model problem. I have added two sphere(osg::Sphere) and one terrain(JoeDirt.flt) to the scene. I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get success on the terrain model. What can I do to effect the terrain with green light? I have tried this code block; -- *int main() { osgViewer::Viewer viewer; osg::ref_ptrosg::Group root (new osg::Group); osg::ref_ptrosg::MatrixTransform terrainScaleMAT (new osg::MatrixTransform); osg::Matrix terrainScaleMatrix; terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f); //Lighting code osg::ref_ptrosg::Group lightGroup (new osg::Group); osg::ref_ptrosg::StateSet lightSS (root-getOrCreateStateSet()); osg::ref_ptrosg::LightSource lightSource1 = new osg::LightSource; // create a local light. osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f)); osg::ref_ptrosg::Light myLight = new osg::Light; myLight-setLightNum(1); myLight-setPosition(lightPosition); myLight-setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); myLight-setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f)); myLight-setConstantAttenuation(1.0f); lightSource1-setLight(myLight.get()); lightSource1-setLocalStateSetModes(osg::StateAttribute::ON); lightSource1-setStateSetModes(*lightSS,osg::StateAttribute::ON); lightGroup-addChild(lightSource1.get()); //Light markers: small spheres osg::ref_ptrosg::Geode lightMarkerGeode (new osg::Geode); lightMarkerGeode-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(-5.0f,-2.0f,3.0f),0.5f))); //lightMarkerGeode-getOrCreateStateSet()-setMode(GL_LIGHTING,osg::StateAttribute::OFF); //Second light marker lightMarkerGeode-addDrawable(new osg::ShapeDrawable(new osg::Sphere(osg::Vec3f(2.0f,-1.0f,3.0f),0.5f))); //Loading the terrain node osg::ref_ptrosg::Node terrainnode (osgDB::readNodeFile(JoeDirt.flt));
Re: [osg-users] osg::Light Simple Question ?
Does your terrain does have Normals ? Also you have a scale on your terrain (and a non-uniform scale at that) so you WILL have to re-normalize your normals See http://www.vis-sim.com/osg/osg_faq_1.htm#f19 _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ümit Uzun Sent: Saturday, July 19, 2008 6:11 AM To: OpenSceneGraph Users Subject: Re: [osg-users] osg::Light Simple Question ? Thanks for reply, I have converted terrain model to osg and opened it with text editor. osg file format like below; -- Group { name db nodeMask 0x cullingActive TRUE num_children 1 Geode { DataVariance STATIC name p1_437 nodeMask 0x cullingActive TRUE StateSet { UniqueID StateSet_0 DataVariance STATIC rendering_hint DEFAULT_BIN renderBinMode INHERIT GL_CULL_FACE ON GL_LIGHTING OFF Material { ColorMode OFF ambientColor 0.722 0.722 0.729 1 diffuseColor 0.918 0.918 0.918 1 specularColor 0.137 0.137 0.137 1 emissionColor 0 0 0 1 shininess 10 } CullFace { UniqueID CullFace_1 mode BACK } textureUnit 0 { GL_TEXTURE_2D ON Texture2D { file Cell 23.rgb wrap_s REPEAT wrap_t REPEAT wrap_r CLAMP min_filter LINEAR mag_filter LINEAR maxAnisotropy 1 borderColor 0 0 0 0 borderWidth 0 useHardwareMipMapGeneration TRUE unRefImageDataAfterApply TRUE internalFormatMode USE_IMAGE_DATA_FORMAT resizeNonPowerOfTwo TRUE } TexEnv { mode MODULATE } } } num_drawables 1 Geometry { DataVariance STATIC useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 1 { DrawArrays QUADS 0 1600 } .. . .. etc. -- The TexEnv configuration have MODULATE mode. And I have changed it to GL_MODULATE and GL_LIGHTING OFF to ON but there is no light effect on terrain too. Then I deleted the TexEnv code block from the osg file format then lighting not effect too. Peter, I added lightSS-setMode(GL_LIGHTING,osg::StateAttribute::ON); pattern to my code but there is no change on the state of terrain too. Jean, if I write a node visitor for TexEnv, I thing there won't be any change too, because of I have removed the TexEnv pattern from osg file format but there wasn't any change on terrain. Any idea for lightiing the terrain like other components. Thanks for all advices. Best Regards. Ümit UZUN 2008/7/19 Peter Wraae Marino [EMAIL PROTECTED]: Hi, isnt there missing a setMode( GL_LIGHT1, osg::StateAttribute::ON ); for your terrain group? (or did I miss something?) Peter http://osghelp.com http://osghelp.com/ On Sat, Jul 19, 2008 at 12:39 AM, Ümit Uzun [EMAIL PROTECTED] wrote: Hi All, I have an simple question about light the terrain model problem. I have added two sphere(osg::Sphere) and one terrain(JoeDirt.flt) to the scene. I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get success on the terrain model. What can I do to effect the terrain with green light? I have tried this code block; -- int main() { osgViewer::Viewer viewer; osg::ref_ptrosg::Group root (new osg::Group); osg::ref_ptrosg::MatrixTransform terrainScaleMAT (new osg::MatrixTransform); osg::Matrix terrainScaleMatrix; terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f); //Lighting code osg::ref_ptrosg::Group lightGroup (new osg::Group); osg::ref_ptrosg::StateSet lightSS (root-getOrCreateStateSet()); osg::ref_ptrosg::LightSource lightSource1 = new osg::LightSource; // create a local light. osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f)); osg::ref_ptrosg::Light myLight = new osg::Light; myLight-setLightNum(1); myLight-setPosition(lightPosition); myLight-setAmbient(osg::Vec4(0.2f,0.2f,0.2f,1.0f)); myLight-setDiffuse(osg::Vec4(0.1f,0.4f,0.1f,1.0f)); myLight-setConstantAttenuation(1.0f); lightSource1-setLight(myLight.get()); lightSource1-setLocalStateSetModes(osg::StateAttribute::ON); lightSource1-setStateSetModes(*lightSS,osg::StateAttribute::ON); lightGroup-addChild(lightSource1.get()); //Light markers: small spheres osg::ref_ptrosg::Geode lightMarkerGeode (new osg::Geode); lightMarkerGeode-addDrawable(new osg::ShapeDrawable(new osg
Re: [osg-users] osg::Light Simple Question ?
Hi Gordon, I have tried terrainScaleMAT-getOrCreateStateSet()-setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON ); pattern but the result is same. There is no light effect on the terrain. I don't understand why? I can change the light effect for the spheres by lightMarkerGeode-getOrCreateStateSet()-setMode(GL_LIGHTING,osg::StateAttribute::OFF or ON); but same code for terrainnode isn't working. Thanks for all replies, Ümit UZUN 2008/7/19 Gordon Tomlinson [EMAIL PROTECTED]: Does your terrain does have Normals ? Also you have a scale on your terrain (and a non-uniform scale at that) so you WILL have to re-normalize your normals See http://www.vis-sim.com/osg/osg_faq_1.htm#f19 -- *From:* [EMAIL PROTECTED] [mailto: [EMAIL PROTECTED] *On Behalf Of *Ümit Uzun *Sent:* Saturday, July 19, 2008 6:11 AM *To:* OpenSceneGraph Users *Subject:* Re: [osg-users] osg::Light Simple Question ? Thanks for reply, I have converted terrain model to osg and opened it with text editor. osg file format like below; -- Group { name db nodeMask 0x cullingActive TRUE num_children 1 Geode { DataVariance STATIC name p1_437 nodeMask 0x cullingActive TRUE StateSet { UniqueID StateSet_0 DataVariance STATIC rendering_hint DEFAULT_BIN renderBinMode INHERIT GL_CULL_FACE ON GL_LIGHTING OFF Material { ColorMode OFF ambientColor 0.722 0.722 0.729 1 diffuseColor 0.918 0.918 0.918 1 specularColor 0.137 0.137 0.137 1 emissionColor 0 0 0 1 shininess 10 } CullFace { UniqueID CullFace_1 mode BACK } textureUnit 0 { GL_TEXTURE_2D ON Texture2D { file Cell 23.rgb wrap_s REPEAT wrap_t REPEAT wrap_r CLAMP min_filter LINEAR mag_filter LINEAR maxAnisotropy 1 borderColor 0 0 0 0 borderWidth 0 useHardwareMipMapGeneration TRUE unRefImageDataAfterApply TRUE internalFormatMode USE_IMAGE_DATA_FORMAT resizeNonPowerOfTwo TRUE } TexEnv { mode MODULATE } } } num_drawables 1 Geometry { DataVariance STATIC useDisplayList TRUE useVertexBufferObjects FALSE PrimitiveSets 1 { DrawArrays QUADS 0 1600 } .. . .. etc. -- The TexEnv configuration have MODULATE mode. And I have changed it to GL_MODULATE and GL_LIGHTING OFF to ON but there is no light effect on terrain too. Then I deleted the TexEnv code block from the osg file format then lighting not effect too. Peter, I added lightSS-setMode(GL_LIGHTING,osg::StateAttribute::ON); pattern to my code but there is no change on the state of terrain too. Jean, if I write a node visitor for TexEnv, I thing there won't be any change too, because of I have removed the TexEnv pattern from osg file format but there wasn't any change on terrain. Any idea for lightiing the terrain like other components. Thanks for all advices. Best Regards. Ümit UZUN 2008/7/19 Peter Wraae Marino [EMAIL PROTECTED]: Hi, isnt there missing a *setMode*( GL_LIGHT1, osg::StateAttribute::ON ); for your terrain group? (or did I miss something?) Peter http://osghelp.com On Sat, Jul 19, 2008 at 12:39 AM, Ümit Uzun [EMAIL PROTECTED] wrote: Hi All, I have an simple question about light the terrain model problem. I have added two sphere(osg::Sphere) and one terrain(JoeDirt.flt) to the scene. I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get success on the terrain model. What can I do to effect the terrain with green light? I have tried this code block; -- *int main() { osgViewer::Viewer viewer; osg::ref_ptrosg::Group root (new osg::Group); osg::ref_ptrosg::MatrixTransform terrainScaleMAT (new osg::MatrixTransform); osg::Matrix terrainScaleMatrix; terrainScaleMatrix.makeScale(0.05f,0.05f,0.03f); //Lighting code osg::ref_ptrosg::Group lightGroup (new osg::Group); osg::ref_ptrosg::StateSet lightSS (root-getOrCreateStateSet()); osg::ref_ptrosg::LightSource lightSource1 = new osg::LightSource; // create a local light. osg::Vec4f lightPosition (osg::Vec4f(0.0,0.0,3.0,1.0f)); osg::ref_ptrosg::Light myLight = new osg::Light; myLight
Re: [osg-users] osg::Light Simple Question ?
Hello Ümit, I have tried terrainScaleMAT-getOrCreateStateSet()-setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON ); pattern but the result is same. There is no light effect on the terrain. I don't understand why? As Gordon said, check if your terrain has normals in the first place... Rescaling non-existing normals won't do anything :-) In your .osg file, check for normalArray under your Geometry, and check that normalBinding is set to PER_VERTEX. If the model has no normals, you can generate them with a modeling tool or use the osgUtil::SmoothingVisitor to create smooth normals across the surface. And BTW, yes you're right that the two suggestions I gave before were mutually exclusive, i.e. if you checked your model and changed the TexEnv in it you don't need a NodeVisitor to do the same thing... Oh, just another little thing, are you sure you're reloading the .osg model and not the original one without your changes? J-S -- __ Jean-Sebastien Guay[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Light Simple Question ?
The reason you need GL_RESCALE_NORMAL is because you have scaled your terrain. OpenGL by default does NOT scale normal on a scale matrix because the act of rescale requires the use of sqr roots and this is expensive. when you have a lot of them every frame ( see any good OpenGL book for details) I would recommend that you create your terrain to the correct size and not scale at run time, _ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Ümit Uzun Sent: Saturday, July 19, 2008 9:06 AM To: OpenSceneGraph Users Subject: Re: [osg-users] osg::Light Simple Question ? Hi Jean, Thanks for reply. You are right, my model hasn't normals :) So terrainScaleMAT-getOrCreateStateSet()-setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON ); pattern doesn't work on terrain lightening. Like your advice I can use osgUtil::SmoothingVisitor but I choose easier way which is gathering model which has normals in it. So I use new model with adding GL_RESCALE_NORMAL control and result is perfect like added screenshot:) I have a last question about why my model's lightening operation related with normals rescaling process? I can't understand backgroud of this command. Thanks for helps Jean and Gordon :) Best Regards. Ümit UZUN 2008/7/19 Jean-Sébastien Guay [EMAIL PROTECTED]: Hello Ümit, I have tried terrainScaleMAT-getOrCreateStateSet()-setMode( GL_RESCALE_NORMAL, osg::StateAttribute::ON ); pattern but the result is same. There is no light effect on the terrain. I don't understand why? As Gordon said, check if your terrain has normals in the first place... Rescaling non-existing normals won't do anything :-) In your .osg file, check for normalArray under your Geometry, and check that normalBinding is set to PER_VERTEX. If the model has no normals, you can generate them with a modeling tool or use the osgUtil::SmoothingVisitor to create smooth normals across the surface. And BTW, yes you're right that the two suggestions I gave before were mutually exclusive, i.e. if you checked your model and changed the TexEnv in it you don't need a NodeVisitor to do the same thing... Oh, just another little thing, are you sure you're reloading the .osg model and not the original one without your changes? J-S -- __ Jean-Sebastien Guay[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] osg::Light Simple Question ?
Hello Ümit, I am trying to effect the components of scene with green light. Although green light could effected two of sphere, couldn't get success on the terrain model. What can I do to effect the terrain with green light? Your terrain's texture is probably being applied in GL_REPLACE mode, instead of in GL_MODULATE mode. In GL_MODULATE, the texture color is multiplied by the shading value at a pixel to give the final surface color, and in GL_REPLACE mode the texture color is used directly (replacing the shading). Your options: * Check the terrain model file (you can try osgconv model.whatever model.osg if it isn't an .osg file, and then open it in a text editor to check for the texture application mode) and change it in the model. * Write a NodeVisitor that you will run on your terrain model after having loaded it to change any osg::TexEnv object from REPLACE mode to MODULATE mode (or just remove the TexEnv, since the default is MODULATE). I recommend option 1, your life will be much easier if your models are correct in the first place and you don't have to hard-code any changes in your program. J-S -- __ Jean-Sebastien Guay[EMAIL PROTECTED] http://www.cm-labs.com/ http://whitestar02.webhop.org/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org