Note that there are some explanatory texts on larger screens.

plurals
  1. POConfused Regarding World View Projection Matrix question for Ray Tracing using XNA
    primarykey
    data
    text
    <p>So I've decided to rewrite an old ray tracer I had which was written in C++ and to do it in C#, leveraging the XNA framework.</p> <p>I still have my old book and can follow the notes however I am confused regarding a few ideas and I was wondering whether someone could articulate it nicely.</p> <pre> <code> for each x pixel do for each y pixel do //Generate Ray //1 - Calculate world coordinates of current pixel //1.1 Calculate Normalized Device coordinates for current pixel 1- to -1 (u, v) u = (2*x/ WIDTH) - 1 ; v = (2*y/HEIGHT) - 1 ; Vector3 rayDirection = -1*focalLength + u'*u + v'*v </code> </pre> <p>In the above code u' and v' are the orthnormal basis calculated for the given camera (I know the same names make it confusing)</p> <p>If I follow the book and do it the way it expresses, it works. However I am trying to leverage XNA and getting confused on how to perform the same actions but using Matrices.</p> <p>So I've tried to replace the following steps with the XNA code</p> <pre> <code> class Camera { public Camera(float width, float height) { AspectRatio = width/height; FOV = Math.PI / 2.0f; NearPlane = 1.0f; FarPlane = 100.0f; ViewMatrix = Matrix.CreateLookAt(Position, Direction,this.Up); ProjectionMatrix=Matrix.CreatePerspectiveFieldOfView(FOV, AspectRatio,NearPlane,FarPlane); } } </code> </pre> <p>It's at this point I'm confused in the order of operations I am supposed to apply in order to get the direction vector for any pixel (x, y) ?</p> <p>In my head I'm thinking: (u,v) = ProjectionMatrix * ViewMatrix * ModelToWorld * Vertex(in model space)</p> <p>Therefore it would make sense that</p> <p>Vertex (in world space) = Inverse(ViewMatrix) * Inverse(ProjectionMatrix) * [u, v, 0]</p> <p>I also remembered something about how the view Matrix can be Transposed as well as Inverted since it is orthonormal.</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