Re: rendering simple 3d planes (with clipping)
Posted: Thu Apr 07, 2022 12:34 am
You don't actually need sorting; just enable the depth buffer in love.conf and then use love.graphics.setDepthMode and OpenGL will take care of sorting for you - assuming you don't have half-transparent objects.mk8 wrote: ↑Sun Apr 03, 2022 5:44 pm sorry about late reply and thanks alot! i know how basic sorting works, so i should be at least able to implement it into your code. the question is, how about performance? would it run with at least a reasonable framerate (~40 FPS) on an average computer? i'm sure mine would handle it, since it's pretty strong, but i have no way to test it out on an average one.
The rendering speed depends a lot on the geometry you have. If you go this way you're doing pretty much the same kind of OpenGL that other 3D applications are doing; the main difference, CPU wise, is that it's in Lua. Note that you also need some understanding of OpenGL caveats and optimizations if you want to make it efficient. One way of testing is to disable vsync and check how much faster it runs than one frame time.
There's no sorting involved per se; setDepthMode just makes the nearest pixel be visible and discards any other pixel behind. I explained it earlier:mk8 wrote: ↑Mon Apr 04, 2022 5:27 am 1. woulddo the sorting, or do i need to mess with the canvas' pixel format or am i completely off with this?Code: Select all
love.graphics.setDepthMode("lequal", true)
The idea is that the [depth buffer] contains the depth of each point; it is initialized to all infinite before rendering anything, because the depth of vacuum is infinite Now you start rendering a plane, and for each pixel that the plane touches, you check its depth (normally the Z coordinate of the camera coordinates, which is why it's also called a Z buffer). If it's less than what is already in the buffer, it means it's closer to the camera than what was previously drawn, therefore it's visible and you draw it, and store the new depth in the buffer; otherwise you skip it because it's behind something else.
It depends on how many textures you have. Texture atlases (spritesheets) are always preferred over single textures when possible; just keep in mind that implementations may impose limits on the maximum size of a texture (but IIRC 2048x2048 is guaranteed).mk8 wrote: ↑Mon Apr 04, 2022 5:27 am 2. i would obviously like to have more than just 1 texture in the game. would it be faster to create a new 'mesh' of pgimeno's example sort for every texture, or create a single 'mesh' with a spritesheet texture, and set different faces to different uv values to match the desired tile
It's not expensive, but if you just need to change the position or orientation of the object, that's the job for the "model matrix". Typically you have a model placed at (0,0,0) and pointing east, and then you have a matrix that allows changing its position and rotation; you pass it to the shader just before drawing it.
If it's animated (vertices move in relation to each other and not just as a block) then yes, you need to update vertices.
That I can't answer. Computers that don't have a graphics card and are limited to software rendering will struggle even with a few triangles. The slowest GPUs typically have more trouble with big images than with the geometry itself. A reasonable cutoff to make it work on old toasters might be a few thousands polygons. If you plan for beefier machines, probably tens or hundreds of thousands.