How to tint a texture

Hi all, I’m using JME3, I’ve seen that MaterialState and some other stuff is gone, how can I add a tint effect to texture?



Thanks in advance…

Since you are asking about MaterialState I suggest you g through the material tutorial: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:beginner:hello_material

“Tint” depends on which shader (Lighting, SolidTexture etc) you use.



Edit: Oh, and as a jME2 veteran, ban all those updateXXXState() from your code, you don’t need them, if you feel like you do theres something wrong.

Ok thanks, I’ve read the Materials intro and I could even create a custom one using the material editor, It’s based on the ‘Lighting’ definition, is there a way to apply some tinting to the texture using this definition so I can keep the shadowing effect? I’m triyng to shade some cubes and I want to colour them without loosing the per-face shading I got with hand-coded normals. May be a picture explains it better :wink:







And NO, I’m not writing a Minecraft clone :slight_smile:

Use the parameter “Diffuse”

Sorry but I’ve tried and It does not work. Setting on UseMaterialColors does not work either. I get maybe a darker texture with some colors and no texture at all with others like pure Red. What could I do to acheive what I want? I mean, a way to blend the texture colors with the Diffuse color in the material…



Anyone?

So there is no way to use Lighting matdef and blend the DiffuseMap texture with a color? Please, is there another way to get the same result?

Pushing up this year old item because I need exactly this: There’s a given texture (without Alpha channel/transparent areas) and I need to color it conditionally. I tried ColoredTextured.j3md, but to no avail since the ColorMap simple overrides the Color. Same for Lighting.j3md where DiffuseMap overrides Diffuse. I’m pretty certain this must be possible in a very easy fashion, but I guess it’s well hidden :slight_smile:



Can anyone help out?

Particle effects do something similar to this (they colour a greyscale texture) so it might be worth looking at how they do it. I think you might need a custom shader though.

D’oh, figured it out:



[java]

mat = new Material(am, “Common/MatDefs/Light/Lighting.j3md”);

mat.setTexture(“DiffuseMap”, texture);

mat.setColor(“Diffuse”, ColorRGBA.Red);

mat.setColor(“Ambient”, ColorRGBA.Red);

mat.setBoolean(“UseMaterialColors”, true);

[/java]



The trick is the “UseMaterialColors” flag. So now the texture is tinted red. I still don’t know though, how the material determines how “intense” the tinting is. It fits my need right now, but understanding it would be great, too :slight_smile:

1 Like

If I remember right, you can intensify (or diminish) a color by multiplying it (or dividing it).



[java]

ColorRGBA brightRed = ColorRGBA.Red.mult(5.0);

[/java]



That should multiply the red by 5. Although, truth be told, at a certain point saturation is so high that it shouldn’t make a difference.

@madjack said:
If I remember right, you can intensify (or diminish) a color by multiplying it (or dividing it).

[java]
ColorRGBA brightRed = ColorRGBA.Red.mult(5.0);
[/java]

That should multiply the red by 5. Although, truth be told, at a certain point saturation is so high that it shouldn't make a difference.


Note that mult() will also affect alpha... so sometimes you have to reset it to 1.0.