Tests with shadowGenerator usin PCSS filter

Hi,
I have been trying to create shadows and was successful with PCSS and while creating tests i fumbled again. :slight_smile:

expect(shadowGenerator.useContactHardeningShadow).toBe(SHADOW_GENERATOR_PROPERTIES.useContactHardeningShadow);
** expect(shadowGenerator.filter).toBe(SHADOW_GENERATOR_PROPERTIES.filter);**

the above 2 fail…

when i build and run the code everything seems fine, i can create some good shadows. and inspector shows fine… with all the values being set… but…test fails on these two properties.

filter and useContactHardeningShadow

-------------------------here is code--------------------

const DIRECTIONAL_LIGHT_PROPERTIES = {
name: “abc”,
direction: new Vector3(0.0, -3, -0.7),
position: new Vector3(0, 1.076, 0.434),
intensity: 2.66,
}

const SHADOW_GENERATOR_PROPERTIES = {
mapSize: 1024,
useContactHardeningShadow: true,
darkness: 0.34,
filter: 7,
shadowMaxZ: 1,
shadowMinZ: 0.7,
contactHardeningLightSizeUVRatio: 0.06,
}

class DDirectionalLight extends DirectionalLight{
constructor(params: DirectionalLightInterface) {
super(params.name, params.direction, params.scene);
this.position = params.position;
this.intensity = params.intensity;
}
}

const shadowCastLightData: DirectionalLightInterface = {
name: DIRECTIONAL_LIGHT_PROPERTIES.name,
direction: DIRECTIONAL_LIGHT_PROPERTIES.direction,
scene: PlayerManager.scene,
position: DIRECTIONAL_LIGHT_PROPERTIES.position,
intensity: DIRECTIONAL_LIGHT_PROPERTIES.intensity,
};

function createShadow(dlight: DirectionalLight):ShadowGenerator {
if(!dlight){
return undefined
}
const shadowGenerator = new ShadowGenerator(SHADOW_GENERATOR_PROPERTIES.mapSize, dlight);

shadowGenerator.setDarkness(SHADOW_GENERATOR_PROPERTIES.darkness);
shadowGenerator.filter = SHADOW_GENERATOR_PROPERTIES.filter;
shadowGenerator.useContactHardeningShadow = SHADOW_GENERATOR_PROPERTIES.useContactHardeningShadow;
shadowGenerator.contactHardeningLightSizeUVRatio = SHADOW_GENERATOR_PROPERTIES.contactHardeningLightSizeUVRatio;

dlight.shadowMinZ = SHADOW_GENERATOR_PROPERTIES.shadowMinZ;
dlight.shadowMaxZ = SHADOW_GENERATOR_PROPERTIES.shadowMaxZ;

return shadowGenerator;

}

--------------------tests-----------------------
const engine = new NullEngine();
const testScene = new Scene(engine); // scene us require because without scene, this test will fail
shadowCastLightData.scene = testScene;

describe(‘createShadow tests’, () => {
beforeEach(() => {
jest.spyOn(console, ‘error’).mockImplementation();
});

it(‘should return an object if parameters are met’, () => {
const shadowLightsInput = new DDirectionalLight(shadowCastLightData);
const shadowGenerator = createShadow(shadowLightsInput);
expect(shadowGenerator).toBeDefined();
expect(shadowGenerator.darkness).toBe(SHADOW_GENERATOR_PROPERTIES.darkness);
expect(shadowGenerator.contactHardeningLightSizeUVRatio).toBe(SHADOW_GENERATOR_PROPERTIES.contactHardeningLightSizeUVRatio);
expect(shadowLightsInput.shadowMinZ).toBe(SHADOW_GENERATOR_PROPERTIES.shadowMinZ);
expect(shadowLightsInput.shadowMaxZ).toBe(SHADOW_GENERATOR_PROPERTIES.shadowMaxZ);

expect(shadowGenerator.useContactHardeningShadow).toBe(SHADOW_GENERATOR_PROPERTIES.useContactHardeningShadow);
expect(shadowGenerator.filter).toBe(SHADOW_GENERATOR_PROPERTIES.filter);
});

it(‘should return undefined if parameters are undefined’, () => {
expect(createShadow(undefined)).toBeUndefined();
});
});

Have you tried to console.log the two values shadowGenerator.useContactHardeningShadow and SHADOW_GENERATOR_PROPERTIES.useContactHardeningShadow to see their values?

1 Like

It might be cause in null engine it simulates gl1 so PCSS would not be supported :slight_smile:

1 Like

Perfect @sebavan , that makes sense… Thank you very much and thank you Evgeni, really thank you very much,.