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
A lot depends on what you do with it in the shader though.
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.
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.
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
@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.
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.
this shot is of the whole shader.
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.
and a quick screen of the result.
i based the blend hardness bit on tutorial Laurens Corijn made.
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!
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.
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:)
if you want anything else explained just ask.