This object is used by the renderers to create an array of shadow map textures for lights in the scene.
The ShadowMapping object will request the following shaders to the ShaderManager:
Shadow mapping is enabled by setting the shadowRendering option when the renderer is created:
renderer = Renderer.create(graphicsDevice,
mathDevice,
shaderManager,
effectManager,
{ shadowRendering: true });
Here Renderer can be either DeferredRendering or ForwardRendering.
To enable shadows for a light set the shadows argument when it is created:
var light = Light.create(
{
name : lightName,
color : color,
point : true,
shadows : true,
halfExtents: v3Build.call(mathDevice, 40, 40, 40),
origin: v3Build.call(mathDevice, 0, 10, 0),
material : lightMaterial
});
Only point and spot lights support shadows.
By default all materials cast shadows. If you want a material to ignore this you can set the noshadows flag:
var material = Material.create(graphicsDevice);
material.meta.noshadows = true;
Required scripts
The ShadowMapping object requires:
/*{{ javascript("jslib/shadowmapping.js") }}*/
/*{{ javascript("jslib/camera.js") }}*/
Summary
Creates and returns a ShadowMapping object.
Syntax
var shadowMapping = ShadowMapping.create(graphicsDevice, mathsDevice, shaderManager, effectsManager, sizeLow, sizeHigh);
Returns a ShadowMapping object.
Summary
Updates the shadow mapping shader.
Syntax
shadowMapping.updateShader();
Summary
The default update function to be registered on the effects by the renderer.
Syntax
effect = Effect.create("blinn");
effectManager.add(effect);
effectTypeData = { prepare : forwardPrepareFn,
shaderName : "shaders/forwardrendering.cgfx",
techniqueName : "blinn",
update : forwardUpdateFn,
shadowMappingShaderName : "shaders/shadowmapping.cgfx",
shadowMappingTechniqueName : "rigid",
shadowMappingUpdate : shadowMapping.update,
loadTechniques : loadTechniques };
effectTypeData.loadTechniques(shaderManager);
effect.add(rigid, effectTypeData);
Summary
The default skinned update function to be registered on the effects by the renderer.
Syntax
effect = Effect.create("blinn_skinned");
effectManager.add(effect);
effectTypeData = { prepare : forwardPrepareFn,
shaderName : "shaders/forwardrendering.cgfx",
techniqueName : "blinn_skinned",
update : forwardUpdateFn,
shadowMappingShaderName : "shaders/shadowmapping.cgfx",
shadowMappingTechniqueName : "skinned",
shadowMappingUpdate : shadowMapping.skinnedUpdate,
loadTechniques : loadTechniques };
effectTypeData.loadTechniques(shaderManager);
effect.add(rigid, effectTypeData);
Summary
Update all the buffers and textures used by the ShadowMapping object to use new texture sizes.
Syntax
shadowMapping.updateBuffers(sizeLow, sizeHigh);
Returns true if buffers where updated successfully, false otherwise. If sizeLow and sizeHigh are the same as the current low and high resolution values then no update is done and the function returns true. If sizeLow and sizeHigh are undefined then the buffers are recreated with their previous resolutions.
Summary
Destroy all the buffers and textures used by the ShadowMapping object.
Syntax
shadowMapping.destroyBuffers();
Summary
Draw the shadow map for a light instance.
Syntax
cameraMatrix = camera.matrix;
shadowMapping.drawShadowMap(cameraMatrix, minExtentsHigh, lightInstance);
Returns null. The function adds the following properties to the lightInstance object:
If the shadow map is not empty then shadows is set to true, false otherwise.
shadowMap ShadowMap object for lightInstance.
Note
Currently this function will continue to draw shadows for static nodes when they or their renderables are disabled.
Summary
Blur all of the shadow maps to give softer shadows.
Syntax
shadowMapping.blurShadowMaps();
Summary
Releases the ShadowMapping object and all the resources it allocated.
Syntax
shadowMapping.destroy();
Summary
The exponential shadow map’s texture.
Syntax
var shadowMapTexture = shadowMap.texture;
A Texture object. The shadow map texture is given in RGBA format.
Summary
The exponential shadow map’s render target.
Syntax
var shadowMapRenderTarget = shadowMap.renderTarget;
A RenderTarget object.
Summary
The light instance for the exponential shadow map.
Syntax
var shadowMapLightInstance = shadowMap.lightInstance;
A lightInstance object.