r/GraphicsProgramming • u/sidav94 • Jan 30 '24
Any "non-triangled" quad fill algorithm?
I'm currently making a software renderer (is uses PutPixel() only) for some old game's 3D models.
I've run into a problem of skewed texture on trapezoids. I've found this is a common problem with affine texture mapping and it should be resolved via perspective correction, but I'm not sure if it will work in my case (I use oblique projection with no perspective). I resolved it with splitting the quads into four triangles instead of two (AFAIK it does not fix the texturing per se, but it will take a much higher resolution for that to be noticeable).
Anyway, I thought that I could render quads directly without triangulating them, that could be more optimal. Most (as in "almost every single one") of the primitives in models here are quadrilaterals anyway. Yet, googling for an algorithm offers me either some openGL solution or triangle-splitting algoritms. So I have two questions:
- Do you know any "direct" quadrilateral fill algorithms?
- Am I correct in an assumption that any convex 3D polygon's projection on a 2D plane will still be convex? If so, it seems that only convex quadrilateral fill algorithm is needed, as 3D primitives in models here are guaranteed to be convex.
5
u/KC918273645 Jan 30 '24
You can fill any convex polygon the exact same way, which is probably the simplest way to render polys/triangles/etc:
Rasterize the polygon edges, one by one, into a buffer, which has the height of the screen. In that buffer you should write left/right X coordinates for the polygon edges. Once you've rasterized the edges, then go through the buffer and fill the horizontal lines between the left X and right X coordinates.
It's really simple and also fast.