Provides a forward shading solution.
At draw time all the visible renderables are classified and sorted to maximize rendering performance, minimizing shader technique changes whilst taking advantage of hardware Z-buffers.
Renderable objects are classified into 3 main categories:
The application can draw any additional renderables by a set of callback functions given to the ForwardRendering object.
The ForwardRendering object will request the following shaders to the ShaderManager:
Features supported:
Features not supported:
For point and spot lights the lighting attenuation is calculated using two textures, the falloff texture provides attenuation depending on the Z coordinate on light space and the projection texture provides attenuation and color based on the X and Y coordinates on light space.
These are the effects supported by this renderer:
constant
lambert
blinn
phong
normalmap
normalmap_specularmap
normalmap_alphatest
normalmap_specularmap_alphatest
normalmap_glowmap
normalmap_specularmap_glowmap
rxgb_normalmap
rxgb_normalmap_specularmap
rxgb_normalmap_glowmap
rxgb_normalmap_specularmap_glowmap
glowmap
lightmap
skybox
add
add_particle
blend
blend_particle
translucent
translucent_particle
filter
invfilter
invfilter_particle
glass
glass_env
modulate2
env
flare
The following meta material properties are supported for the scene renderables:
The renderable will not cast shadows.
Non-opaque material that will blend with the background. The renderable will be rendered back to front and will be ignored during lighting calculations. Materials using effects with alpha test enabled but without blending enabled do not need this flag.
Non-opaque material that will blend with the surface immediately below. The renderable will be ignored during lighting calculations. Materials using effects with alpha test enabled but without blending enabled do not need this flag.
Scale for the flare dimensions in world units. Only required if effect is flare.
The renderable will be rendered last if opaque or first if transparent and will be ignored during lighting calculations.
The following TechniqueParameters properties are supported for the scene renderables:
Array with 4 numbers providing the material color
Array of 6 numbers forming a 3x2 transformation matrix applied to the uv coordinates
Texture that will provide the diffuse color
Texture that will provide the specular color
Texture that will provide the per pixel normal
Texture that will provide the emissive color
Cubemap texture that will provide the skybox color
Texture that will provide the alpha component
The following TechniqueParameters properties are supported for the scene lights:
Texture that will modulate the light color on the XY plane
Texture that will modulate the light color on the Z plane
The renderables are rendered in the following passes:
Required scripts
The ForwardRendering object requires:
/*{{ javascript("jslib/renderingcommon.js") }}*/
/*{{ javascript("jslib/forwardrendering.js") }}*/
Summary
Syntax
var settings = {
shadowRendering: true,
shadowSizeLow: 512,
shadowSizeHigh: 1024
};
var renderer = ForwardRendering.create(graphicsDevice, mathDevice, shaderManager, effectManager, settings);
The shadowRendering option enables shadow mapping. The shadowSizeLow and shadowSizeHigh set the sizes for the ShadowMapping object shadow textures.
Summary
This method does nothing, it is provided for interface compatibility with other renderers.
Syntax
renderer.updateBuffers(graphicsDevice, width, height);
Summary
Updates the shaders used for forward rendering.
Syntax
renderer.updateShader(shaderManager);
If the required shaders were not ready when the renderer was created this method can be used to update them.
Summary
Updates light and material information to prepare for the forward shading.
Syntax
renderer.update(graphicsDevice, camera, scene, currentTime);
Call this function after the scene and the camera have been updated for the current frame.
Summary
Renders the scene.
Syntax
renderer.draw(graphicsDevice,
clearColor,
drawDecalsFn,
drawTransparentFn,
drawDebugFn,
postFXsetupFn);
The callback executed to draw extra visible decals, it can be set to null. For example:
function drawDecalsFn()
{
fxm.drawDecals(graphicsDevice);
}
The callback executed to draw extra visible transparent objects, it can be set to null. For example:
function drawTransparentFn()
{
fxm.drawTransparent(graphicsDevice);
}
The callback executed to allow the application draw any debugging information required, it can be set to null. For example:
function drawDebugFn()
{
scene.drawNodesExtents(graphicsDevice, camera);
}
The callback executed to set the GraphicsDevice to the state required for the transfer of the shaded scene to the backbuffer, can also be used to apply fullscreen effects. It is only required to set the active technique and set the required TechniqueParameters parameter, the renderer is responsible for drawing the fullscreen quad. For example:
function copyPostFXSetupFn(graphicsDevice, finalTexture)
{
graphicsDevice.setTechnique(copyTechnique);
copyTechniqueParameters.colorTexture = finalTexture;
graphicsDevice.setTechniqueParameters(copyTechniqueParameters);
};
You can find some examples in the PostEffects object.
Summary
Sets the lighting scale factor applied to the lighting calculations. By default this values is set to 2.0.
Syntax
var scale = 1.0;
renderer.setLightingScale(scale);
Get the default size of the buffer used by skinning. This will be undefined until the shaders are loaded.
See also GPUSkinController.
For example:
GPUSkinController.setDefaultBufferSize(renderer.getDefaultSkinBufferSize());
Summary
Releases the ForwardRendering object and all the resources it allocated.
Syntax
renderer.destroy();
Summary
The version number of the ForwardRendering implementation.
Syntax
var versionNumber = ForwardRendering.version;
Summary
A dictionary of passes to passIndex used by DrawParameters to specify the pass they are rendered in.
Valid values are:
Syntax
drawParameters.userData.passIndex = forwardRender.passIndex.transparent;
Summary
The ShadowMapping object used by the renderer to render shadows.
Syntax
var shadowMaps = ForwardRendering.shadowMaps;