Advertisement

Basic Rendering Question: Advanced Lighting on Cube, but Normals are interpolated between Triangles

Started by May 26, 2021 09:04 AM
2 comments, last by icy00 3 years, 5 months ago

Hello there!

I'm still very much a novice concerning 3D rendering, so I apologize in advance for my naivety. I have a question regarding the basic 3D rendering techniques for a cube. So, if I have a cube with 8 vertices (position and normal) and an index buffer defining 12 triangles with those 8 vertices, and i render the cube as a triangle strip, what happens is that the normal of every vertex is interpolated in between all the faces that use that vertex. Now, I want to do some advanced light shading in the pixel shader of this cube, but all i have are the interpolated normals which won't give me the correct results, because they are being averaged between all the different triangles that use the vertex.

I see a couple of different solutions here:

  • Use a triangle list instead of the triangle strip, but this increases the vertex count from 8 to 24,
  • Define a geometry shader in between the vertex and pixel shader of the cube and calculate the normal of a triangle and pass that normal to the pixel shader (if that's even possible),
  • Give the vertices texture coordinates and use a normal map for the cube.

Considering this being a rather simple example with 8 vertices, i guess it wouldn't really make a difference choosing any of these methods. But if I want to utilize the GPU's instancing capabilities and have multiple thousand instances of this cube, what would be the correct choice?

I feel like there is a very easy solution to the the problem I can't see yet and I am totally overthinking it.

Thanks in advance,

Paul

icy00 said:
Use a triangle list instead of the triangle strip, but this increases the vertex count from 8 to 24,

icy00 said:
Give the vertices texture coordinates and use a normal map for the cube.

Notice both methods have in common that you have to duplicate vertices. Because for useful UV map without overlaps or flips, you also have to cut the mesh open in UV space, thus you get at least 14 vertices IIRC.

So in practice you have to duplicate vertices along the boundary of each UV chart, and along hard edges with multiple normals per vertex. Other reasons can be to reduce bone count for skinning, splitting my material, etc.

If you think of a detailed mesh with thousands of triangles, those duplicated vertices are few in comparison to the total vertex count, so it's no problem and the preferred method.
GS adds complexity and should be the slowest solution, normal mapping gives no win if you only want flat polygons, and 24 vertices still isn't much.

Advertisement

@JoeJ

JoeJ said:
Notice both methods have in common that you have to duplicate vertices.

very true, didn't even think about that.

JoeJ said:
If you think of a detailed mesh with thousands of triangles, those duplicated vertices are few in comparison to the total vertex count, so it's no problem and the preferred method.

I can see that being true too.

JoeJ said:
GS adds complexity and should be the slowest solution, normal mapping gives no win if you only want flat polygons, and 24 vertices still isn't much.

Alright, i will go for the increased vertex count then. Thank you for your answer! Helped a lot.

This topic is closed to new replies.

Advertisement