Note that there are some explanatory texts on larger screens.

plurals
  1. POProjection and clipping issue?
    text
    copied!<p>I am currently developing a Direct3D 11 rendering engine using C#.</p> <p>I have already succeded in drawing triangles, applying color and textures, etc. The object I am trying to display now is a rotated cube with a side length of 1 placed at the origin of the world space. But I am getting unsatisfying results when applying the view and especially the projection matrix. As it is difficult to explain, I just show you what result I get for different view/projection combinations:</p> <hr> <p>HLSL snippet from my vertex shader:</p> <pre><code>float4x4 wvpMatrix = mul(World, mul(View, Projection)); output.Position = mul(input.Position, wvpMatrix); </code></pre> <p>The world matrix I use:</p> <pre><code>// Static rotation around all three axes matrices.World = Matrix.Identity * Matrix.CreateFromYawPitchRoll(0.5f, 0.6f, 1.0f); </code></pre> <hr> <p><strong>Test A</strong></p> <p>Simple view vector from origin in the positive z direction. No projection used. You can see that the back of the cube is being clipped.</p> <pre><code>matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up); matrices.Projection = Matrix.Identity; </code></pre> <p><img src="https://i.stack.imgur.com/VPdLa.jpg" alt="Cube with back corners clipped"></p> <hr> <p><strong>Test B</strong></p> <p>View matrix stays the same, but now I am using an orthographic projection matrix. This time the front of the cube vanishes. The parts you can see are those which were clipped in Test A.</p> <pre><code>matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, 0), new Vector3(0, 0, 1), Vector3.Up); matrices.Projection = Matrix.CreateOrthographic(2, 2, 0.01f, 100.0f); </code></pre> <p><img src="https://i.stack.imgur.com/BMqpD.jpg" alt="Cube with front corner clipped"></p> <hr> <p><strong>Test C</strong></p> <p>Again no projection, just like in Test A. This time the scene is being viewed from a point three units in the negative z direction. The cube looks distorted when the camera position is not set to the origin of the system. I think there is also some clipping.</p> <pre><code>matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, -3), new Vector3(0, 0, 1), Vector3.Up); matrices.Projection = Matrix.Identity; </code></pre> <p><img src="https://i.stack.imgur.com/FICTy.jpg" alt="Distorted cube"></p> <hr> <p><strong>Test D</strong></p> <p>Finally, I use a perspective projection. Up to now I have not found a camera position from which any part of the cube is visible. All I get is fullscreen cornflower blue.</p> <pre><code>matrices.View = Matrix.CreateLookAt(new Vector3(0, 0, -3), new Vector3(0, 0, 1), Vector3.Up); matrices.Projection = Matrix.CreatePerspectiveFieldOfView(1, 1, 0.1f, 100); </code></pre> <p><img src="https://i.stack.imgur.com/9rWSa.jpg" alt="No visible parts of the cube"></p> <hr> <p>First thing I want to do is drawing the full cube - no clipping. I tried different combinations of near/far plane values but I could not find an acceptable solution. My final goal would be to have a perspective projection. But as you see I can't even get a good orthagonal view of the scene. </p>
 

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