I figured out how to raycast in my fragment shader! I discovered the gl_FragCoord variable, which returns the coordinates of the current fragment in screen space. By passing the shader the screen's dimensions I can convert this number into normalized device coordinates and create a 3D ray based on the fragment and view matrix.
I've tested my raycasts by coloring each fragment with the X, Y, and Z components of the ray it generates. So far everything looks correct. Next step: getting a raymarch to work!
As an added bonus, it's already given that each ray generated will hit the cloud's bounding box since they're only generated from fragments. I can skip that particular test during my raymarch now, since it would actually serve to slow down my renders rather than speed them up as it would in an offline renderer.
Rays as RGB:
No comments:
Post a Comment