... projection, perspective, viewport

Published September 05, 2008
Advertisement
The next step was to add a perspective projection transformation.

I made the following changes for this:

1) Added a projection matrix in the Renderer class and the following function for generating the matrix:

int SetPerspective(float aFov, float aAspectRatio, float aNear, float aFar);

This function creates a projection matrix, which later gets passed down to the VertexEngine class before drawing.

2) Added a function for setting the viewport in the Renderer class:

int SetViewPort(int aWidth, int aHeight, int aOffsetX, int aOffsetY);

This function passes down the viewport data to the VertexEngine class, which uses it to form a matrix that will later be used to transform from normalized device coordinates to screenspace.

3) In the VertexEngine class, I updated the 'ProcessVertex' function I had in there such that three extra steps are performed at the end:
- multiply world-view transformed vertex with the projection matrix to perform linear portion of perspective projection
- divide the result with Z coordinate (stored in the homogenous W coordinate) resulting in normalized device coordinates
- multiply the NDCs to screenspace by multiplying by the matrix created in step 2 above

After adding the appropriate calls to my test application, I get the following (there is a slight x-axis rotation going on so its from a front-top view) ...



The remaining tasks for the vertex stage are culling and frustum clipping.
Previous Entry ... view transform
Next Entry .. clipping!!!
0 likes 4 comments

Comments

Jason Z
It's looking pretty good - you're almost to the fun part: rasterization. When I wrote my software renderer, that was the most time consuming (and fun) part of the project.

Keep up the good work!
September 05, 2008 05:52 AM
HopeDagger
Software rendering has been an interest of mine for ages, so I'm sure you can fathom my interest and excitement when I stumbled across your journal. [grin]

Things are looking great here thus far, and I'm looking forward to watching your renderer progress. Are you thinking about writing a little 3D game with your renderer after its all over, perchance?

Keep up the awesome stuff!
September 05, 2008 08:44 AM
extralongpants
Cool stuff.

I still want to write a software renderer some day.

I really hope Intel's Larrabee is successful. It might spur the development of some really cool software renderers
September 05, 2008 12:56 PM
Clapfoot
Thanks for the motivational comments! I haven't thought about making a game out of it.. i'm hoping to just finish to be honest hehe.
September 06, 2008 12:38 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement