• Advertisement

Archived

This topic is now archived and is closed to further replies.

How to render shadowmaps?

This topic is 5383 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I am wondering how to render a complete spherical shadow map from a light origin. Say you have a closed room and some obstacles in it. In the middle of the room there is a light source. Is there a way you can render the entire shadowmap scene in one pass? (If you face the light "camera" forward, you''ll miss everything behind it) I was thinking about rendering with FOV value 180. that would solve the clipping problem, but i''ve heard somewhere that the depth buffer is calculated as one-directional, not radial. If this is true, this theory is wasted. Any ideas? Is the only sollution to render a cube map and hope that the seams are not noticeable? Electron

"The truth can be changed simply by the way you accept it."


Share this post


Link to post
Share on other sites
Advertisement
Spherical rendering is *very* difficult, since straight lines are not preserved - a straight line on a model will not necessarily translate to a straight line in the rendering. This would be extremely difficult to work with, for a start it means you can''t use 3D acceleration (which is built on the assumption that straight lines are preserved).

So I would suggest you use cubemaps, and focus on making the process as efficient as possible. I don''t recall seams being a major issue, but I''ve never implemented them so I''m not sure.

Share this post


Link to post
Share on other sites
Are there any tutorials (with basic sample code) to show how to render shadow cube maps in OpenGL. I don''t have the faintest clue about where to start with setting up all the OpenGL parameters for shadow mapping.

Share this post


Link to post
Share on other sites
To put it VERY simple, you render the scene six times (front, back, left, right, up and down) from the origin of the light source. for each render, you retrieve the depth buffer and save it as a texture.

Now comes the fun (and REALLY difficult) part. For each pixel rendered, check the distance between it and the light source.
if the distance is greater than the correspondent distance in the stored depth texture, render it black. (It''s behind something else)
And if it''s equally large, render it lit.



Electron

"The truth can be changed simply by the way you accept it."


Share this post


Link to post
Share on other sites
Hey, I''ve been thinking about this alot lately... I''m wondering, how do one check the distance between a rendered pixel, and some 3D-point? It makes no sense to me... I can understand how to get the distance between two 3D-points and two pixels, but this I don''t get... Please explain to me, how to go about it.

thanks!

Share this post


Link to post
Share on other sites
quote:

Are there any tutorials (with basic sample code) to show how to render shadow cube maps in OpenGL


Keep in mind, that current 3D hardware doesn''t directly support cubemap depth textures for shadowmapping (the r-coordinate, that is used during pixel depth comparison is needed to address a cubemap). But if you are a little creative, there are ways around that (esp. easy with ARB_fragment_program).

You might also want to take a look at dual-paraboloid shadowmapping. It essentially uses two parabolic textures to achieve pointlight shadowmapping. Very interesting, as it only uses two textures per lightsource, instead of six. Look here for more ideas about special shadowmapping techniques. IIRC, delphi3d.net currently has a dual-paraboloid shadowmapping demo up.

Share this post


Link to post
Share on other sites
To get the distance from the rendered depth buffer, it''s no problem. You simply take the depth value (i use float, hence ranging from 0 to 1)
then i get the znear and zfar settings.
So, the distance to the nearest (LIT) pixel is:

litdepth = znear + (zfar-znear) * depthvalue;


Now, take the view matrix you used when you created the depth buffer, and invert it.
Multiply the current pixel position with this matrix.
Now i *think* you have the right depth value in your Z-component.

CAUTION: Don''t take my word for that this will actually work! I haven''t tried it (yet).




Electron

"The truth can be changed simply by the way you accept it."


Share this post


Link to post
Share on other sites
Ah, I see... Does anyone know where I can find some tutorials on this? I''ve read about how to do shadows using the depth-buffer, but I''ve never been able to find concrete examples, so I really don''t know how to implement it.
I''m not supposed to fight my way to the depth-buffer manually, pixel by pixel... yak! That can''t be the way to do it, so I''m craving for a tutorial on this subject.

Thanks

Share this post


Link to post
Share on other sites
I can''t say i''m an expert or something, but i''m pretty sure that shadow maps using the depth buffer can only be done in a per-pixel basis.


Electron

"The truth can be changed simply by the way you accept it."


Share this post


Link to post
Share on other sites
quote:

I''m not supposed to fight my way to the depth-buffer manually, pixel by pixel...


You don''t need to. GeForce3 and higher, as well as newer Radeons, have dedicated hardware support for depth shadowmaps, and will do the perpixel comparison for you. Check out this and this nVidia paper, for instance. ATI also have some shadowmapping papers on their developer site.

Share this post


Link to post
Share on other sites
I read the PDF about (dual) paraboloid shadow mapping, it''s quite interesting. But you need to transform geometry to fit the paraboloid mapping and the geometry also has to be tessellated some. I haven''t tested this method on low-poly models yet to see what happend, I think that''ll be my project tomorrow

Share this post


Link to post
Share on other sites
quote:

But you need to transform geometry to fit the paraboloid mapping and the geometry also has to be tessellated some.


Sure, since the parabolic projection, similar to a spherical one, does not preserve straight lines. I guess on high-poly scenes, the results won''t be too bad. Don''t know about low poly, but it could introduce artifacts in the shadows. I haven''t tested the algorithm myself, although I did with a dual-paraboloid envmapping algorithm some time ago. I just found the idea of using this technique on pointlight shadowmapping very interesting.

Share this post


Link to post
Share on other sites
http://ice.prohosting.com/~bgcjr/Release.rar
a demo of DPSM for GeForce.

Share this post


Link to post
Share on other sites

  • Advertisement