Hello!
I’ve been experimenting with DirectionalLightShadowRenderer and DirectionalLightShadowFilter, trying to weigh up which is the best one to use.
DirectionalLightShadowFilter seems to give me more fps. However, I notice that with DirectionalLightShadowFilter, the edges of geometries in the distance seem to become pixelated, whereas with DirectionalLightShadowRenderer, the edges of geometries are always smooth. This effect does seem to only be noticeable on geometries in the distance. Up close, everything looks smooth whichever class I use.
I haven’t been able to find this issue mentioned anywhere, so, I thought I’d post a topic.
I’ve written two simple programs that demonstrate this effect, and have attached the screenshots for comparison.
Using DirectionalLightShadowRenderer, the edges are nice and smooth:
Using DirectionalLightShadowFilter, the edges are pixelated:
The settings I used to produce these screenshots were 640 x 480, Vzync enabled, 24 bpp color depth, and 16x anti-aliasing. However, whatever settings I use, I get the same pixelating effect on geometries in the distance.
The difference is subtle in those screenshots, but, in the game I’m working on, and when adding shadows to that town.zip scene, it’s quite noticeable and looks quite ugly.
The code that uses DirectionalLightShadowRenderer is:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.DirectionalLightShadowRenderer;
public class DirectionalLightShadowRendererTest extends SimpleApplication {
public static void main(String[] args) {
DirectionalLightShadowRendererTest app = new DirectionalLightShadowRendererTest();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
geom.rotate(0, FastMath.QUARTER_PI, 0);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Diffuse", ColorRGBA.White);
geom.setMaterial(mat);
rootNode.attachChild(geom);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(0, 0, -1));
rootNode.addLight(sun);
DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, 2048, 4);
dlsr.setLight(sun);
viewPort.addProcessor(dlsr);
}
}
The code that uses DirectionalLightShadowFilter is:
package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Vector3f;
import com.jme3.post.FilterPostProcessor;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.shadow.DirectionalLightShadowFilter;
public class DirectionalLightShadowFilterTest extends SimpleApplication {
public static void main(String[] args) {
DirectionalLightShadowFilterTest app = new DirectionalLightShadowFilterTest();
app.start();
}
@Override
public void simpleInitApp() {
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
geom.rotate(0, FastMath.QUARTER_PI, 0);
Material mat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
mat.setBoolean("UseMaterialColors", true);
mat.setColor("Diffuse", ColorRGBA.White);
geom.setMaterial(mat);
rootNode.attachChild(geom);
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(0, 0, -1));
rootNode.addLight(sun);
DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(assetManager, 2048, 4);
dlsf.setLight(sun);
dlsf.setEnabled(true);
FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
fpp.addFilter(dlsf);
viewPort.addProcessor(fpp);
}
}
Has anyone else come across this issue, or is it just me? If it’s a known issue, is there something I can do about it, or is it just a feature of DirectionalLightShadowFilter?
Of course, I can just use DirectionalLightShadowRenderer, but, DirectionalLightShadowFilter seems to give me a higher fps, so, I’d use DirectionalLightShadowFilter if I could find a way to sort out this pixelating effect.
James