[osg-users] Multiple parents, unique states and selective lights
Hi, I have a situation where I have Geodes with multiple parents. This means that the Drawables in the scenegraph might be rendered multiple times with different transforms depending on the node path to the root. The problem is that I need to be able to set a unique set of shader uniforms for the different rendered instancies of the same Drawable. What I want to do is to test the bounding sphere of the instance against that of the lights in the scene and set the uniforms based on this test. We do not use osg::Lights since we do not have to support fixed function pipeline, and the lights are stored in a separate datastructure in world space since light calculations is done in world space in the shaders. An idea that I have is to add a drawcallback to the Drawable. In the callback I use RenderInfo::getState to retrieve the state for that instance. State::getInitialInverseMatrix combined with State::worldViewMatrix would give me the world matrix. The world matrix is used to transform the bounding sphere of the drawable and it can then be used for intersection tests. Im not really sure how to set the uniforms at this stage though. As I understand (from stepping trough the code) it is to late to change/add a stateset. I suppose that it would be possible to inject some OpenGL code, but this make me think that there might be a better solution. Is there a better way of achieving what I want than the idea i outlined above? By the way: What does initial means in State::getInitialInverseMatrix)? /Andreas Lindmark ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Multiple parents, unique states and selective lights
Hi Andreas, Andreas Lindmark schrieb: Hi, I have a situation where I have Geodes with multiple parents. This means that the Drawables in the scenegraph might be rendered multiple times with different transforms depending on the node path to the root. The problem is that I need to be able to set a unique set of shader uniforms for the different rendered instancies of the same Drawable. What I want to do is to test the bounding sphere of the instance against that of the lights in the scene and set the uniforms based on this test. We do not use osg::Lights since we do not have to support fixed function pipeline, and the lights are stored in a separate datastructure in world space since light calculations is done in world space in the shaders. An idea that I have is to add a drawcallback to the Drawable. In the callback I use RenderInfo::getState to retrieve the state for that instance. State::getInitialInverseMatrix combined with State::worldViewMatrix would give me the world matrix. The world matrix is used to transform the bounding sphere of the drawable and it can then be used for intersection tests. Im not really sure how to set the uniforms at this stage though. As I understand (from stepping trough the code) it is to late to change/add a stateset. I suppose that it would be possible to inject some OpenGL code, but this make me think that there might be a better solution. Is there a better way of achieving what I want than the idea i outlined above? You could add the position dependend StateSet directly to the Transforms (in osg every osg::Node can have its own StateSet). You could do this in an updateCallback. By the way: What does initial means in State::getInitialInverseMatrix)? /Andreas Lindmark Regards, Peter Hrenka -- Vorstand/Board of Management: Dr. Bernd Finkbeiner, Dr. Florian Geyer, Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board: Prof. Dr. Hanns Ruder Sitz/Registered Office: Tuebingen Registergericht/Registration Court: Stuttgart Registernummer/Commercial Register No.: HRB 382196 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Multiple parents, unique states and selective lights
2008/10/29 Peter Hrenka [EMAIL PROTECTED] Hi Andreas, Andreas Lindmark schrieb: Hi, I have a situation where I have Geodes with multiple parents. This means that the Drawables in the scenegraph might be rendered multiple times with different transforms depending on the node path to the root. The problem is that I need to be able to set a unique set of shader uniforms for the different rendered instancies of the same Drawable. What I want to do is to test the bounding sphere of the instance against that of the lights in the scene and set the uniforms based on this test. We do not use osg::Lights since we do not have to support fixed function pipeline, and the lights are stored in a separate datastructure in world space since light calculations is done in world space in the shaders. An idea that I have is to add a drawcallback to the Drawable. In the callback I use RenderInfo::getState to retrieve the state for that instance. State::getInitialInverseMatrix combined with State::worldViewMatrix would give me the world matrix. The world matrix is used to transform the bounding sphere of the drawable and it can then be used for intersection tests. Im not really sure how to set the uniforms at this stage though. As I understand (from stepping trough the code) it is to late to change/add a stateset. I suppose that it would be possible to inject some OpenGL code, but this make me think that there might be a better solution. Is there a better way of achieving what I want than the idea i outlined above? You could add the position dependend StateSet directly to the Transforms (in osg every osg::Node can have its own StateSet). You could do this in an updateCallback. Regards, Peter Hrenka Hi Peter, I thought about doing something along those lines, but the trouble is that the Transforms or nodes above the transforms can also have have multiple parents and become part of several node paths.. Consider the following: A Root with two children (T1 and T2). T1 And T2 both have Group as a child that in its turn have two transforms as children (T3, and T4). T3 and T4 has the Geode as a child. Primitive text graph art: Root / \ T1 T2 \/ group /\ T3 T4 \/ Geode Geode will now render as four objects with four different matricies (T1*T3, T1*T4, T2*T3 and T2*T3) even though Geode only has two parents. Regards, Andreas ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org