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 Halbwachs<[email protected]> 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
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
--
-------------------------------------------------------
Yvon Halbwachs Email : [email protected]
Mobile: +47 95 94 14 42
WWW : http://www.kalkulo.no
-------------------------------------------------------
Kalkulo AS - A subsidiary of Simula Research Laboratory
-------------------------------------------------------
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org