•      Sign In
• Create Account

### #Actualmv348

Posted 09 November 2012 - 01:08 AM

Thanks for that very prompt and clear response, Hodgeman! I saw your response earlier but didn't have time to respond until now.

I just have one more question on a slightly different area of this topic. The primitives that form the shadow volume in the above tutorial are created using the geometry shader, Each triangle given to the Geometry Shader comes paired with 3 neighboring vertices, and these are used to determine which of its edges are silhouette edges. These edges are projected (as a quad) an infinite distance behind the occluder and they form the 'sides' of the volume. The triangle (if front facing) is rendered at its present location and it forms part of the front cap of the volume, and another triangle (projected backwards) forms the back cap.

Makes sense. What I'm confused about is a small tweak used to avoid floating point inaccuracies. Here is the code from the Geometry Shader that creates the front cap:
// front cap
vec3 LightDir = (normalize(GSin[0].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[0].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[2].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[2].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[4].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[4].WorldPos + LightDir), 1.0);
EmitVertex();
EndPrimitive();


As you can see, the vertex is shifted slightly by a distance of EPSILON, in the direction of the light. I don't quite understand the need for this. The tutorial explains this tweak by stating:

The reason is that due to floating point errors we might encounter bizarre corruptions where the volume hides the front cap. Moving the cap away from the volume by just a bit works around this problem

I don't really understand how the sides of the volume could hide the cap but even so, that would probably occur if the sides of the volume somehow got in front of the cap. But what this does is move the vertex along the vector from the light to the occluder, placing the cap deeper inside the volume, and so I would think this would only make matters worse.

Why exactly is that tweak needed and why does it work?
.

### #3mv348

Posted 09 November 2012 - 01:06 AM

Thanks for that very prompt and clear response, Hodgeman! I saw your response earlier but didn't have time to respond until now.

I just have one more question on a slightly different area of this topic. The primitives that form the shadow volume in the above tutorial are created using the geometry shader, Each triangle given to the Geometry Shader comes paired with 3 neighboring vertices, and these are used to determine which of its edges are silhouette edges. These edges are projected (as a quad) an infinite distance behind the occluder and they form the 'sides' of the volume. The triangle (if front facing) is rendered at its present location and it forms part of the front cap of the volume, and another triangle (projected backwards) forms the back cap.

Makes sense. What I'm confused about is a small tweak used to avoid floating point inaccuracies. Here is the code from the Geometry Shader that creates the front cap:
// front cap
vec3 LightDir = (normalize(GSin[0].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[0].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[2].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[2].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[4].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[4].WorldPos + LightDir), 1.0);
EmitVertex();
EndPrimitive();


As you can see, the vertex is shifted slightly by a distance of EPSILON, in the direction of the light. I don't quite understand the need for this. The tutorial explains this tweak by stating:

The reason is that due to floating point errors we might encounter bizarre corruptions where the volume hides the front cap. Moving the cap away from the volume by just a bit works around this problem

I don't really understand how the sides of the volume could hide the cap but even so, that would probably occur if the sides of the volume somehow got in front of the cap. But what this does is move the vertex along the vector from the light to the occluder, placing the cap deeper inside the volume, and so I would think this would only make matters worse.

Why exactly is that tweak needed and why does it work?
.

### #2mv348

Posted 09 November 2012 - 01:06 AM

Thanks for that very prompt and clear response, Hodgeman! I saw your response earlier but didn't have time to respond until now.

I just have one more question on a slightly different area of this topic. The primitives that form the shadow volume in the above tutorial are created using the geometry shader, Each triangle given to the Geometry Shader comes paired with 3 neighboring vertices, and these are used to determine which of its edges are silhouette edges. These edges are projected (as a quad) an infinite distance behind the occluder and they form the 'sides' of the volume. The triangle (if front facing) is rendered at its present location and it forms part of the front cap of the volume, and another triangle (projected backwards) forms the back cap.

Makes sense. What I'm confused about is a small tweak used to avoid floating point inaccuracies. Here is the code from the Geometry Shader that creates the front cap:
// front cap
vec3 LightDir = (normalize(GSin[0].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[0].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[2].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[2].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[4].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[4].WorldPos + LightDir), 1.0);
EmitVertex();
EndPrimitive();


As you can see, the vertex is shifted slightly by a distance of EPSILON, in the direction of the light. I don't quite understand the need for this. The tutorial explains this tweak by stating:

The reason is that due to floating point errors we might encounter bizarre corruptions where the volume hides the front cap. Moving the cap away from the volume by just a bit works around this problem

I don't really understand how the sides of the volume could hide the cap but even so, that would probably occur if the sides of the volume somehow got in front of the cap. But what this does is move the vertex along the vector from the light to the occluder, placing the cap deeper inside the volume, and so I would think this would only make matters worse.

Why exactly is that tweak needed and why does it work?
.

### #1mv348

Posted 09 November 2012 - 01:00 AM

Thanks for that very prompt and clear response, Hodgeman! I saw your response earlier but didn't have time to respond until now.

I just have one more question on a slightly different area of this topic. The primitives that form the shadow volume in the above tutorial are created using the geometry shader, Each triangle given to the Geometry Shader comes paired with 3 neighboring vertices, and these are used to determine which are silhouette edges. These edges are projected an infinite distance behind the object and they form the 'sides' of the volume. The triangle (if front facing) is rendered at its present location and it forms part of the front cap of the volume, and another triangle (projected backwards) forms the back cap.

Makes sense. What I'm confused about is a small tweak used to avoid floating point inaccuracies. Here is the code from the Geometry Shader that creates the front cap:
// front cap
vec3 LightDir = (normalize(GSin[0].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[0].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[2].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[2].WorldPos + LightDir), 1.0);
EmitVertex();
LightDir = (normalize(GSin[4].WorldPos - gLightPos)) * EPSILON;
gl_Position = gVP * vec4((GSin[4].WorldPos + LightDir), 1.0);
EmitVertex();
EndPrimitive();


As you can see, the vertex is shifted slightly by a distance of EPSILON, in the direction of the light. I don't quite understand the need for this. The tutorial explains this tweak b y stating:

The reason is that due to floating point errors we might encounter bizarre corruptions where the volume hides the front cap. Moving the cap away from the volume by just a bit works around this problem

I don't really understand how the sides of the volume could hide the cap but even so, that would probably occur if the sides of the volume somehow got in front of the cap. But what this does is move the vertex along the vector from the light to the occluder, and so I would think this would only make matters worse.

Why exactly is that tweak needed and why does it work?
.

PARTNERS