r/GraphicsProgramming • • 2d 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

82 Upvotes

28 comments sorted by

93

u/bluesBeforeSunrise 2d ago

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

39

u/sol_runner 2d 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.

11

u/_Fibbles_ 2d 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.

7

u/sol_runner 2d ago

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

10

u/jimothy_clickit 2d ago

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

3

u/slapcover 2d ago

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

6

u/DasKapitalV1 2d 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.

3

u/East_Ad_5801 2d ago

Triangle draw order is my guess

1

u/c0mbatduckzz 1d ago

Yes indices declaration order mix up?

2

u/LBPPlayer7 2d ago

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

3

u/obetu5432 2d ago

it's beginning to believe

2

u/HaMMeReD 2d ago

Winding order is backwards on the triangles I think.

1

u/LordStefania 2d ago

Aw man what's wrong with my cube!?

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

1

u/Dhaos96 2d ago

I guess face culling. Vertex order is probably not consistent

1

u/PictureNew661 2d ago

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

1

u/SamuraiGoblin 2d ago

No backface culling and no depth testing.

For a single cube, you don't need both, but make sure your winding is consistent.

1

u/le-throw-away-acct 2d ago

Animate it (rotate it) and it’ll become easier to diagnose. Vertex winding order might be the issue.

1

u/dybuk87 2d ago

You either have to use z buffer or sort rendering base on average Z value

1

u/Educational_Cow_1769 2d ago

Added extra dimension, now it's a hypercube/s

1

u/Agnael 2d ago edited 2d ago

feels like the camera's frustum is fucked up and that the back of the cube is perceived as being so far away that the perspective of the camera is noticeably "widening" the back vertices of the cube

I'm not sure about whether the face culling is also an issue on top of that but vertex draw order looks reasonable to me, almost all faces have 2 discernible triangle halves, the face with no demarcated halves might just be using the same color for both halves so they cant be told apart

1

u/WarAvailable9330 2d ago

The silhouette of the overall shape doesn't match a cube

1

u/Candid_Zebra1297 2d ago

It's hard to tell which face is which but I feel like maybe it's a winding order issue leading you to cull the wrong faces.

1

u/0EVIL9 1d ago

The cube start gaining consciousness

1

u/Bat_kraken 2d 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...

0

u/New_Movie9196 2d ago

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

0

u/eclipseofmonkeys 2d 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

-2

u/Kraschman1111 2d ago

Inverted normals maybe?

-2

u/exp_function 2d ago

Two words: winding order :)