2
votes

When I read about how to get the direction vector in raycasting, for example on this site: http://www.daimi.au.dk/~trier/?page_id=98

They first render the mesh with front face culling and then with back face culling. And then subtract the backface from the front to get at a direction vector for each pixel.

But is this not to much work to get the direction vector, is it not more simpler and faster to just take the vertex position(in world coordinates) and subtract the camera position in the fragment shader to get the direction vector? This should give the exact same answer but we skip the backface and frontface rendering.

1

1 Answers

3
votes

The method they describe gives the exact segment of the ray which passes through the object (which is important for volume rendering). So if you want to get the ray segment for that pixel that passes through the object, this is a reasonable thing to do.

If all you want to do is get a direction vector from the camera to the object, then doing as you suggest (and optionally normalizing it) is a more efficient way of going about it.