GPU ray marching...

Started by
26 comments, last by Basiror 16 years, 1 month ago
But wait didnt you say you implemented it 'this way' (mirroring) a year ago with your volumetric fog? You used a geometry shader?

If mirroring DOES require a geometry shader, there HAS to be another way to do this. The GPU Gems 3 article makes no mention of using geometry shaders just to render stuff clipped by the near plane.

*and about 'proper' mirroring - When a point is transformed into camera space, wouldnt a simple 'invert the z value' mirror the point along the clip plane? Assuming the clip plane is located at 0,0,0 (the camera). So something like this...

Quote:
float4 wvPos = mul( worldView, inPos );
wvPos *= float4(1,1,-1,1);
outPos = mul( proj, wvPos );


Since the normal of the nearplane (in camera space) is 0,0,1 correct?
Advertisement
Quote:Original post by ZealousEngine
But wait didnt you say you implemented it 'this way' (mirroring) a year ago with your volumetric fog? You used a geometry shader?

If mirroring DOES require a geometry shader, there HAS to be another way to do this. The GPU Gems 3 article makes no mention of using geometry shaders just to render stuff clipped by the near plane.

*and about 'proper' mirroring - When a point is transformed into camera space, wouldnt a simple 'invert the z value' mirror the point along the clip plane? Assuming the clip plane is located at 0,0,0 (the camera). So something like this...

Quote:
float4 wvPos = mul( worldView, inPos );
wvPos *= float4(1,1,-1,1);
outPos = mul( proj, wvPos );


Since the normal of the nearplane (in camera space) is 0,0,1 correct?


further at the top we agreed that snapping the vertices is a more elegant solution than mirroring since it requires less passes


also what do you consider camera space? before the perspective transform or after?

before = gl_ModelViewMatrix*gl_Position;
negating the z axis should do the job i think just try it and see if it works

but if your hardware is capable of geometry shaders I would try the second approach I guess it will be quite a bit faster and is certainly more robust compared to the stencil buffer that has a maximum of 8 bits == 255 ray volume intersections



http://www.8ung.at/basiror/theironcross.html
Well I am having trouble getting either the 'snapping' OR mirroring solution to work.

In dx World is the same as Model, and I consdier View/Camera space the same thing. So in my CG/HLSL vertex shader, I am doing...

Quote:
float4 wvPos = mul( worldView, inPos );
wvPos *= float4(1,1,-1,1);
outPos = mul( proj, wvPos );


Now that SHOULD transform the vert into camera/view space, invert the z position (which, in camera space, should mirror the vert along the clip plane?), then we transform again by the projection matrix. In my mind it should work perfectly, but im getting some errors. These errors MAY be unrelated, thats why I just want somebody to confirm that the above vertex shader should work fine.

And im still a little fuzzy on how you can snap the vertices to the nearplane withotu causing any distortion. In what space should this snapping be done? Camera space?
is see nothing wrong with your mirroring code

does it render anything at all? did you take care about backface culling?


as for snapping there shouldn t be any distortion
just make sure that you offset the polygons away from the near plane into forward direction a little

e.g.: you got a triangle with one vertex behind the clippingplane

clip it in the geometry shader and you get 3 triangles

a quad( 2 triangles) in front of the plane
and a triangle sharing an edge with the quad, the 3rd coordinate of that triangle is projected onto


at the top the clipping case
below a verification that snapping doesn t influence the final result
the gray area are actually wrong but the ray intersection distance is so tiny that it doesn t matter

the thin black line is some offset you may apply to the vertices to position them in front of the near plane
http://www.8ung.at/basiror/theironcross.html
What I meant was there is no way to 'snap' to the nearplane without distortion without using a geometry shader. Its silly to require a geometry shader when mirroring SHOULD work the same way.

I am glad you say my mirroring code looks ok (in my mind it looks ok too). Maybe there is something else wrong with my code, I will keep working on it...
why would you go the multi pass way if there is an easier way to do it

I dunno if you gpu is capable of geometry shaders, but I d prefer it over using stencil buffers and such things

and the geometry shader way is certainly faster since there is
a) less overdraw
b) less buffer swapping
taking place
http://www.8ung.at/basiror/theironcross.html
There are lots of reasons not to use geometry shaders. Not many people have cards that support them is the biggest one.
well, you can still do the same thing in the vertex shader


render each triangle 3x time and in order to discard it you just move it out of the frustrum

this offers you the same possibilities as the geometry shaders only utilizing vertex & fragment shaders

http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement