Point light shadows.

Point light shadows.

Above: Light is bleeding through the mesh.

This is with a 128x128x6 shadow cube map for this point light, which requires a high bias even with 1 tap PCF. (1 tap PCF generally requires the least bias of all the available shadow methods in Babylon).

The bias moves the shadow away from the caster, and so in some cases the shadow cast is “missed” because it was moved too far from the casting surface. This can be fixed by using 256x256 shadow maps, but since Scarlet6 is in the browser, I will avoid using maps that large for now.

Above: Light is bleeding through the mesh. The shadow bias is obvious when the point light gets very close to the shadow caster.

Another way to fix the issues above is to render both the front and back faces of shadow casters (default is just front faces as you would normally render a mesh). This would probably be quick if I only do this for the tile near the light (the only place that needs it anyway). It’s on the TODO list, but I want to get to writing actual gameplay ASAP so I won’t implement this for now.

Shadows in Babylon seem to simply assume that the shadow extends an infinite distance, so I improved the depth accuracy by reducing the shadow generator’s depth range to a minimum by changing this code:

{
public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): PointLight {
    var activeCamera = this.getScene().activeCamera;
    Matrix.PerspectiveFovLHToRef(Math.PI / 2, 1.0, activeCamera.minZ, activeCamera.maxZ, matrix);
    return this;
}

To this code (notice we now use the light’s range as far Z instead of the active camera’s far Z):

{
public setShadowProjectionMatrix(matrix: Matrix, viewMatrix: Matrix, renderList: Array<AbstractMesh>): PointLight {
    Matrix.PerspectiveFovLHToRef(Math.PI / 2, 1.0, this.range/1000.0, this.range, matrix);
    return this;
}

That also reduces the near Z shadow camera clip plane, which removed some light bleeding due to casters getting clipped away when the point light is very near the object.

Above: Point light shadows.
Above: Point light shadows.

Bean

Bean
I'm Bean. From BeanstalkBlue.
https://beanstalk.blue

Robust character collision!

Player character now detects collision. Continue reading

Collision beginnings

Published on March 24, 2017

Collision beginnings

Published on March 24, 2017