I am getting odd shadows on a smoothed sphere. Why are they there and how do I get rid of them?

Alright, thank you very much!

Note: ambient will only increase the brightness of the ‘nonlit’ side of an object if that object has an ambient color. If you set the “DiffuseColor” material parameter then also remember to set the “AmbientColor” (likely to the same value).

I don’t see a “DiffuseColor” or “AmbientColor” in the Lighting.j3md material. I do have this though, if this is what you were talking about:

mat.setColor("Ambient", color);
mat.setColor("Diffuse", color);

Boosting the ambient like mat.setColor("Ambient", color.mult(2f)); does seem to do exactly what I want, thank you!

Yeah, I forgot which ones we add Map to and which ones we add Color to.

Usually, set ambient and diffuse the same. Then control the ambient ‘intensity’ of your scene with the ambient light.

Bumping up the ambient seems to brighten everything, not just the brightness of the ‘nonlit’ side of the object. Perhaps I misinterpreted something though.

As far as I know it should work exactly like that.

Oh! pspeed was just talking about the ambient property on the material, not the ambient light. I did misinterpret something. My bad!

Hrrm, but it was also mentioned:

Set the diffuse and ambient the same for your materials. (unless you require them to be different for some special case)

Control the overall brightness of your scene with the regular lights.

“I increased ambient super high and now everything is super bright!”

Then your main light is too bright for your ambient value. Ambient will up the level of everything. The main light will only up the level of stuff that is lit.

Ah yeah, I know I set it super bright. I was just showing that it lit up everything (like it was supposed to).

So if I wanted the darker part of the sphere to be the color it is in the super bright image, but have everything else be around the same light level it’s at in the other images, my best course of action is to crank up the ambient color in my material?

I’m just trying to light up the dark spots a bit without lightening up the entire scene as a whole.

No, your best course of action is to the light the scene properly.

“The lit parts are too bright.” means your main light is too bright. I’m not sure why setting this lower is a problem for you.

I’m sorry about the miscommunication :confounded:

Here’s my desired result:

The relevant code I use to accomplish this is:

//sphere mat
mat.setBoolean("UseVertexColor", true);
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Ambient", color.mult(3f));
mat.setColor("Diffuse", color);
mat.setColor("Specular", color);
mat.setBoolean("VertexLighting", true);

//ambient light
al.setColor(ColorRGBA.White.mult(0.1f));

I’m asking if this is the correct way to achieve what I want in the pic above or not. How I’m interpreting you guys now is that this line of code is wrong:

mat.setColor("Ambient", color.mult(3f));

and that I should be tweaking the value I give to the ambient light itself instead:

al.setColor(ColorRGBA.White.mult(0.1f)); //this value

My argument with the very bright scene pic I posted was that if I crank up the ambient light to make the right side of the sphere lighter, I end up making the left side of the sphere too bright, because the ambient light lights up my entire scene, which I don’t want.

1 Like

Thats how Ambient Lighting works. You have to reduce your main light to achieve the desired effect actually.

The difference between changing the Ambient Color and the Ambient Light is: The first one is on a per Material base and the second one is for the whole Scene. I guess you also want that behavior on another sphere, a cube and all, so take case b.

Oh! Thank you! I totally understand now! I dim the directional light and make my ambient light more powerful. Yes that achieves exactly what I want as well. Thank you everyone for your patience and helpfulness!

Don’t be ashamed of being new, this stuff is hard and takes a long time to get your head around. We have all asked ‘silly’ questions at some point, I perhaps have asked the silliest, so don’t feel bad. =)

1 Like

Alright, so I’ve actually… tried a simpler shape. Same lighting configuration and such, and I get this:

This “”“tree”"" is made up of two simple icosphere meshes added to the scene separately. There is no smoothing and they’re both made up of 12 vertices I think.

I am using the stock Lighting.j3md instead of the one I made for the sphere. However, trying the one I made for the sphere doesn’t fix the weird shadows I’m getting. Playing with the shadow edge thickness doesn’t have any impact either.

Should I make another copy of Lighting.j3md and play with the PolyOffsets again, or is there something else wrong here?

How it looks with disabled edge filtering?

BY disabling edge filtering do you mean just removing this line?:

dlsr.setEdgeFilteringMode(EdgeFilteringMode.PCFPOISSON);

(I looked at the EdgeFilteringModes and didn’t see a value like “NONE” so I hope just removing the whole line “disables” it.)

Here’s what I get:

In my game I encountered several shadows artifacts, and tuning PolyOffset was simply not enough. Serrated patterns are caused by the angle between surface and light vector, in most cases you can remove them using edge filtering, sometimes PolyOffset needs to be adjusted.
The gap in lower right part of your tree may be caused by inaccurate PolyOffset value AND/OR by lack of precision - I don’t know what are the default settings for z-buffer and shadowmaps (I mean bits per pixel) but I think that you can try to increase it. Unfortunately I don’t know how to make it on unmodified JME, you need to look for that on your own.

So you suggest I:

  • tweak the PolyOffset
  • increase the z-buffer

Thank you!