Re: [osg-users] Passing node transformations to the vertex shader
J-S, Of course. It's not that I didn't know state is inherited by child nodes, but for some reason, my testing of uniform inheritance failed, so I was manually propagating uniform pointers... Took 30 seconds to disable that code and prove your point. Thanks again. - Joel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43150#43150 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Passing node transformations to the vertex shader
Hi Joel, So far as your optimization tip goes, I assume you're meaning to apply the shader at the transform node as well? I've been doing that sort of thing already, just not on my Transform nodes... No, I mean that all non-Transform children under a Transform will have the same transformation, so you can put the uniform ONLY on Transform nodes. The non-Transform nodes (Geodes etc.) under them will then inherit the uniform. In my case, I was putting the uniform on Geodes, but say there are 20 Geodes under one same Transform then my code would (I assume) send the uniform to OpenGL 19 times too many (redundant state changes = bad). You just have to handle the one exception where there may not be a Transform between the root of your graph and a non-Transform node, but that will in general be very rare. Anyways, it may well be premature optimization. Putting the uniform on Geodes is much easier (that's why I did that for my simple example) so you can start with that and see if performance is acceptable. As Robert says, if you get 60hz in all your use cases, you're done, go have a beer. ;-) Anyway, thanks for the sample code - I really appreciate that. Hope it helps you out. J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.dyndns-web.com/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Passing node transformations to the vertex shader
J-S, Thanks for the reply. I hadn't sat down and compared matrices yet, but I had debugged to ensure I was getting something. And yes, I'm accommodating for the fact that it's a ModelView (and not just a Model) matrix. I've also been using the osg_ attributes to this point, in lieu of the OpenGL built-in's and have been through most of the documentation you mentioned (though I've not looked at osg::RenderLeaf). So far as your optimization tip goes, I assume you're meaning to apply the shader at the transform node as well? I've been doing that sort of thing already, just not on my Transform nodes... Anyway, thanks for the sample code - I really appreciate that. Joel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43142#43142 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Passing node transformations to the vertex shader
I've encountered the same problem, and setting the context->getState()->setUseModelViewAndProjectionUniforms(true); for each context didn't work in any case (with a multi-pass offscreen rendering). So the simple solution for me was to use the #version 150 compatibility profile, which let's you access the gl_ matrices the old fashioned way. Hi, I'm implementing shaders in GLSL 140+ (i.e. no built-in uniforms), and I've had reasonably good success thus far. However, it's quite obvious that passing the vertices in using osg_Vertex doesn't include any transformations which may have been inherited (or directly applied). This exact question was asked a few months ago here: http://forum.openscenegraph.org/viewtopic.php?t=8350&highlight=vertex+transform+shader In the last post, the user indicates they solved the problem as follows: "Basically what I've had to do is manually append the view matrix onto each light's model transformation each frame and that gives the expected transformation." I'm not sure what he meant, esp. since it made the difference from seeing nothing to seeing anything at all for him. In my case, I have basic lighting running perfectly in GLSL 140+ (using uniforms / attributes instead of built-in's), but if I were to transform the model, the transformation never shows up in the vertex shader. It seems apparent that I need to multiply the osg_Vertex vector in my vertex shader with the model matrix for that geometry (via a uniform updated every frame, or at least whenever the geometry is transformed). The only function that I've found that may get the model matrix is getModelMatrix() in the IntersectionVisitor class. Any thoughts? Joel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43125#43125 ___ 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] Passing node transformations to the vertex shader
Hey, thanks for the fast response... What you're suggesting I actually tried. The View matrix was intact, but the transformations were not. So far as I can tell, my understanding matches what you're telling me, but just to be sure, I've assumed the following: 1. The CullVisitor function, getModelViewMatrix() returns the accumulated matrix. 2. The CullVisitor callback must be added to the parent Transform node (PositionAttitudeTransform, MatrixTransform, etc.). 3. The CullVisitor can directly set the Uniform (whose pointer was passed in the CullVisitor constructor) with the return value of getModelViewMatrix(). (The Uniform lives in the stateset of the child node which has the shader program loaded, of course). Thanks, Joel -- Read this topic online here: http://forum.openscenegraph.org/viewtopic.php?p=43127#43127 ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Passing node transformations to the vertex shader
Hello Joel, It seems apparent that I need to multiply the osg_Vertex vector in my vertex shader with the model matrix for that geometry (via a uniform updated every frame, or at least whenever the geometry is transformed). The only function that I've found that may get the model matrix is getModelMatrix() in the IntersectionVisitor class. You need to accumulate the matrices from the root of your graph to the drawables, and provide this to your vertex shader so it can transform your vertices. There are many ways you could do this. One would be to subclass the osgUtil::CullVisitor class, and whenever your custom CullVisitor gets to a Transform node, instead of applying the accumulated matrix to the fixed pipeline state, it would set a Uniform so that the accumulated matrix is available to your shader. You then set an instance of your custom CullVisitor on your viewer (I think), and it will use it in the cull traversal instead of the stock CullVisitor. There are other, perhaps less intrusive but potentially slower ways: putting callbacks on all Transform nodes, or creating another visitor that runs each frame after the update traversal, or something like that. But I think the custom CullVisitor way is the cleanest. Others (Robert?) can correct me if I'm wrong. Hope this helps, J-S -- __ Jean-Sebastien Guayjean-sebastien.g...@cm-labs.com http://www.cm-labs.com/ http://whitestar02.dyndns-web.com/ ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org