Advertisement

Quake 1 source code triangle rasterization

Started by May 05, 2024 07:57 PM
7 comments, last by phantomus 7 months, 1 week ago

Has anyone looked into the Quake 1 source code? I can't find a function to texture a triangle with perspective in software mode. Who can help? Need function name.

black4 said:
I can't find a function to texture a triangle with perspective in software mode.

Maybe there is none. They used polygons for the BSP level, and maybe also for characters.

Found some related functions here:

https://github.com/id-Software/Quake/blob/master/WinQuake/r_draw.c

Iirc, the hidden surface removal worked with scanlines. So instead just rendering them from a given polygon, they first need to go through the HSR system, doing some sorting and culling to prevent overdraw.
And ofc. a polygon needs to be clipped by the frustum as well, before all that.
That's pretty complicated.

If you just want some example to rasterize textured triangles in software, better find some tutorial explaining just that.

For details on Quake, Michael Abrashs Graphics Programming Blackbook has some chapters about it.

Edit: Iirc, I've learned pretty anything about rasterization from Abrashs book. Including perspective correct texturing, subpixel accuracy and clipping. There also were related projects with source code, which i've found from googling. It's all free and PD i think. I never really looked into Doom or Quake code, because the book had it all already.

Advertisement

Also be aware that the techniques they used were specifically designed for the hardware of the era. The hardware from 1996 was radically different in graphics processing than systems in 2024. The DOS-based world where the program had complete hardware control is also vastly different from today's OS design.

Many optimizations for that hardware are useless today, and some trigger emulated behavior and are slower than alternatives.

It can be useful to learn how systems used to work, but it is not today's best practice.

Thank you very much for your answers. I looked at the PDF book, looked at the contents of the book, but did not find a section dedicated to perspective texturing. My English is a little bad, can you tell me the chapter number where perspective texturing is explained in the book?

black4 said:
can you tell me the chapter number where perspective texturing is explained in the book?

Ugh, trying to do so, i see the chapter names barely provide context, lots of code is in assembly, each chapter begins with random stories from personal life, text is scanned in most versions (although there is a html version too somewhere). Probably i remember it wrong and had rasterization already before the book. (Definitively learned about BSP trees from it, but maybe that's all.)
I have to agree with frob. Most of it is outdated and it's not ideal for learning in general. There should be better resources.

Maybe this: https://www.scratchapixel.com/lessons/3d-basic-rendering/rasterization-practical-implementation/overview-rasterization-algorithm.html

But that's quite a lot of material too. And seemingly it does not cover the original scanline method, but rather the ‘parallelizable’ method of looping over all pixel in a bounding rectangle, checking if a pixel is inside the triangle, calculating depth and UVs individually for each pixel. This become more popular with SIMD hardware.

The scanline method does much less work by processing only pixels in the triangle and interpolating depth and UVs along edges and across the scanline.
It's more complicated but not really outdated. Unreals Nanite software rasterizer on GPU uses the scanline approach for example.

And that's currently the only reason why it's eventually worth learning about software rasterization again at all. (Although i expect GPUs will likely add efficient methods to handle small triangles efficiently in the near future.)

However, in general i would be happy that i do not have to learn this anymore, since every HW has a GPU now. It's really complicated. Camera projection, clipping, edge setup, edge interpolation, finally rasterizing the scanline. All of that is needed, and my old code would not fit into a forum thread, nor would it be easy to read either.

I saw lots of related YT videos and github projects as well. But can't recommend anything specific.

Well, you might find some stuff useful here:


https://www.gamers.org/dEngine/quake/papers/checker_texmap.html



@joel The website I linked, had Michael Abarash reference for:
Zen of Graphics Programming 2nd edition, is it possibly this book you were probably talking about and not the black book?

Btw Chris website can be found here:


https://www.chrishecker.com/Miscellaneous_Technical_Articles

None

Advertisement

AliAbdulKareem said:
Zen of Graphics Programming 2nd edition, is it possibly this book you were probably talking about and not the black book?

I don't think so. But i remember Chris Heckers articles. Probably a good resource. : )

Perhaps my software rasterizer repo is of use to you:

https://github.com/jbikker/softrast

Have a look at file rasterizer.cpp, the triangle renderer starts at line 80.

- Jacco.

This topic is closed to new replies.

Advertisement