Trenki
Member
Hi all!
Last weekend I took the time to code a class which can rasterize triangles. The code is kept quite general for maximum extensibility.
I used various pieces of code from the web as a basis such as the code from devmaster and filled in the missing parts.
- The rasterizer can support an arbitrary number of render targets (you will most likely use two, a color buffer and a depth buffer).
- It can be configured with a "PixelShader" which does the actual hard work of shading each pixel.
- It does only use integer math.
- It interpolates an arbitrary number of integer variables (this means you can use fixed point here) across the triangle. This is done perspectively correct for the corners of each 8x8 block and linearly within the block which saves cpu cycles.
The only problem I can see right now is with small or large but thin triangles. Because the rasterizer is tile based it must at least scan a whole 8x8 block and test each pixel if it is inside the triangle or not.
Large triangles are handled quite efficiently since for the inner part only the corners are tested for inout.
What do you think about this.
The code is ~500 lines of C++ long, so I don't post it here unless requested otherwise. If you would like to take a look at it please email me at: trenki2 - at - gmx.net
I've now uploaded a vastly improved version of the renderer to my new domain www.trenki.net. Check it out if you are interested.
Last weekend I took the time to code a class which can rasterize triangles. The code is kept quite general for maximum extensibility.
I used various pieces of code from the web as a basis such as the code from devmaster and filled in the missing parts.
- The rasterizer can support an arbitrary number of render targets (you will most likely use two, a color buffer and a depth buffer).
- It can be configured with a "PixelShader" which does the actual hard work of shading each pixel.
- It does only use integer math.
- It interpolates an arbitrary number of integer variables (this means you can use fixed point here) across the triangle. This is done perspectively correct for the corners of each 8x8 block and linearly within the block which saves cpu cycles.
The only problem I can see right now is with small or large but thin triangles. Because the rasterizer is tile based it must at least scan a whole 8x8 block and test each pixel if it is inside the triangle or not.
Large triangles are handled quite efficiently since for the inner part only the corners are tested for inout.
What do you think about this.
The code is ~500 lines of C++ long, so I don't post it here unless requested otherwise. If you would like to take a look at it please email me at: trenki2 - at - gmx.net
I've now uploaded a vastly improved version of the renderer to my new domain www.trenki.net. Check it out if you are interested.