Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL Clip Space Frustum Culling Wrong Results
    primarykey
    data
    text
    <p>I implemented a Clip-Space Frustum Culling on the CPU. In a simple reduced case, I just create a rectangle based on 4 different points which I'm going to render in GL_LINES modes.</p> <p>But sometimes, it seems to me, I get wrong results. Here is an example:</p> <p><a href="http://s7.directupload.net/images/121205/imawbhoh.png" rel="nofollow noreferrer">http://s7.directupload.net/images/121205/imawbhoh.png</a></p> <p>In this render pass, my frustum culling computation detects, all points would be outside the positive y coordinate in NDC coordinates.</p> <p>Here is the input:</p> <p>Points:</p> <pre><code>P1: -5000, 3, -5000 P2: -5000, 3, 5000 P3: 5000, 3, 5000 P4: 5000, 3, -5000 </code></pre> <p>MVP (rounded):</p> <pre><code> 1.0550 0.0000 -1.4521 1138.9092 -1.1700 1.9331 -0.8500 -6573.4885 -0.6481 -0.5993 -0.4708 -2129.3858 -0.6478 -0.5990 -0.4707 -2108.5455 </code></pre> <p>And the calculations (MVP * Position)</p> <pre><code>P1 P2 P3 P4 3124 -11397 -847 13674 3532 -4968 -16668 -8168 3463 -1245 -7726 -3018 3482 -1225 -7703 -2996 </code></pre> <p>And finally, transformed by the perspective divide (w-component)</p> <pre><code>P1 P2 P3 P4 0.897 9.304 0.110 -4.564 1.014 4.056 2.164 2.726 0.995 1.016 1.003 1.007 1.0 1.0 1.0 1.0 </code></pre> <p>As you can see, all transformed points have their y component greater than 1 and should be outside the Viewing Frustum.</p> <p>I already double checked my matrices. I also made a transform feedback in the Vertex Shader to be sure, I use the same matrices for computation on CPU and GPU. Even the result of MVP * Point is the same in my Vertex Shader as on the GPU. My rendering pipeline is as simple as possible. </p> <p>The vertex Shader is </p> <pre><code>vColor = aColor; gl_Position = MVP * aVertexPosition; //With Transform Feedback enabled //transOut = MVP * aVertexPosition </code></pre> <p>And the fragment Shader</p> <pre><code>FragColor = vColor; </code></pre> <p>So the Vertex Shader has the same results as my CPU computations. But still, they are lines drawn on the screen! Any Ideas why there are lines? Do I do something wrong with the perspective divide?</p> <p>What do I have to do, to detect, that this rectangle should not be culled, because there is at least one line visible (basically a strip of another line is visible as well in this example)</p> <p>If it helps: The visible red line is the one between P1 and P2...</p> <p><strong>[Edit]</strong> Now I implemented a world space culling by computing the camera frustum normals and hesse normal form equations. This works fine with correct recognition. Sadly I do need correct computations in clip space, since I'm going to make other computations with that points. Someone any ideas?</p> <p>Here is my computation code:</p> <pre><code>int outOfBoundArray[6] = {0, 0, 0, 0, 0, 0}; std::vector&lt;glm::dvec4&gt; tileBounds = activeElem-&gt;getTileBounds(); //Same as I use for world space culling const glm::dmat4&amp; viewProj = cam-&gt;getCameraTransformations().viewProjectionMatrix; //Same camera which I use for world space culling. for (int i=0; i&lt;tileBounds.size(); i++) { //Apply ModelViewProjection Matrix, to Clip Space glm::dvec4 transformVec = viewProj * tileBounds[i]; //To NDC space [-1,1] transformVec = transformVec / transformVec[3]; //Culling test if ( transformVec.x &gt; 1.0 ) outOfBoundArray[0]++; if ( transformVec.x &lt; -1.0 ) outOfBoundArray[1]++; if ( transformVec.y &gt; 1.0 ) outOfBoundArray[2]++; if ( transformVec.y &lt; -1.0 ) outOfBoundArray[3]++; if ( transformVec.z &gt; 1.0 ) outOfBoundArray[4]++; if ( transformVec.z &lt; -1.0 ) outOfBoundArray[5]++; //Other computations... } for (int i=0; i&lt;6; i++) { if (outOfBoundArray[i] == tileBounds.size()) { return false; } } return true; </code></pre>
    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