I’m wondering what causes the black bars on some of the vertical surfaces in my game when they are lit by directional light from above plus ambient light. I’m also wondering if there’s a fix for this problem, short of tweaking the light direction.
Here’s a test app which demonstrates the problem I’m talking about:
[java]
package shadows;
import com.jme3.app.SimpleApplication;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import com.jme3.renderer.queue.RenderQueue;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.DirectionalLightShadowRenderer;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.texture.Texture;
/**
-
A simple JME3 app to demonstrate shadow rendering issues.
*/
public class Main
extends SimpleApplication {public static void main(String[] args) {
Main app = new Main();
app.setShowSettings(false);
app.start();
}@Override
public void simpleInitApp() {
/*
* background
/
viewPort.setBackgroundColor(ColorRGBA.Gray);
/
* camera
/
cam.setLocation(new Vector3f(4f, 2f, 0f));
Quaternion startRotation = new Quaternion(0.2f, -0.6f, 0.2f, 0.7f);
cam.setRotation(startRotation);
flyCam.setMoveSpeed(10f);
/
* lighting
*/
DirectionalLight mainLight = new DirectionalLight();
mainLight.setColor(ColorRGBA.White);
mainLight.setDirection(Vector3f.UNIT_Y.negate());
rootNode.addLight(mainLight);AmbientLight ambientLight = new AmbientLight(); ambientLight.setColor(ColorRGBA.White.mult(4f)); rootNode.addLight(ambientLight); /* * cubic box with logo */ Material logoMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"); Texture logo = assetManager.loadTexture("Textures/Terrain/splat/road.jpg"); logoMaterial.setTexture("DiffuseMap", logo); Box boxMesh = new Box(1f, 1f, 1f); Geometry logoBox = new Geometry("box", boxMesh); logoBox.rotate(0f, FastMath.PI / 4, 0f); logoBox.setLocalTranslation(Vector3f.ZERO); logoBox.setMaterial(logoMaterial); logoBox.setShadowMode(RenderQueue.ShadowMode.CastAndReceive); rootNode.attachChild(logoBox); /* * shadow renderer */ DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, 512, 3); dlsr.setEdgeFilteringMode(EdgeFilteringMode.Nearest); dlsr.setLight(mainLight); dlsr.setShadowIntensity(0.8f); viewPort.addProcessor(dlsr);
}
}
[/java]
When I run this, the top face of the cube (which is horizontal) shows the texture clearly, but the sides (which are vertical but not axis-aligned) shows narrow vertical black bars superimposed on the texture.