GPU ray marching...

Started by
26 comments, last by Basiror 16 years, 1 month ago
Hrmm wait a minute.. is mirroring as simple as scaling the object by (-1,-1,-1)? Turning it inside out basically? Ogre does all scalling on a 'scene node' basis so if I scaled this scene node by (-1,-1,-1), the volume cube would be mirrored the way we want?

I would just try it but im not home at the moment :(

*and my idea about manually setting the z position in screen space for verts was to ensure verts behind the clip plane got pushed infront of it. But I like your mirroring idea better.
Advertisement
Wait a minute, shouldnt this simple shader do the trick?

Quote:
outPos = mul( worldViewProj, inPos );

outPos *= float4(-1,-1,-1,1);


Just mirroring/flipping the positions in screen space? Or do I need to do the mirror in another space?

*er wait wouldint it be...

Quote:
outPos = mul( worldView, inPos );

outPos *= float4(-1,-1,-1,1);

outPos = mul( proj, outPos );


since we want to do the mirroring in camera space right?

[Edited by - ZealousEngine on February 22, 2008 10:18:04 PM]
snapping the vertices behind the near plane in the vertex shader onto the near plane is indeed a nice solution that should work .

but you need to consider 2 cases:

a) edges that are clipped
b) triangles that are completely behind the near plane

I guess you want to calculate the length of the ray volume intersection right?
so you accumulate the the distances to the back facing and the front facing triangles and subtract them in a 3rd pass right?


thats how I did it in my volumetric fog renderer
http://www.8ung.at/basiror/theironcross.html
Well the length of the ray is being calculated by comparing the zdepth of the backfaces and frontfaces. When the frontfaces are clipped by the nearplane, I plan to set their zdepth to 0 (or whatever the nearplane is actually).

So was I right earlier in saying the mirroring should be done in camera space? And a simple * float4(-1,-1,-1,1) should do the trick? Tried it earlier and got some strange results.. not sure if its working..

*and yeah my earlier idea was to basically snap the verts to the nearplane, think thats a better idea than mirroring?
mirroring with -1-1-1-1 will only work in some special cases

its just negating you coordinates which isn t equal to mirroring against a arbitrary plane


snapping the vertices to the near plane is indeed the correct solution as far as i can see, you have to pass the information of the neighboring vertices of each triangle

e.g.:

tri(a,b,c)
//use texcoords to pass the vertices twice
info(b,c,a)
info(c,a,b)

then check if the triangle is behind the near plane
in this case just project it onto the near plane

if it spans the near plane you have to clip the triangle,
this can be done with geometry shaders, thus requires a GF8+ board
http://www.8ung.at/basiror/theironcross.html
Im sure this has to be possible without using a geometry shader. Are you sure I cant just snap ALL verts to the nearplane? *Remember were doing this in a vertex shader, so I dont see why you are concerned with edges, neighbors, clipping, ect... I ran a test last night and it LOOKS like its working...

Quote:
mirroring with -1-1-1-1 will only work in some special cases

its just negating you coordinates which isn t equal to mirroring against a arbitrary plane


But mirroring in CAMERA space seems like it should be equal to mirroring along the nearplane, no?

[Edited by - ZealousEngine on February 24, 2008 12:15:52 PM]
think about the case where 1 vertex is behind the plane and 2 are in front of it the clipped triangle is a quad and thus can t be represented by a single triangle

I doubt it that mirroring can be done like this in a reliable way

to mirror properly(in world coordinates) you plug the vertices into the plane equation, get the shortest distance and offset the vertices by -2*distance*planenormal

+epsilon to place them slightly in front of the near plane in your case





http://www.8ung.at/basiror/theironcross.html
Quote:think about the case where 1 vertex is behind the plane and 2 are in front of it the clipped triangle is a quad and thus can t be represented by a single triangle


But there is no clipping going on at this stage. We do the mirroring in the vertex shader, then send triangles along to be clipped. So in your example with 1 vert behind, two infront, you would miltiply by float4(-1,-1,-1,1) (in CAMERA space), and end up with the opposite (two verts in front, one behind).

THEN after vertex shading the triangle would be clipped accordingly. Am I still missing something?
Ok well now I DO see a problem with just *= float4(-1,-1,-1,1). Imagine youre in the dead center of a box volume, looking straight ahead. The 'invert all positions' WILL put the faces clipped by the nearplane infront of the camera, but they will be upside down! That *= float4(-1,-1,-1,1) only works in certain cases as you pointed out.

So it sounds like I need to brush up on my 'mirroring math' (if anyone could provide a simple example for mirroring along the nearplane in a vertex shader that would be great!).

*And I ran some tests on my 'snap everything to the neaprlane idea', and didnt get very good results. The problem seems to be, when snapping stuff behind the camera to the nearplane, it isnt projected properly (you lose all depth), thus giving incorrect results.

I think the mirroring solution IS the way to go, if I can just figure out how to do TRUE mirroring (not just inverting everything).
Quote:Original post by ZealousEngine
Quote:think about the case where 1 vertex is behind the plane and 2 are in front of it the clipped triangle is a quad and thus can t be represented by a single triangle


But there is no clipping going on at this stage. We do the mirroring in the vertex shader, then send triangles along to be clipped. So in your example with 1 vert behind, two infront, you would miltiply by float4(-1,-1,-1,1) (in CAMERA space), and end up with the opposite (two verts in front, one behind).

THEN after vertex shading the triangle would be clipped accordingly. Am I still missing something?


the clipping takes place after this stage, and the point is to project all triangles behind the near plane onto the near plane which is not possible if two edges of a triangle span the plane, thus you have make use of the geometry shader to discard the original triangle and insert 2 new triangles(clipping produces a quad and will be done in the geometry shader)
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement