Ambient pass problems – models semitransparent

I have issues with new Ambient pass for Lighting shader. It is way too bright for my needs and on top of that, I had a custom shader which used to cancel part of ambient color based on texture parameters. Now it seems to be not possible, as ambient color is in separate pass (so I would have to replicate all logic in custom ambient part of the shader). I tried to delete Ambient pass from my custom shader and reintroduce ambient part of vertex shader. It almost works, just for some reason, all my models became semitransparent out of the sudden. It looks a bit like 0.5 alpha applied to all of them. They do not have any alpha/transparent queue/etc attached to them, so it is bit magic.

Edit: some observations

Models are semitransparent only if drawn on top of things using Lighting.j3m. If I position camera so model is drawn over skybox, it is drawn properly (no transparency).

They are for sure not in transparent queue, they are drawn in wrong order for transparency (front to back) - so they are obscuring other models, but things with ambient pass shine through them.

If I enable bloom filter, models become even more transparent.

On top of that, objects with glow color are leaving traces on skybox as I move the camera (but this can be possibly old issue, I have never tested this thing before).

I had to readd the ambient stage to my shaders to get them opaque, with wonderful fragment shader being


void main(){

gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);



Still, light is way off what I used to have previously. I do not really understand the idea of ambient pass. Wouldn’t it be better to have specific light type called AmbientLight (as opposed to DirectionalLight and PointLight) which would provide ambient for object? At the moment, I cannot have strong diffuse light (from DirectionalLight) as it is blowing ambient out of proportion. I suppose that I can manipulate ambient color of objects to be a fraction of previous values, but first I would like to understand what is the reasoning behind the change ?

how about just amking the ambient lower and the direct higher?

We didn’t have ambient light before, so all objects that did not have a light directly shine on them were black.

Generally this is not preferable, you want some ambient to exist so you don’t have a light effecting every part of your scene.

It’s possible to add an ambient light, but it would require running the entire Lighting.frag pixel shader on it which is not needed.

The issue with the transparency should be fixed in recent revision, by the way

I have managed to reintroduce explicit ambient pass in my shaders, thanks for the fixes.

One thing which bugs me, is why in AmbientPass.frag, we have

vec4 color = m_Ambient;
color.a = m_Diffuse.a;

why alpha channel is taken from diffuse material color? I could understand that it is later taken from diffuse map (which is not really diffuse map, as it is also used for ambient ;) ), but base one?

Its kind of a standard for us. The alpha is the product of diffuse color alpha and diffuse texture alpha. Before it was a lot more complex and taking alpha from ambient and specular too.

For the end user its better, usually people have transparency set on the diffuse map (this was the common way pre-OpenGL2) and same thing goes for diffuse color.

With this method, you can make a model transparent by either changing diffuse color alpha or by having an alpha channel in the diffuse map

I probably had a bit different use case - for me, ‘diffuse map’ was in fact ‘decal texture’. For non-transparent case, it doesn’t matter, but for transparent case, I wanted texture transparency to control how much of base color is visible (and then, possibly have object transparency controlled with base color alpha).

Anyway, beauty of shader system is that I’m able to make my own version very easily :slight_smile:

Or you could make that feature available as a boolean for the current Lighting shader and then it could become a core jME3 feature :smiley: