Note that there are some explanatory texts on larger screens.

plurals
  1. POMy shadow volumes don't move with my light
    primarykey
    data
    text
    <p>I'm currently trying to implement shadow volumes in my opengl world. Right now I'm just focusing on getting the volumes calculated correctly.</p> <p>Right now I have a teapot that's rendered, and I can get it to generate some shadow volumes, however they always point directly to the left of the teapot. No matter where I move my light(and I can tell that I'm actually moving the light because the teapot is lit with diffuse lighting), the shadow volumes always go straight left.</p> <p>The method I'm using to create the volumes is:</p> <ol>1. Find silhouette edges by looking at every triangle in the object. If the triangle isn't lit up(tested with the dot product), then skip it. If it is lit, then check all of its edges. If the edge is currently in the list of silhouette edges, remove it. Otherwise add it.</ol> <ol>2. Once I have all the silhouette edges, I go through each edge creating a quad with one vertex at each vertex of the edge, and the other two just extended away from the light.</ol> <p>Here is my code that does it all:</p> <pre><code>void getSilhoueteEdges(Model model, vector&lt;Edge&gt; &amp;edges, Vector3f lightPos) { //for every triangle // if triangle is not facing the light then skip // for every edge // if edge is already in the list // remove // else // add vector&lt;Face&gt; faces = model.faces; //for every triangle for ( unsigned int i = 0; i &lt; faces.size(); i++ ) { Face currentFace = faces.at(i); //if triangle is not facing the light //for this i'll just use the normal of any vertex, it should be the same for all of them Vector3f v1 = model.vertices[currentFace.vertices[0] - 1]; Vector3f n1 = model.normals[currentFace.normals[0] - 1]; Vector3f dirToLight = lightPos - v1; dirToLight.normalize(); float dot = n1.dot(dirToLight); if ( dot &lt;= 0.0f ) continue; //then skip //lets get the edges //v1,v2; v2,v3; v3,v1 Vector3f v2 = model.vertices[currentFace.vertices[1] - 1]; Vector3f v3 = model.vertices[currentFace.vertices[2] - 1]; Edge e[3]; e[0] = Edge(v1, v2); e[1] = Edge(v2, v3); e[2] = Edge(v3, v1); //for every edge //triangles only have 3 edges so loop 3 times for ( int j = 0; j &lt; 3; j++ ) { if ( edges.size() == 0 ) { edges.push_back(e[j]); continue; } bool wasRemoved = false; //if edge is in the list for ( unsigned int k = 0; k &lt; edges.size(); k++ ) { Edge tempEdge = edges.at(k); if ( tempEdge == e[j] ) { edges.erase(edges.begin() + k); wasRemoved = true; break; } } if ( ! wasRemoved ) edges.push_back(e[j]); } } } void extendEdges(vector&lt;Edge&gt; edges, Vector3f lightPos, GLBatch &amp;batch) { float extrudeSize = 100.0f; batch.Begin(GL_QUADS, edges.size() * 4); for ( unsigned int i = 0; i &lt; edges.size(); i++ ) { Edge edge = edges.at(i); batch.Vertex3f(edge.v1.x, edge.v1.y, edge.v1.z); batch.Vertex3f(edge.v2.x, edge.v2.y, edge.v2.z); Vector3f temp = edge.v2 + (( edge.v2 - lightPos ) * extrudeSize); batch.Vertex3f(temp.x, temp.y, temp.z); temp = edge.v1 + ((edge.v1 - lightPos) * extrudeSize); batch.Vertex3f(temp.x, temp.y, temp.z); } batch.End(); } void createShadowVolumesLM(Vector3f lightPos, Model model) { getSilhoueteEdges(model, silhoueteEdges, lightPos); extendEdges(silhoueteEdges, lightPos, boxShadow); } </code></pre> <p>I have my light defined as and the main shadow volume generation method is called by:</p> <pre><code>Vector3f vLightPos = Vector3f(-5.0f,0.0f,2.0f); createShadowVolumesLM(vLightPos, boxModel); </code></pre> <p>All of my code seems self documented in places I don't have any comments, but if there are any confusing parts, let me know.</p> <p>I have a feeling it's just a simple mistake I over looked. Here is what it looks like <a href="http://i.stack.imgur.com/Vpkuh.png" rel="nofollow">with</a> and <a href="http://imgur.com/qP6qK.png" rel="nofollow">without</a> the shadow volumes being rendered.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload