Ray tracing in GLSL for self shadowing

I am trying to implement self shadowing in the fragment shader to do self shadowing. I was wondering if there are any good tutorials on this or anyone has done this yet? Here is what I have so far…

float selfShadow(void)
{
     float surfaceHeight = vertex.y;
     float rayHeight = vertex.y + .005;
          
     while(rayHeight > surfaceHeight && rayHeight < lightDir.y)
     {
        rayHeight += .1;
     }
     return rayHeight < surfaceHeight; 
}

You mean self shadowing bumpmaps? Have you tried Horizon mapping?

Originally posted by Humus:
You mean self shadowing bumpmaps? Have you tried Horizon mapping?
Hi Humus. I am trying to do per pixel self shadowing with the GPU instead right now I am doing it on the CPU with per vertex and saving it out to a greyscale texture and using it like a lightmap to self shadow my terrain… So if thats horizon mapping then yes. :slight_smile:

For terrain you can certainly use horizon mapping for self-shadowing as long as the terrain is static. It’s cheap and quite effective. Just google on it. There’s plenty of material.

Originally posted by Humus:
For terrain you can certainly use horizon mapping for self-shadowing as long as the terrain is static. It’s cheap and quite effective. Just google on it. There’s plenty of material.
Yeah its static, but I did implement it and it ran slow… Probably did something wrong on my part, may have been the step amount was to small and stalled the pipeline…

Step amount? Are you talking about the hoziron map building phase? At runtime it should amount to just a single lookup in a angle map (or you can do that with math) and a single lookup in the horizon map.

Originally posted by Humus:
Step amount? Are you talking about the hoziron map building phase? At runtime it should amount to just a single lookup in a angle map (or you can do that with math) and a single lookup in the horizon map.
Nah its the amount to raise the slope to trail back to the light source. I decided that the performance and quailty wasn’t worth it, compared to doing the self shadowing map on the CPU at load time and using it as lightmap in the FS. Thanks

Fair enough. If both the light and terrain is static, then a lightmap is probably a better choice. But if the light is dynamic a horizon map is a better choice.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.