dcversus Posted May 21, 2015 Share Posted May 21, 2015 HiI'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 setplayers[0].meshModel.material.diffuseTexture.hasAlpha = false;All transparent replaced with black color. How do I change this color?Thanks in advance!footman.zip Quote Link to comment Share on other sites More sharing options...
Temechon Posted May 21, 2015 Share Posted May 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
dcversus Posted May 21, 2015 Author Share Posted May 21, 2015 Thanks for the answer.When I use emissiveColor becomes not so necessary I need to replace certain parts of the texture to another color like this (I manually painted texture): Maybe can use a dynamic texture? But I do not understand how Quote Link to comment Share on other sites More sharing options...
RaananW Posted May 21, 2015 Share Posted May 21, 2015 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. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 21, 2015 Share Posted May 21, 2015 Hello, if you want you can either use different texture files with all the color OR you can use two objects like Raanan mentioned OR you can use decals Quote Link to comment Share on other sites More sharing options...
dcversus Posted May 21, 2015 Author Share Posted May 21, 2015 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??? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted May 21, 2015 Share Posted May 21, 2015 Decals can be used on top of emissiveColor:http://doc.babylonjs.com/page.php?p=25094 And yes decals can be under a texture Quote Link to comment Share on other sites More sharing options...
dcversus Posted May 22, 2015 Author Share Posted May 22, 2015 I was not able move decal with character (charapter have animations) and place it under texture. The decal can be moved together with the animation of the skeleton? Quote Link to comment Share on other sites More sharing options...
dcversus Posted May 22, 2015 Author Share Posted May 22, 2015 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) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.