34
\$\begingroup\$

My question is what is written in title. This term "vertex color" appear a lot. I am having hard time to understand this.

For example:

Isn't a vertex simple point on 3D space? If so, how can a point have a color? Or does this "color" mean something else?

There is a "Vertex Color" node in unreal engine's material editor.

Can someone shed light on my question? I couldn't find anything usefull when I googled "what is a vertex color" but the documentations that are too technical for me.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ In geometry a vertex is just a point in space. But for 3D rendering you want things to look nice, which might mean attaching more information to each vertex, like a colour, or a texture coordinate, or skeletal weights so you can animate the mesh more easily, or a normal direction to use in lighting calculations. \$\endgroup\$
    – user253751
    Mar 23, 2017 at 19:51
  • 3
    \$\begingroup\$ I think a big part of your confusion is because of the frequent conflating of terms “vertex” and “position” in 3D/graphics. Mathematically, your statement “Isn't a vertex simple point on 3D space?” is correct, but in the realm of game engines & graphics, no, a position is a simple point in 3D space; and a (mesh) vertex is a piece of data that almost always has a position, but may also have a normal, tangent, texture coordinate, color, and/or any of numerous other pieces of data. A mesh vertex is really just a chunk of data that's processed at the vertex stage of rendering. \$\endgroup\$ Mar 29, 2017 at 8:43

5 Answers 5

32
\$\begingroup\$

Vertex colors aren't that relevant when you have a fully textured 3d mesh. But it gets interesting when you have an untextured but colored mesh. In that case you assign a color to every vertex. The shader would then color each pixel of a polygon by interpolating between the colors of the three vertices.

Vertex colors can also sometimes be interesting in combination with textures. When you want to use a shading algorithm like Gouraud Shading, you just calculate the light intensity on each vertex, assign the light color to the vertex as a vertex color, and when you render the texture you multiply the color value of each texture pixel with the interpolated colors. This allows you to calculate light sources in the vertex shader instead of the pixel shader. This is usually far faster, because the vertex shader is usually executed far less frequently.

\$\endgroup\$
4
  • 2
    \$\begingroup\$ btw, vertex color was used in some older games that didn't have any dynamic lightning/shadows. For example Richard Burns Rally from 2004 is using vertex color to create different looking textures and apply shadows. \$\endgroup\$
    – martin
    Mar 24, 2017 at 6:22
  • \$\begingroup\$ The Witness is a recent game that makes extensive use of vertex colours and lightmaps, but not many textures. \$\endgroup\$
    – user253751
    Aug 23, 2019 at 0:52
  • \$\begingroup\$ @Philipp "because the vertex shader is usually executed far less frequently" Why? Isn't the vertex shader part of the rendering pipeline and thus executed each frame? Why so less frequently? Wouldn't the vertex "color" have to be calculated every frame as well, just as if it was in the pixel shader? \$\endgroup\$
    – KeyC0de
    Nov 7, 2019 at 11:31
  • 1
    \$\begingroup\$ @Nikos A vertex shader is called once per vertex. A pixel shader is then called once per pixel. A polygon with 3 vertices usually results in more than 3 on-screen pixels (if your game ends up calculating a lot of polygons which cover less than 3 pixels, you might want to look into what you can do regarding culling and LOD). \$\endgroup\$
    – Philipp
    Nov 7, 2019 at 12:42
26
\$\begingroup\$

In theory, Vertex Color allows to color a model without having to bother with textures. This is quite common in CAD.

enter image description here enter image description here enter image description here enter image description here

In practice, it's just one more slot you can use to push data into the vertex, which you then use in the vertex shader to do crazy stuff.

"Isn't a vertex simple point on 3D space?"

That's what I used to think, when I first started with 3D. I learned quickly that I was wrong.

You can think of a vertex as a data blob that makes up a corner of a triangle you want to paint on screen (and neither the "corner" part nor the "triangle", "paint", or "screen" parts are always true). Position is one -optional - aspect of that data blob we call Vertex.

There is a lot you can do by attaching additional data to the vertex. The most famous example is that you can add uv coordinates to draw a texture on that triangle. You (usually) can't decide what part of a texture to draw on the triangle if you just have a point - you need texture coordinates too.

Other standars examples of what's in that blob are normals, and tangents. What's important is that all of them are optional, including the position. Vertex Color is just one of these optional inputs that you can use or abuse to create a pretty picture on the screen.

