Problem with UseAlpha material setting

Hi,

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:

Code:
[java]

ninja = assetManager.loadModel(“Models/ork_temp/orkblend_temp.j3o”);
Node gm2=(Node) ninja;
Geometry g=(Geometry) gm2.getChild(“meHumanMale.0011”);
g.getMaterial().setColor(“Diffuse”, ColorRGBA.Green);
g.getMaterial().setTexture(“DiffuseMap”,
assetManager.loadTexture(“Textures/untitled.png”));
g.getMaterial().setBoolean(“UseMaterialColors”,true);
g.getMaterial().setBoolean(“UseAlpha”,true);
rootNode.attachChild(ninja);

[/java]

Greetings

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:

Bild hochladen

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.

Greetings

Yes, well you told it to tint the whole mesh green:
g.getMaterial().setColor(“Diffuse”, ColorRGBA.Green);

I’m not sure what result you expected otherwise, actually.

1 Like

Actually the basic idea is that you can change the color of the armor for example. Its also described here:

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:how_to_use_materials#optional_transparent

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.

So you’ve written a custom shader? If so then something must be wrong with it.

If it’s one of the JME shaders then frag color = texture color * diffuse color basically. So you will not get the effect you desire.

2 Likes

Basically I have just started using JME. No idea of shaders at all. I imported the file from blender and loaded it with the code above.
I read about the effect here:
https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:intermediate:how_to_use_materials#optional_transparent

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.

1 Like

HI!

I think you forgot to add your alpha map :slight_smile:

g.getMaterial().setTexture(“AlphaMap”, assetManager.loadTexture(“Textures/untitled_alpha.png”));

Oh, hang on, does your diffuse map already have one in the alpha channel? you don’t need to call the above and then

g.getMaterial().setBoolean(“UseAlpha”,true);

Its one or the other.

@javagame said: HI!

I think you forgot to add your alpha map :slight_smile:

g.getMaterial().setTexture(“AlphaMap”, assetManager.loadTexture(“Textures/untitled_alpha.png”));

Oh, hang on, does your diffuse map already have one in the alpha channel? you don’t need to call the above and then

g.getMaterial().setBoolean(“UseAlpha”,true);

Its one or the other.

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.

@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.
@umask007 said: Do I really have to write an own shader or did I do something wrong?

The above site states:

That quote is no longer correct… for maybe a year and a half it is no longer correct. I guess it’s been tough to find all of the mentions of it.

1 Like

So whats the new way to do it?
Writing an own shader doesnt seem an alternative because I have zero experience in it.

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 ll take a look at it, thanks

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”);

mat.setColor(“Color”, ColorRGBA.Red);
mat.setTexture(“ColorMap”, assetManager.loadTexture(“Textures/untitled.png”));
g.setMaterial(mat);

[/java]

but now the lighting is missing. The model looks bad. What to do?

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!

1 Like