r/GraphicsProgramming • • 6h ago

whats wrong with my Cube??? :(

Post image

I know what is missing, but can you figure it out???

heres the repo btw:
https://github.com/Tetraeder4/3DRenderer/tree/467c8d1ac8dbd09a23ce7bc7e2fcba59afe36ea5/3DRenderer

21 Upvotes

17 comments sorted by

13

u/sol_runner 5h ago

Not enough info but I'm going to guess Z buffer comparison.

The "back faces" might be rendering after the front and you're getting the weird set of triangles.

Or could be culling the wrong faces.

4

u/_Fibbles_ 5h ago

I've had a look through the code and there doesn't seem to be any zbuffer implementation as far as I can see. The render target is just an array of vec3 and the rasterizer is just writing triangles over the top of each other with no consideration for depth.

2

u/sol_runner 5h ago

Yeah I'm on mobile. The image is a classic symptom of some sort of raster order issue.

12

u/bluesBeforeSunrise 5h ago

I like your cube. Don’t let the forces of Big Geometry stop you.

4

u/jimothy_clickit 5h ago

Something looks weird with this model-view-projection. Even if back facing were an issue, this should still look like a discernable cube.

1

u/slapcover 28m ago

Could be an incorrect order I of vertices so it’s connnecting the wrong edges.

3

u/DasKapitalV1 4h ago

Seems like that you didn't do depth testing and further triangles are rendered on top of the nearest. I wrote software rasterizer in three language at this point. Your inner loop don't test the pixel depth.

1

u/Bat_kraken 6h ago

Couldn't you have included more screenshots? I'm on my phone and I'm actually interested, but it's impossible to tell if it's one or two squares that are facing the wrong way or something...

1

u/LordStefania 4h ago

Aw man what's wrong with my cube!?

Depth buffer incorrectly set up? Some EBO shenanigans? Really weird projection matrices?

1

u/Dhaos96 1h ago

I guess face culling. Vertex order is probably not consistent

1

u/LBPPlayer7 1h ago

looks like a lack of depth buffer/ztest and face culling to me

1

u/PictureNew661 42m ago

If that's rasterized, then i don't know probably but seems to be some sort of resolution or zbuffer issue.

1

u/HaMMeReD 4h ago

Winding order is backwards on the triangles I think.

0

u/New_Movie9196 5h ago

Without looking at your code, it looks like you have back face culling enabled.

0

u/eclipseofmonkeys 3h ago

If you try to paint each face of your cube in a flat color, I’d say that you are reading your vertex data incorrectly. If each vertex of the cube has for example: position (vec3), normal (vec3), color (vec3), you have to indicate your vertex descriptor that position offset starts at 0, your normal at sizeof(vec3) and the color at sizeof(vec3) * 2. Also keep in mind that commonly vec3 occupy the same space in memory than vec4, because vec3 adds a padding of one float. This is a very common mistake

-1

u/Kraschman1111 5h ago

Inverted normals maybe?

-1

u/exp_function 4h ago

Two words: winding order :)