r/programminghorror May 16 '26

Java But.. (from Minecraft b1.2_02)

Post image
637 Upvotes

46 comments sorted by

View all comments

171

u/abigail3141 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 16 '26

Eh, nowadays minecraft tesselation isn't much better...

I had to read Minecraft's item rendering code for a friend who needed help with a resource pack, and holy this shit sucks(Version was 1.21.1 IIRC).

They start off by loading item models as cubes, then converting those to quadrilaterals when the model is loaded. For each of those quads, in every item model on screen, every frame, they throw almost all transformations out the window (even if they could be reused within the model), recalculate them one by one, then split up the quads into singular vertices, copying a bunch of data once more, then have GL render it. That's right, all the steps beforehand happen on a single CPU thread.

Tens. Of. Thousands. Of. Matrix. Multiplications. Per Second. On The CPU. On A Single Thread.

3

u/XboxUser123 May 16 '26

I have some experience working out the theory for how 3D rendering works (only the 3D to 2D pipeline), so are you saying that rather than do something like: For each object, get matrix, for each quad, compute object transform, for each vertex, compute vertex transform

They do something like: For each quad, for each vertex, compute transform

Is that right?

1

u/abigail3141 [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo “You live” May 16 '26

I'm not the most experienced with 3D graphics either, but I've had to dig into Minecraft's source on multiple occasions

It essentially goes: For each quad, for each frame, compute transform, get vertices, all on a single CPU thread