Blending textures with vertex colors

Hi all.



I have seen this video with blender:



http://www.youtube.com/watch?feature=player_embedded&v=rv24WsM2zaU#!



I think possibly we can add such a thing to our shaders too? If someone can give me a tip, so i'll try to make it.

It’s already implemented in Terrain materials, doesn’t it?

There is a more sophisticated way of doing that presented in this short UDK tutorial:

Vertex Painting in UDK



I implemented that version in blender and extended the lighting material to support it.

This is how it looks in blender:

http://i.imgur.com/PID3p.jpg



Test in blender:

http://i.imgur.com/lGyvU.jpg



And in JME:

http://i.imgur.com/ll01m.jpg



An example material file:

[java]

Material My Material : Common/MatDefs/Light/LightingM.j3md {

MaterialParameters {



DiffuseMap : Repeat textures/brick-tm.jpg

NormalMap : Repeat textures/brick-tmn.jpg

DiffuseMap2 : Repeat textures/dirt-tm.jpg

NormalMap2 : Repeat textures/dirt-tmn.jpg

BlendFactor : 10

BlendMap : Repeat textures/dirt-tms.jpg

UseVertexColor : true

[/java]



I uploaded the example blend file+ textures+ shaders here:

https://www.dropbox.com/s/8cktv4fqvqufbeb/vertblend.zip

1 Like

What’s the problem with using the terrain material?

  1. I’ll have a look at the terrain shader. Thanks!


  2. @remorhaz OMG!! How do you get the shader from blender? Can you explain it? And how do you convert it to JME shader?

I did not get the shader from blender to jme, I just implemented the same transformation so the result is the same.

The terrain shader does not use vertex colors so I don’t know how to get the same blending effect using just alpha maps and tiling textures.

Using vertex colors let you more control of the blending.

@remorhaz Your shader is really cool! But i did not find the difference between BlendFactor=10 and BlendFactor=0.1. Material looks the same.



Can I add your shader to ShaderBlow Project? http://code.google.com/p/jme-glsl-shaders/downloads/list

If you want I can add you there as a developer.

Also it’s interesting is it possible to combine textures with textureArray?

@remorhaz I also found a bug in your fragment shader:

[java]bc = pow(bc,10); // original

bc = pow(bc,10.0); // should be



[/java]



Some ATI card cannot compile it. If you use float, so it would be better to write 10.0, 2.0… It’s GLSL :slight_smile: .



Also That's looks much better:

[java]bc = pow(bc,3.0);[/java]

Opps, the second parameter to pow should be the material input parameter BlendFactor and not the constant 10, I forgot to change it back after some testing, thanks for finding it. This is just a proof of concept implementation and made only a couple of happy pass testing. I am experimenting with color management too so the fragment shader now converts sRGB to linear and back. I just uploaded the whole stuff as it is, sharing was not in my mind yet , but feel free to change anything and use it if you like.

Ok, I get you.



What the problem with sRGB and Linear RGB? Why do you make conversions?

When I examined blender’s glsl shaders I found that they do that, then I started to google and I found this article from GPU Gems 3:

Chapter 24. The Importance of Being Linear

This explains it better than I could.

Also for additional info and the math this wikipedia entry comes handy:

http://en.wikipedia.org/wiki/SRGB



Since I use GIMP for creating the textures and GIMP’s default colorspace is sRGB (so my textures are sRGB) I thought I give it a try and see if it makes any difference if I make the conversions in the lighting shader and it seems it does, at least I like it better.



Since opengl 3 there is srgb texture and framebuffer support as more recent GPUs support it on the hardware level.

Wow! it’s interesting. Can you show your tests screenshot with difference of modele lighting?

@Momoko_Fan , @nehon , what do you think about it? Possibly it will be cool for Lighting shader?

@mifth said:
Wow! it's interesting. Can you show your tests screenshot with difference of modele lighting?
@Momoko_Fan , @nehon , what do you think about it? Possibly it will be cool for Lighting shader?

There's not much point, given that it is already supported by the terrain material.
@Momoko_Fan said:
There's not much point, given that it is already supported by the terrain material.

I meant sRGB and Linear RGB only. Nor vertex colors.

Did you read Gems3 pages above?
@Momoko_Fan said:
There's not much point, given that it is already supported by the terrain material.


Terrain material does not use vertex colors just alpha map and scaled up UVs and of course there is no need to change the built in material system.

As for the color correction, it is a matter of taste. See below for illustration.
- Top left is blender viewport
- Top right is JME with srgb/linear transformation
- Bottom right is the unmodified lighting shader with the same material and lighting setup as top right, it is darker in general but the cement parts look a bit strange, the normal mapping effect is more intense though
- Bottom left is the unmodified lighting shader but with light intensity increased a bit, it illustrates that it does not compensate the overall darkness of the cement parts

Again, it is a matter of taste and someone would even prefer the not corrected version.

http://i.imgur.com/WFptA.jpg

sRGB colorspace is a different thing. I thought were were just discussing texture blending with vertex colors? I understand there’s a difference but really how hard is it to use a stencil texture in Blender instead of vertex color for blending? In fact texture painting gives you more accuracy than vertex color, especially in your example that uses quads.

@remorhaz can you make a test with s sphere instead of plane? And one light source.

@Momoko_Fan said:
sRGB colorspace is a different thing. I thought were were just discussing texture blending with vertex colors? I understand there's a difference but really how hard is it to use a stencil texture in Blender instead of vertex color for blending? In fact texture painting gives you more accuracy than vertex color, especially in your example that uses quads.


Of course there is no difficulty in using stencil maps in blender, the difference is that textures are material parameters and vertex colors are part of the mesh data. If you want to batch draw calls then you have to use the same stencil texture for all of your meshes (to use the same material) meanwhile if you use vertex colors you can use the same tiling textures (material) and yet have different blending on different objects. The tradeoff is that you must throw some extra vertices here and there in your mesh. So each technique has its own pros and cons.
@mifth said:
@remorhaz can you make a test with s sphere instead of plane? And one light source.


I used one directional light + ambient light.
Why don't you try it yourself?
Here is the shader:
https://www.dropbox.com/s/a4oyfvarze06ec5/LightSRGB.zip