Weird white lines on voxel edges

Hello, I’m trying to create a simple voxel game. And when I started creating shadows I saw that they were awful:
Screenshot from 2021-08-04 19-56-52

How can I fix it?
Also, cubes are created out of quads and then combined to mesh with GeometryBatchFactory.makeBatches

here is the code:

private void setUpShadowCasting() {
        final int SHADOWMAP_SIZE = 512;
        DirectionalLightShadowRenderer dlsr = new DirectionalLightShadowRenderer(assetManager, SHADOWMAP_SIZE, 1);
        dlsr.setLight(sun);
        viewPort.addProcessor(dlsr);

        DirectionalLightShadowFilter dlsf = new DirectionalLightShadowFilter(assetManager, SHADOWMAP_SIZE, 1);
        dlsf.setLight(sun);
        dlsf.setEnabled(true);
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        fpp.addFilter(dlsf);
        viewPort.addProcessor(fpp);
    }

private void createSun() {
        sun = new DirectionalLight();
        sun.setColor(ColorRGBA.White);
        sun.setDirection(new Vector3f(-.5f, -.5f, -.5f).normalizeLocal());
        rootNode.addLight(sun);
    }

Note: changing SHADOWMAP_SIZE or nbSplits doesn’t fix that situation.

You are supposed to use either, not both.

Screenshot from 2021-08-05 13-10-07
The problem did not go. Leaving only dlsr/dlsf did not help.
Also, increasing nbSplits to 4 and SHADOWMAP_SIZE to 4096 leaves the same thing, but thinner.

  1. how small this voxels are?
    (imagine tiny tree leaf where you make camera see it huge on screen and you require shadow to be perfect)
    (also remember there is something like “float-precision”)

  2. how mesh look like? is this boxes or real voxel or even greedy meshing?

  1. They’re 1x1x1.
  2. The mesh is optimized with my algorithm. It has a list of cubes. And then It adds quad geometry to the quadList if there is no cube in front. And then GeometryBatchFactory.makeBatches combines quadList to one Spatial that will be added to a scene.
    For understanding it looks like:

That’s sort of the nature of the shadows.

Without seeing your whole scene I would have to guess that your mesh is very big and or not broken up into chunks… and the shadows do not have a resolution to fit what’s in the camera view. There is a way to limit the shadow processing to only a distance from the camera which can help.

2 Likes

There is a way to limit the shadow processing to only a distance

How can I achieve that?

https://javadoc.jmonkeyengine.org/v3.4.0-stable/com/jme3/shadow/AbstractShadowFilter.html#setShadowZExtend-float-

Hello there, I’ve tried to resize chunk to 1 block, which means that on it will be only 6 faces 1x1. As @pspeed said before, that visual artefact exists because the shadow map is too small to cover the whole chunk with a lot of faces. But now I see the same:


The SHADOWMAP_SIZE is 512.
I think that to make it better we need to make faces that are turned away from the sun should be darkened, as it was without shadows.

P.S. also I have upgraded world generation

https://javadoc.jmonkeyengine.org/v3.4.0-stable/com/jme3/shadow/AbstractShadowFilter.html#setRenderBackFacesShadows-java.lang.Boolean-

Thanks, that makes the situation better, but there is only one thing left:


that white lines. They’re looking like cellshading.