\$\endgroup\$
11
  • 2
    \$\begingroup\$ ".. as a data blob that makes up an edge of a triangle" even that is not necessarily. Vertexes could be rendered as points just fine. \$\endgroup\$
    – Kromster
    Mar 23, 2017 at 12:53
  • 4
    \$\begingroup\$ For some great examples of the shader effects you can achieve using vertex colours, I highly recommend checking out Natalie Burke's GDC talk from last year, "Animating With Math" (video is members-only at the moment, but the slides are free here). She shows how many of the animations in Destiny's gear, character hair and cloth, and even parts of their enemies and environments were achieved using vertex shaders, shaped and controlled with vertex colour channels. \$\endgroup\$
    – DMGregory
    Mar 23, 2017 at 12:59
  • 5
    \$\begingroup\$ I'd argue, that those were not vertex colors, but vertex attributes shown as colors for easier perception. \$\endgroup\$
    – Kromster
    Mar 23, 2017 at 13:04
  • 1
    \$\begingroup\$ There are some similarly inventive uses of vertex shaders in this talk about FortNite, although if I recall correctly I think they mostly used the vertices' UV channels rather than colour channels. \$\endgroup\$
    – DMGregory
    Mar 23, 2017 at 13:15
  • 4
    \$\begingroup\$ Strictly speaking from a geometry/maths-based point of view a vertex is just a point in space. The 'vertex colour' is an attribute applied to the vertex by the 'idea' of a vertex used by GPUs. It's the same as a circle having a colour or not. The geometric/mathematical 'idea' of a circle does not have a colour but the rendering software 'idea' of a circle associates a colour to the circle. Thus @Kromster's argument is more technically correct. \$\endgroup\$
    – Pharap
    Mar 23, 2017 at 23:55
9
\$\begingroup\$

Vertices can have colors, it's a property just like the normal of it.

In 3d enviroments a triangle gets colored based on their vertices' color information. The closest fragments to vertex A get the color of it, the closesr to vertex B get the colornof B, and the color interpolates between the 2.

It works the same way as per-vertex lighting

It's an easy way to add colors to a model without using a texture.

\$\endgroup\$
5
  • \$\begingroup\$ +1 for giving a (hopefully) familiar example of another similar vertex attribute \$\endgroup\$
    – A C
    Mar 23, 2017 at 16:43
  • \$\begingroup\$ The problem with vertex colors and normals is that they assume the vertex is part of a mesh (an approximation of a curved surface). If you want sharp edges or different colored faces (such as on a cube), you need separate vertices for each face, which greatly increases memory usage (and slows rendering). \$\endgroup\$
    – amI
    Mar 23, 2017 at 21:19
  • \$\begingroup\$ @aml You can use the flat "operator" in glsl to output make the shading look flat. It's not completeley the same, but it works. \$\endgroup\$
    – Bálint
    Mar 23, 2017 at 21:51
  • 1
    \$\begingroup\$ other interpolated attribute : texture coordinate and z-buffer ! we have the vertex shader computing some data for each of the 3 vertices of the triangle, those are interpolated when drawing the triangle on the screen (or in some buffer), and the pixel shader is called with the interpolated value for each drawn pixel \$\endgroup\$ Mar 24, 2017 at 14:37
  • \$\begingroup\$ @aml Of course x2 isn't a bottleneck. And geometry shaders are made for that, I'd say (e.g. : transforming a depth texture into triangles) \$\endgroup\$ Mar 24, 2017 at 14:38
1
\$\begingroup\$

There are solid answers here already - I just want to chime in with one more common way you'll see vertex colours used:

Varying object colours (or other attributes) within a single batch / draw call.

You'll see this used in rendering particle systems, text, and batched (usually atlassed) sprites.

Imagine you have a particle emitter that spawns particles with a random start colour, or that fade to 0 alpha over the particles' lifetime. If we were to use shader uniforms to send this colour data, we'd need to draw each differently-coloured particle in its own draw call, making the particle system much more expensive. Instead, we can bake these colours into the vertex data for the particles, and render the whole batch together in a single call.

Unity appears to use this technique for particle colour variation, as well as for colouring individual characters in a TextMesh or Sprites rendered together in a batch.

\$\endgroup\$
0
\$\begingroup\$

In the context of Roblox, vertex color is a Vector3 with a range of 0...1 (negative values -1...0 are flipped and treated the same as positive values). The greater the value, the brighter the color is.

\$\endgroup\$
1
  • \$\begingroup\$ also in roblox studio try some texture on special mesh (file mesh) in a part with this link: geogebra.org/m/Dq2A7aRv and move the a b c as same as your rgb color that is on brick part (Color) and use the abc on vertex color on special mesh and tada it will be the same color as the brickpart (or the intended color you like) also sometime its broken. (i tried my best to make you understand cuz i dont really like to talk much) \$\endgroup\$
    – icee2553
    Sep 14, 2022 at 12:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .