Jump to content

Team colors


dcversus
 Share

Recommended Posts

Hi
I'm making a game where need use many of the same models in which the same texture, that has transparent. This transparency should be replaced with team colors. When I import model I set
players[0].meshModel.material.diffuseTexture.hasAlpha = false;

All transparent replaced with black color. How do I change this color?

Thanks in advance!

footman.zip

Link to comment
Share on other sites

Hi,

You cannot change the texture color directly in Babylon, but you can change the material emissive color or diffuse color.

players[0].meshModel.material.emissiveColor = BABYLON.Color3.Black();

Moreover, if your characters all use the same material, changing the color for one will change the color for every one. Be careful, and try to clone() the material each time you have a different color.

Link to comment
Share on other sites

I am not sure it will actually work... If you define something transparent, it will be transparent, meaning no color will be displayed underneath. (I might be wrong thou  ;)

I think you will need an extra object after the transparent texture to display the color. Or build a custom shader that does that. 

Link to comment
Share on other sites

Different textures difficult to use, can be a lot of teams.

I do not know how to make an object with a different texture after transparent, In my model, it is difficult to do?

I tried to use a decal looks like the emissiveColor, decal can not be under the texture, right?

I liked the idea of a shader, you can help write a shader that would replace one color to another for a single mesh???

Link to comment
Share on other sites

I decided to the task of with the use of shaders! Thank you all for answers and advice, here's the code pixel shader:

#ifdef GL_ESprecision highp float;#endifvarying vec2 vUV;uniform sampler2D textureSampler;uniform vec3 color;uniform vec3 replace;void main(void) {  float r = texture2D(textureSampler, vUV).r;  float g = texture2D(textureSampler, vUV).g;  float b = texture2D(textureSampler, vUV).b;  vec4 pixel = vec4(r,g,b,1.0);  vec3 eps = vec3(0.1, 0.1, 0.1);  if( all( greaterThanEqual(pixel, vec4(color - eps, 1.0)) ) && all( lessThanEqual(pixel, vec4(color + eps, 1.0)) ) )  pixel = vec4(replace, 1.0);  gl_FragColor = pixel;}

Hope this helps someone)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...