i have a problem with UseAlpha. It doesnt seem to work properly. I made a texture which is translucent, except for the eye region. On the following screenshot, the eye should be white, but it seems that the diffuse color shines through:
Seems like the eyes are being drawn behind the eye sockets. It’s the only way they’d be green unless the eyes are actually the same geometry (also possible with information provided).
The eyes and the body are the same geometry. There are other geometries in this model. It seems that the model was split up when I imported it from Blender, so I used
the appropriate geometry to set the texture.
Probably the problem gets more clear with the texture:
This is a screenshot from gimp so that its visible where the translucent spots are. I think the eyes should be shown in white, while the rest of the body should be green, and of course the texture should be visible on the body,too.
I want to set the texture for all geometries in the model to one texture. The texture will be partly transparent where the armor
will be painted, so the resulting color will be an armor that is a combination of the texture and the underlying diffuse color.
However, there are areas on the texture that may not be affected by the diffuse color (for example the eye or the belt, which
have always the colors specified in the texture), thats why they are not set transparent.
This way you can have a lot of different character looks with just one texture, that saves a lot of work.
I am not sure if I unterstood the content of this wiki page correctly.
So what would you recommend to enable using models with textures and the ability to change the color at runtime?
That page is just talking about making parts of your texture transparent against the rest of the scene. I’m not sure what the easiest approach is for you. It’s something that I would write a custom shader for but that’s kind of advanced.
@pspeed said:
He wants to use alpha for controlling how the diffuse color is mixed with the texture... not to control the alpha of the texture as is conventional.
Ohhh I see, Can’t you do this with one of the settings in lightblow shader maybe? If not, maybe a simpler way would be to make multiple armor textures in different colours and apply them as necessary
Do I really have to write an own shader or did I do something wrong?
The above site states:
It is possible to load a DiffuseMap texture that has an Alpha channel, and combine it with an underlying Material Color.
mat.setBoolean("UseAlpha",true);
The Material Color bleeds through the transparent areas of the top-layer DiffuseMap texture. In this case you do not need BlendMode Alpha – because it's not the whole Material that is transparent, but only one of the texture layers. You use this bleed-through effect, for example, to generate differently colored uniforms, animals, or plants, where each Material uses the same "template" DiffuseMap texture but combines it with a different color.
Note: I’m not saying that what you want is not a desirable feature. I guess it wasn’t used as often as fading a whole texture and stuff.
Maybe someone will add it back as a different mode or something but I don’t have time to right now. I think it’s a matter of changing a color * diffuse to mix(color.rgb, diffuse.rgb, color.a) or something.
It’s funny because the UseAlpha flag isn’t even used right now. Maybe it could be changed to do the current behavior if true and use alpha as a color mix value if not.
Might be better to just get rid of that setting and change it to something clearer. UseAlphaMask or something to get the behavior you want.
As I said, I don’t have time to add it right now but maybe someone else does… but it would be in trunk and not in any release. Actually, looking at the shader it is more complicated than that. The diffuse color is mixed in with the lighting color. It would be easier to add to unshaded but I suspect you want lighting.
@javagame said:
Ohhh I see, Can't you do this with one of the settings in lightblow shader maybe? If not, maybe a simpler way would be to make multiple armor textures in different colours and apply them as necessary
Ah… the light blow shaders may be able to handle this. I’ve never looked at them, though.
I think I found the solution:
[java]
ninja = assetManager.loadModel(“Models/ork_temp/orkblend_temp.j3o”);
Node gm2=(Node) ninja;
Geometry g=(Geometry) gm2.getChild(“meHumanMale.0011”);
Material mat = new Material(assetManager, “Common/MatDefs/Misc/ColoredTextured.j3md”);
In the material editor for the a for lighting.j3md material there is a boolean on the left called useMaterialColors that will blend your diffuse map with the diffuse colour, according to the editor you should not need to make your image transparent though, this will blend the entire diffusemap with that colour, and it should work fine in code, just set that boolean to true and set a diffuse, and then see what happens!