I am writing a game using OpenGL and I am trying to implement shadow volumes.
I want to build the shadow volume of the model on the GPU through the vertex shader. To this end, I present a model with VBO, where:
- The vertices are duplicated so that each triangle has its own unique three vertices
- Each vertex has a normal to its triangle.
- For the reasons Iโm not going to enter, I did these two points anyway, so I donโt worry too much about duplicating vertices
- Degenerate triangles are added to form squares inside the edges between each pair of "regular" triangles.
Using this model format, inside the vertex shader, I can find the vertices that are part of the triangles that are facing away from the light and move them back to form a shadow volume.
What I left to figure out which transformation I should apply to the back vertices.
I can detect when the vertex is facing away from the light, but I'm not sure which transformation I should apply to it. This is what my vertex shader looks like:
uniform vec3 lightDir;
void main()
{
vec3 eyeNormal = normalize(gl_NormalMatrix * gl_Normal);
vec3 realLightDir = normalize(lightDir);
float dotprod = dot(eyeNormal, realLightDir);
if (dotprod <= 0.0)
{
gl_Position = ???;
}
else
{
gl_Position = ftransform();
}
}
I tried just setting it gl_positionon ftransform() - (vec4(realLightDir, 1.0) * someConstant), but it caused some depth checking errors (some faces seemed to be visible behind others when I displayed the volume with color) and someConstantdidn't seem to affect how far back faces expand.
Update - January 22
, , , . , , , .
, gluLookAt. ; . , glTranslated, ().
(.. ) ( ). , . , :
- ?
user256282