Hi all,
I’m getting very bad shadow artifacts when using a directional light, as you can see in this screenshot.
So I have a sphere with a quad intersecting it. The quad has an alpha texture applied to it and is rendered in the transparent queuebucket. I’ve tried everything I could think of; changing blendmodes, edge filtering techniques, lambda values, etc… I even tried a custom obj for the quad with more triangles, but nothing seems to have an effect.
Here’s the relevant code:
For the rings (quad):
Quad quad = new Quad((float)planet.getRadius() * scale, (float)planet.getRadius() * scale);
spatial = new Geometry(planet.getName() + "Rings", quad);
spatial.setLocalTranslation(-(float)planet.getRadius() * scale/2f, -(float)planet.getRadius() * scale/2f, 0);
spatial.setShadowMode(ShadowMode.CastAndReceive);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors",true);
mat.setColor("Ambient", ColorRGBA.White);
mat.setColor("Diffuse", ColorRGBA.White);
mat.setTexture("DiffuseMap", assetManager.loadTexture("assets/Textures/" + planet.getName() + "RingsColor.png"));
mat.setTexture("AlphaMap", assetManager.loadTexture("assets/Textures/" + planet.getName() + "RingsAlpha.png"));
mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.Off);
mat.getAdditionalRenderState().setBlendMode(BlendMode.PremultAlpha);
spatial.setMaterial(mat);
spatial.setQueueBucket(Bucket.Transparent);
planetNode.attachChild(spatial);
For the shadow and light:
sunlight = new DirectionalLight();
sunlight.setColor(ColorRGBA.White.mult(0.85f));
Vector3d v = spaceship.getPos().subtract(planetMap.get("Sun").getPos()).norm();
sunlight.setDirection(v.toFloat());
rootNode.addLight(sunlight);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
final int SHADOWMAP_SIZE=2048;
DirectionalLightShadowFilter sunshadow = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 4);
sunshadow.setLight(sunlight);
sunshadow.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
fpp.addFilter(sunshadow);
and finally for the planet:
Geometry geo = planetGeo.clone();
geo.setName(planet.getName());
geo.setLocalTranslation(0, 0, 0);
geo.scale((float)planet.getRadius());
geo.setMaterial(planet.getMaterial());
geo.setShadowMode(ShadowMode.Cast);
I’d love to hear any ideas or solutions! The only thing that helped a tiny little bit was reducing the shadow map resolution to 512, but that didn’t exactly improve the quality and didn’t do anything to make the shadows soft…