Re: [osg-users] Computing depth buffer in osgVolume
Hi Robert, Thanks for your tips, I managed to compute correctly the depth value in the fragment shader. I only needed access to the volume locator matrix to compute the right position of the ray, and then use the projection transformation matrix to compute the depth value in the range [-1,1]. Then I had to rescale it to [0,1] since this is what the Z-buffer expects. To summarize, the fragment shader becomes something like: uniform mat4 LocatorMatrix; vec4 pos = LocatorMatrix * vec4(texcoord,1.0); vec4 transformedpos = gl_ModelViewProjectionMatrix * pos; gl_FragDepth = ((transformedpos.z / transformedpos.w) + 1.0) * 0.5; Where LocatorMatrix is an extra uniform in the fragment shader that gives the locator matrix (added to osgVolume::RayTracedTechnique). Maybe this should be integrated in the next release of OSG? I can send you the code of each shaders if you are interested. Best regards, Yvon Robert Osfield wrote: Hi Yvon, The present osgVolume shaders that I've written compute the ray start position from the initial fragment generated by rendered the backface of the cube, then shoots the ray forward towards the eye point and then clamps this to the dimensions of the cube. It then computes the texcoords for this from these ray coords. Robert. On Wed, Aug 5, 2009 at 7:40 PM, Yvon Halbwachsy...@kalkulo.no wrote: Hi, I would like to add the computation of the z-depth value in the ray traced volume shaders. I'm pretty new to raytracing on gpu, so forgive me if this is a naive question! I've tried to add this code in the fragment shader, just after the line gl_FragColor = color: gl_FragColor = color; vec4 inter = gl_ModelViewProjectionMatrix * vec4(texcoord,1); gl_FragDepth = inter.z / inter.w; return; In theory my idea is to compute the position of the intersection with the volume, and use the model view projection transformation matrix to get z buffer value computed. It looks good... but it's not right! Does any one have an idea about what I'm doing wrong? Thanks for any help, Regards, Yvon ___ 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 -- --- Yvon Halbwachs Email : y...@kalkulo.no Mobile: +47 95 94 14 42 WWW : http://www.kalkulo.no --- Kalkulo AS - A subsidiary of Simula Research Laboratory --- ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Computing depth buffer in osgVolume
Yes I agree that the z-buffer depth value makes more sense for the isosurface technique since it defines a single position. I only meant that I modified the shaders for the isosurface technique (volume_iso.frag and volume_tf_iso.frag). Yvon Robert Osfield wrote: Hi Yvon, Good to hear you've got it working. Maybe this should be integrated in the next release of OSG? I can send you the code of each shaders if you are interested. Possibly. It's not clear to me which depth you are computing, as each fragment can have only one depth, for a volume what depth to assume will depend upon the technique, for instance the isosurface or mip techniques will have a single position, but the blending ray tracing techniques won't have any single position that can be identified. Robert. ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org -- --- Yvon Halbwachs Email : y...@kalkulo.no Mobile: +47 95 94 14 42 WWW : http://www.kalkulo.no --- Kalkulo AS - A subsidiary of Simula Research Laboratory --- ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
[osg-users] Computing depth buffer in osgVolume
Hi, I would like to add the computation of the z-depth value in the ray traced volume shaders. I'm pretty new to raytracing on gpu, so forgive me if this is a naive question! I've tried to add this code in the fragment shader, just after the line gl_FragColor = color: gl_FragColor = color; vec4 inter = gl_ModelViewProjectionMatrix * vec4(texcoord,1); gl_FragDepth = inter.z / inter.w; return; In theory my idea is to compute the position of the intersection with the volume, and use the model view projection transformation matrix to get z buffer value computed. It looks good... but it's not right! Does any one have an idea about what I'm doing wrong? Thanks for any help, Regards, Yvon ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Re: [osg-users] Displaying a scene in the background of a QGraphicsView
Hi everybody, I managed to use osg in a Qt QGraphicsView with the information that Eric Zeremba and Rene Molenaar posted some weeks ago. I still have some troubles though... Things work fine when I display the cow.osg scene from the OpenSceneGraph example files, but nothing is displayed when I use cessna.osg. The only way to display it is to enable display lists (it is set to false by default). Anybody has a clue about what's going on? Yvon ___ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org