0
votes

I have a quite theorical question about normals in OpenGL. I could not find a clear explanation anywhere (my knowledge in this subject is not spot on).

I would like to put textures on a Cube, one per face, and the most obvious way to do this is playing with normals.

But including normals in vertices leads to not sharing these vertices :

  • On a Cube with shared vertices, we would have 8vertices.
  • On a Cube with non-shared vertices, we would have 8*3 = 32vertices.

I've read somewhere that shaders can be used to determine normals and apply textures, but I don't really know anything about shaders and was wondering what was the best way to do this work (apply textures on the cube's faces).

On top of that, I would like these vertices to not share the coordinates of the texture applying to them (for example, the vertex on the bottom-left in front of us would have a (0,0) UV coordinates for the texture on the FRONT face of the cube, a (0,1) UV coordinate for the texture on the LEFT face of the cube, and a (1,1) UV coordinate for the texture on the BOTTOM face of the cube). Can shaders achieve this work when patching the texture ?

In conclusion, what is the best way to apply a non-shared texture & non-shared UV coordinate to a vertice : with non-shared vertices (a lot more vertices), or with a shader (more work for the GPU, i guess) ?

1
Most common method is repeating vertices with different attribute, but you can compute also normals in geom shader (increasing work for gpu) and use the primitive index for each face drawn to allocate correct texture.Wrapped texture combination could be build in a fbo if you have only separate ones as inputj-p

1 Answers

0
votes

I would say this depends on your use case. Consider the following:

  • How many vertices do you have to render? If only few, saving mesh storage space is not very important.
  • How often are vertices transferred from CPU to GPU? If it is necessary every frame, saving vertices might speed up rendering time.
  • Are most of you edges non-smooth? If most edges should appear smooth, than you could only break the mesh for the few cases where it is necessary.

For all my hobby projects I went with non-shared vertices, as it is often easier to handle. I would care about performance only if it shows to be a bottle neck in your program.