1
votes

I'm completely new to DirectX (11) so this question will be extremely basic. Sorry about that.

I'd like to draw a cube on screen that has solid-coloured faces. All of the examples that I've seen have 8 vertices, with a colour defined at each vertex (red, green, blue). The pixel shader then interpolates between these vertices to give a spectrum of colours. This looks nice, but isn't what I'm trying to achieve. I'd just like a cube with six, coloured faces.

Two ideas come to mind:

  1. use 24 vertices, and have each vertex referenced only a single time, i.e. no sharing. This way I can define three different colours at each 3D position, one for each face.
  2. use a texture for each face that 'stretches' to give the face the correct colour. I'm not very familiar with textures right now, so not all that sure about this idea.

What's the typical/canonical way to achieve this effect? I'm sure this 'problem' has been solved many, many times before.

2

2 Answers

1
votes

For your particular problem, vertex coloring might be the easiest and best solution. But the more complex you models will become the more complicated is to create a proper vertex coloring, because you don't always want to limit you in your imagination to the underlying geometry.

In general 3D objects are colored with one or more textures. Therefore you create an UV-Mapping (wiki), which unwraps you three-dimensional surface onto a 2D-Plane, the texture. Now you can paint freely in any resolution you want colors on your object, which gives you the most freedom to have the model look as you want.

Of course each application has its own characteristics, so some projects would choose another approach, but I think this is the most popular way to colorize models.

1
votes

Option 1 is the way to go if:

  • You want zero color bleed between faces
  • You want zero texture bleed between faces
  • You later want to use the color as a lighting scheme ala Minecraft

Caveats:

  • Could use more memory as more verts being used (There are some techniques around this depending on how large your object is and its spacial resolution. eg using 1 byte for x/y/z instead of a float)