PDA

View Full Version : Ray tracing in GLSL for self shadowing



Mars_999
04-10-2006, 04:27 PM
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;
}

Humus
04-10-2006, 08:34 PM
You mean self shadowing bumpmaps? Have you tried Horizon mapping?

Mars_999
04-11-2006, 01:28 AM
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. :)

Humus
04-11-2006, 08:07 PM
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.

Mars_999
04-11-2006, 08:48 PM
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...

Humus
04-13-2006, 02:01 PM
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.

Mars_999
04-13-2006, 02:29 PM
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

Humus
04-13-2006, 08:13 PM
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.