Wait, what? They rasterize a triangle by checking for each pixel if it intersects with the triangle? Where are the days when you learned Bresenham [1] or fixed-point arithmetic [2] to determine the extents of a scan line, and then fill it with an ordinary for-loop? [1] https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm [2] https://en.wikipedia.org/wiki/Fixed-point_arithmetic
Checking every pixel is generally faster on modern hardware due to SIMD! Of course you’ll need to clip properly. There are some pathological cases, like a thin long almost diagonal triangles. But those (rare) cases can be handled too by some subdivision clipping.
Implementing a Tiny CPU Rasterizer
31–40 of 50 posts
Re: Implementing a Tiny CPU Rasterizer
#32Earlier quoted context omitted.
Checking every pixel is generally faster on modern hardware due to SIMD! Of course you’ll need to clip properly. There are some pathological cases, like a thin long almost diagonal triangles. But those (rare) cases can be handled too by some subdivision clipping.
I get that a GPU is doing it like that, but are you really sure this is the better algorithm for cpu?
You have also less branches which helps a lot.
Re: Implementing a Tiny CPU Rasterizer
#33[1] https://pikuma.com/courses/learn-3d-computer-graphics-progra...
Re: Implementing a Tiny CPU Rasterizer
#34This might also be of interest to anybody who enjoyed these articles: https://www.scratchapixel.com/ .
Offering this as constructive criticism - the tutorials could be more engaging if the student could follow along and cause things to happen directly on the screen. It'd be awesome to organize the 1st unit as more than just confirming one has a compiler, to take it all the way to a kind of "hello, pixels".
Re: Implementing a Tiny CPU Rasterizer
#35Earlier quoted context omitted.
Perspective correct texture mapping was too expensive for the hardware available at fatmap time I think ? Edit: it was actually possible at the time.
It was but it was borderline. A typical trick was to do the division at the start and end of a span, and interpolate linearly, rather than per pixel. This worked well enough if the triangle was seen fairly straight on and was not too large. Quake popularized the per-8 pixels technique, which is close enough in most cases.
Re: Implementing a Tiny CPU Rasterizer
#36Nostalgia flashback. Anyone else implemented a renderer based on fatmap2.txt[1]? I came up with my own approach using bresenham and storing spans, but it was slow and sucked. Then my buddy found fatmap2.txt on a BBS and gave it to me, as I didn't have a modem at the time. It was a revelation. Programming in Turbo Pascal I was hampered by it being 16bit, but discovered I could prepend the assembly opcodes with 66h to…
Re: Implementing a Tiny CPU Rasterizer
#37By the way, does anyone know how to modify the standard perspective projection to have a spherical cap instead of the flat rectangle as its far clipping plane? Having the flat rectangle means that you can see further from the corner of your eye than in front of you which is definitely not how the human vision works, and there are some games where this bizarre behaviour is very noticeable: you can barely see some thin…
Re: Implementing a Tiny CPU Rasterizer
#38I strongly recommend this course “3D Computer Graphics Programming”[1] from Gustavo Pezzi. It walks you through the creation of CPU rasterizer from scratch in C. I am working through it right now and I enjoy it a lot. [1] https://pikuma.com/courses/learn-3d-computer-graphics-progra...
Re: Implementing a Tiny CPU Rasterizer
#39Nostalgia flashback. Anyone else implemented a renderer based on fatmap2.txt[1]? I came up with my own approach using bresenham and storing spans, but it was slow and sucked. Then my buddy found fatmap2.txt on a BBS and gave it to me, as I didn't have a modem at the time. It was a revelation. Programming in Turbo Pascal I was hampered by it being 16bit, but discovered I could prepend the assembly opcodes with 66h to…
Re: Implementing a Tiny CPU Rasterizer
#40If you like this, there is also the 500 lines of C++ TinyRenderer, loading Obj files, texture mapping, clipping, and vertex/pixel shaders on CPU only: https://github.com/ssloy/tinyrenderer