Home Technical Talk

Vertex color and performance

I'm kinda new to the idea of using vertex colors to blend textures but it seems extreamly useful. From what I understand it can be applied in different ways like for instance painted in Maya etc (where all exported instances of that model will have the same vertex colors), or they can be painted in an editor like UDK (where every instance can have unique vertex colors).
So I'm wondering what the general approach is to add vertex color to game assets. Is it used extensively on most models or is it an expensive feature that should be used only when needed? I suppose it's cheaper to use static vertex colors than to add unique ones for every instance of a model, but how big is the difference?
I understand there are a lot of variables to take into consideration and that it's difficult to give exact answers without having specified details but I'm just looking for a general direction. Any pointers and input on the subject would be helpful:)

Replies

  • Xoliul
    Options
    Offline / Send Message
    Xoliul polycounter lvl 14
    as far as I know the vertex color in itself is not expensive in UDK, I vaguely remember someone calling it "free" but I'm not sure fi that's the truth.
    A lot depends on what you do with it in the shader though.
  • Jeff Parrott
    Options
    Offline / Send Message
    Jeff Parrott polycounter lvl 19
    Well instancing the vertex color on an object means you'll be instancing the object itself anyways. That depends on the engine. Vertex color (and vertex alpha most of the time) is not that expensive now days. I've worked on plenty of project on platforms that couldn't support lightmaps so vertex color (and vertex alpha) were only available. I know vertex alpha adds up. But vertex color even on lower end systems is not that huge of a deal (at least in my experience).

    You can paint vertex color in most 3d applications including Maya/Max, etc as well as UDK. You can also instance objects but keep in mind that lighting specific places (hard shadows on 1 side due to a bright light near it) will be all over that level and might look out of place at times.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    the vertex colours them selfs are extremely cheap to use, the part that could be expensive, is needing to give your meshes more verts so you can paint on them, and what your doing with the vertex colour since ultimately the material will use more texture calls, unless your just manipulating the current textures in the shader.


    other thing to consider, is that just plugging vertex colour into a lerp with 2 textures causes a even gradient transition between the 2 textures where you paint, which makes it almost needed to use a mask or a height map to effect the blending, a lot of people use a height map to make the 2nd texture fill in the cracks and crevices of the material first, and sometimes use a other vert colour to paint in the softness or hardness of the transition.

    if you want some help with that, i could share my shader network for a vertex shading material i made, and point you too the information i used to make it.
  • Eric Chadwick
    Options
    Offline / Send Message
    Vertex color (and vertex alpha) add a little bit to the memory cost for each model. It's more data. For a few assets here and there, nothing big. But if you add to every single asset in the game, and the terrain, and the skies, then it could all add up to several megabytes of additional data.

    I recently had to beg the engineers to let me, when I wanted to add vertex color to all our MMO terrains, because this would add many megabytes to a downloadable game. Not something you think about, until it hits you.

    But yeah, it's generally cheap, and effective. We added some stuff on the wiki about vertex color, and blending. http://wiki.polycount.com/Multitexture
  • o2_is_alright
    Options
    Offline / Send Message
    Thanks a lot for your input guys.

    @Xoliul Ok, that makes sense that what matters more in the end is the material complexity rather then the actual vertex color data.

    @jeffro Instance was maybe the wrong term to use. I was just trying to diffrentiate between when the vertex color data is exported and saved in the model file, and when (for instance in udk) you can paint values uniqely on copies of the same static mesh so the vertex color data is different for all copies.
    I'll be using Unreal for this so thankfully I'll have lightmaps and don't need to worry with lighting with vertex colors.
    And about the alpha channel. Would it be correct to think of it as you would with the alpha channel in a texture sample in terms of how much it increases the file size?

    @passerby I'm watching the tutorial "Advanced mesh paint with udk" tutorial on 3dmotive at the moment. Haven't finished it yet but it sure looks like the material will be quite complex in the end. They're doing what you said about using masks and the different channels for different things. I'd very much like to see your shader and how you set it up. Thanks for sharing:) Always interesting to see different solutions and examples.
    And... Sorry if this is a silly question, but if the shader or material is what might affect performance most, wouldn't using material instances be a good solution? Or it's not that simple? It's probably not, but had to ask.

    @Eric Chadwick Good job in convincing them engineers. Bet they didn't regret their decision when they saw the result:) Although that sounds like a quite extreme example but still, definately something to keep in mind.
    And I should have known better than to forget to check the wiki. Great info as always. Will continue reading tomorrow.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya instancing it would help a bit, also adding some static switch parameters to the material will allow you to enable and disable certain sections of the shader.

    when i get home i will take a little screen shot of the material for you, the last one i made was for a brick wall, and it blends between 2 diffuse maps, and modify's the the normal map and blends between 2 different detail normal maps.

    iirc it was 83 instructions and 5 texture samples, but it is easy to drop the amount of texture samples needed if i just combine a few things.

    edit:

    so here is the shader, the first image is the part that does the vertex blend with the height map effecting it.
    screens_20111206200715.jpg

    this shot is of the whole shader.
    screens_20111206201031.jpg

    and this is a newer verison of the same shader, where i moved the heightmap blend and vertex paint stuff to a material function, to clean things up a bit, and also added tinting, of 2 sets of masked off bricks based on vertex colour.
    screens_20111206201748.jpg

    and a quick screen of the result.
    screens_20111206204731.jpg

    i based the blend hardness bit on tutorial Laurens Corijn made.
  • o2_is_alright
    Options
    Offline / Send Message
    That's very interesting to to see how you set up the material. The OneMinus nodes in the beginning of the Blend Cover and Blend Hardness sections confused me a bit though. What's their function? I liked the part where the detail normals changes with the bland too.
    In the tutorial I've watched they had a different setup for the blend. They started off with:
    red vertex color + heightmap -> subtract node -> divide node.
    Divide + green vertex color -> clamp -> lerp alpha...

    Hope that makes sense, couldn't add an image at this time. I'm guessing this is just another way of doing the same thing?
    Anyways, thanks alot for sharing the material, it looks great!
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    the oneminus just inverts a texture, im useing it because normally a height map uses white for high values black for low but in the case of my vertex blend, i want the opposite to happen, i did the same with the vertex paint too since by default vertex paint is white, so maxed out on all 4 values, so adding the -1 node makes it so by default there is no blend applied.


    with the normals i got a few things going on.

    with the detail normals, got a simple lerp driven by the height-map vert blend, than i mask off the blue channel, and multiply by parameter so i can control the intensity of the detail normals in a material instance, than i append back a blue channel of 0, since i don't want any blue in my detail normals, so it adds to the base normal map better.

    the more interesting part of the normals is how im using the vertex paint to modify the existing normal map, i wanted the bricks with moss cover to look less deep than bricks without moss, so i mask out the blue channel again because i dont want to mess with it, than multiply the red and green, by a decimal number to make them less intense, and append back the original blue channel of the normal map, and plug both the modified normals and the original normals into a lerp controlled by the blend section of the shader.


    ya the method you mentioned would work too, and accomplish the same thing, i might make it like that and see if it's looks different or is cheaper.

    there are a lot of cool things you can do with it too. Since heightmaps and normal maps are quite easy to modify in shader, you could even do things like a 2 layer vertex paint shader, where you paint in say cracks into concrete or stone floor, than have it darken the height map used my the next vertex blend in those areas, so you can later fill them with a other blend like say water for making puddles, than because the part changed values in the height map the water would only fill in places you damaged with the first vertex shader, and things would just work no matter what order you go in on the 2 parts of the vertex blend.

    Things like that is why i just made a function out of my vertex blend, so i can quickly drop more than 1 of them into a material and choose what vert colour does what.
  • o2_is_alright
    Options
    Offline / Send Message
    the oneminus just inverts a texture, im useing it because normally a height map uses white for high values black for low but in the case of my vertex blend, i want the opposite to happen, i did the same with the vertex paint too since by default vertex paint is white, so maxed out on all 4 values, so adding the -1 node makes it so by default there is no blend applied.

    Alright, that makes sense. The math nodes can be quite tricky to understand sometimes I think. I knew OneMinus inverts textures but couldn't put the pieces together in this context:)

    Cool stuff you've got going on with the normals. That's definately something I'm gonna try with my material.
    Gotta love Unreals material editor. It's great how you don't need to be a math person (although I guess it helps) to be able to create awesome materials and really tweak them down to tiny details:)
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya i could just invert the height map in photoshop, and forgo the OneMinus but i actually do use it as a height-map for my bumb-offset in the material so prefer to keep it setup like a normal one.

    if you want anything else explained just ask.
Sign In or Register to comment.