i’ve read a document from mark kilgard about producing shadows with shadow maps.
he is suggesting to use glpolygonoffset. i took a look about this function and still don’t have the slightest idea what it really does.
can anybody clear me up, or suggest a good tut. where i can see, what it does.
What glPolygonOffset does is modify the depth value of a fragment. It adds or substracts a small quantity to this depth value, pulling toward or pushing away the fragment from the viewer.
Why would you like to alter the depth value? To avoid z-fighting.
as i said i am trying to understand this document about shadows created with shadow maps.
in this context, i don’t think it is used to avoid z-fighting, though i have just gotten that far, that it could be used for creating the shadowmap.
Imagine you have an object above a surface. You want to cast some sort of shadow on that surface. One way would be to draw a textured quad on the surface, to make it darker under the object. And there you can run into z fighting problems since you want your shadow to be on the surface. You would give same values for your quad than for the surface itself. By using glPolygonOffset, you avoid z-fighting and have your shadow quad on the surface.
But it might be used in a completely different technique. Do you have a link to the paper you’re trying to understand?
i can’t remember where i found the *.pdf
mark kilgard did a report at “CEDEC 2001” in Tokyo with the title “Shadow mapping with todays OpenGL Hardware”
try and search the forums here first.
this is not just about a simple shadow on a plan. it is for shadows on complex structures.
I found it here
Definitely not a paper for beginners (don’t get me wrong, I’m not saying you’re a beginner, I’m just saying that you should have asked your question in the advanced forum).
So what about this glPolygonOffset? It is still some kind of z-fighting.
Look at page 22 in the pdf. Mark Kilgard says he uses glPolygonOffset to offset values back. He means here that he is pulling everyting toward the viewer (in fact toward the light since we are construction the light view depth map). So why don’t use glTranslate? Because when rendering is done, everything has been perspective corrected. So the depth variation at the center of the window is not the same as at the edges of the window (because of perspective). If you use glTranslate, shadows won’t “stick” on the objects they’re cast on.
Page 23 : glPolygonOffset is guarenteed to be a window space offset. It means that it handles perspective correction when calculating the offset of the fragment.
I tried to explain it as I understand it. Maybe someone here can do better. I strongly encourage you to have a look at the Red Book (page 250 and following). Maybe it will clear things up.
As I understand it, the use of glPolygonOffset in this instance has nothing to do with z-fighting at all. It seems to be merely used to introduce a depth bias in the depth values while constructing of the depth map.
Ok the word z-fighting isn’t appropriate.
Nevertheless, why would a depth bias be needed? I think it is because when you compare the fragment z-value with the light view depth map, due to imprecision , some contiguous fragments (surface-wise) will be stated as shadowed and other as not shadowed. The resulting shadow will have some lit fragments. Look at the pictures page 28 in the PDF. The first pic shows artifacts that look like z-fighting.
Anyway I think the whole idea is to get the shadow as close to the surface as possible, without having artifacts.
Oh well… I’m not a guru at all I wish I had attended the presentation to get all the explanations. If I’m mistaken, don’t hesitate to correct me.