TeamColor

Hi,

how can i create a material with an area for the teamcolor?

It should be also possible that some parts of the texture are transparent.



Example:

http://warcraft.ingame.de/das_spiel/exp/img/healthbar.jpg

(All units of player 1 are red)

  1. Option: Different Models.
  2. Option: Textureoverlay. A second layer given in different Colors.
  3. Option: Give the texture a crazy pink where it should be colored in teamcolors and replace the crazy pink ( or any other color, rly. ) with the teamcolor at runtime in a shader or after laoding or …
  4. Option: Adding an ambient light with the color ( Changes the WHOLE appearance )
  5. Option: ???
  6. Option: Profit!

Ah, I found this where it is explained how to create your own material definition:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:jme3_shaders?s[]=shader#exampleadding_color_keying_to_the_lightingj3md_material_definition

You could write a frag shader that checks against the sample for a value between x color and y color and then replaces it with the color you define.



i.e. in your textures, use something like BRIGHT pink.



In the frag shader you check the sample for a variance of this color and replace it with the color you want to show up. It would look some like this:



[java]

uniform vec4 m_PlaceholderColor

uniform vec4 m_TeamColor;

uniform sampler2D m_Texture;

varying vec2 texCoords;



void main(){

vec4 color = vec4(1.0);



vec4 sampleColor = texture2D(m_Texture, texCoords);

if (sampleColor.x > m_PlaceholderColor.x-YOURVARIANCEVALUE

&& sampleColor.x < m_PlaceholderColor.x+YOURVARIANCEVALUE

&& sampleColor.y > m_PlaceholderColor.y-YOURVARIANCEVALUE

&& sampleColor.y < m_PlaceholderColor.y+YOURVARIANCEVALUE

&& sampleColor.z > m_PlaceholderColor.z-YOURVARIANCEVALUE

&& sampleColor.z < m_PlaceholderColor.z+YOURVARIANCEVALUE) {

color *= m_TeamColor;

} else {

color *= sampleColor;

}

gl_FragColor = color;

}

[/java]



You would have to incorporate this into the jme lighting.vert & frag to do everything you want… but it would work fine.



I just read the example in the link you have there. I guess either way you do it, there will be a slight potential of color bleeding due to the way the samplers work. However, I would chose a key color other than black, as that is a far more useful color than say… neon green, etc.



Another way you may want to try is mapping to transparency.



basically:



[java]

uniform vec4 m_PlaceholderColor

uniform vec4 m_TeamColor;

uniform sampler2D m_Texture;

varying vec2 texCoords;



void main(){

vec4 color = vec4(1.0);



vec4 sampleColor = texture2D(m_Texture, texCoords);

if (sampleColor.w = 0.0) {

color *= m_TeamColor;

} else {

color *= sampleColor;

}

gl_FragColor = color;

}

[/java]



This assumes that your texture do not have transparencies of 0.0 anywhere except where you want your team color.

1 Like

In the example I add another texture to the material which specify where the team color should be.

I think this is a better way than drawing with pink on my diffusemap.