Class ForwardRenderPipeline

A forward rendering pipeline that provides advanced rendering features including shadows, bloom, tone mapping, and IBL.

ForwardRenderPipeline is a comprehensive rendering solution that handles multi-pass rendering setups with features like MSAA, shadow mapping, bloom effects, and tone mapping. It supports both regular rendering and WebXR multi-view rendering for VR applications.

The pipeline automatically manages frame buffers, render targets, and expression chains to provide a complete rendering solution similar to Unity's Universal Render Pipeline (URP).

const expressions = [...];
const matrix = [...];

// Create and setup the render pipeline
const forwardRenderPipeline = new Rn.ForwardRenderPipeline();
await forwardRenderPipeline.setup(1024, 1024, {isShadow: true, isBloom: true});

// Configure expressions and IBL
forwardRenderPipeline.setExpressions(expressions);

const diffuseCubeTexture = new Rn.CubeTexture();
diffuseCubeTexture.baseUriToLoad = './../../../assets/ibl/papermill/diffuse/diffuse';
diffuseCubeTexture.isNamePosNeg = true;
diffuseCubeTexture.hdriFormat = Rn.HdriFormat.RGBE_PNG;
diffuseCubeTexture.mipmapLevelNumber = 1;

const specularCubeTexture = new Rn.CubeTexture();
specularCubeTexture.baseUriToLoad = './../../../assets/ibl/papermill/specular/specular';
specularCubeTexture.isNamePosNeg = true;
specularCubeTexture.hdriFormat = Rn.HdriFormat.RGBE_PNG;
specularCubeTexture.mipmapLevelNumber = 10;

forwardRenderPipeline.setIBLTextures(diffuseCubeTexture, specularCubeTexture);

// Start the render loop
forwardRenderPipeline.startRenderLoop((frame) => {
Rn.System.process(frame);
});

Hierarchy (view full)

Constructors

Properties

_tags: RnTags = {}

Collection of tags associated with this object

InvalidObjectUID: -1 = -1

Invalid object UID constant

currentMaxObjectCount: number = 0

Current maximum object count for UID generation

Accessors

  • get objectUID(): number
  • Gets the unique object identifier

    Returns number

    The object's UID

  • get uniqueName(): string
  • Gets the unique name of this object

    Returns string

    The unique name string

Methods

  • Executes a single frame render using the draw function provided to startRenderLoop.

    Returns void

    This method allows manual control over frame rendering instead of using the automatic render loop. It calls the draw function that was provided to startRenderLoop.

    // Manual frame rendering
    pipeline.draw();
  • Gets the initial expression used for buffer clearing and setup.

    Returns undefined | Expression

    The initial expression, or undefined if not available

    The initial expression is automatically created during setup and handles clearing of color and depth buffers before main rendering begins.

  • Retrieves a complete tag object (name and value) for the specified tag name

    Parameters

    • tagName: string

      The name of the tag to retrieve

    Returns Tag

    A Tag object containing the name and value

  • Retrieves the value associated with a specific tag name

    Parameters

    • tagName: string

      The name of the tag whose value to retrieve

    Returns any

    The tag value, or undefined if the tag doesn't exist

  • Gets the tone mapping expression used for HDR to LDR conversion.

    Returns undefined | Expression

    The tone mapping expression, or undefined if not available

    The tone mapping expression is created during setup when not in simple mode. It handles the conversion from high dynamic range rendering to low dynamic range output suitable for display devices.

  • Checks whether this object has a tag with the specified name

    Parameters

    • tagName: string

      The name of the tag to check for

    Returns boolean

    True if the tag exists (value is not null/undefined), false otherwise

  • Checks if this object has a tag with the specified name and value

    Parameters

    • tagName: string

      The tag name to match

    • tagValue: string

      The tag value to match

    Returns boolean

    True if the object has a matching tag, false otherwise

  • Checks if this object has all the specified tags with exactly matching values

    Parameters

    • tags: RnTags

      Object containing tag names as keys and expected values

    Returns boolean

    True if all specified tags exist with matching values, false otherwise

  • Checks if the object's combined tag string contains all the provided search strings. This allows for flexible searching within tag names and values.

    Parameters

    • stringArray: string[]

      Array of strings that must all be present in the combined tag string

    Returns boolean

    True if all strings are found in the combined tag string, false otherwise

  • Resizes the rendering pipeline to match new canvas dimensions.

    Parameters

    • width: number

      New width of the rendering canvas

    • height: number

      New height of the rendering canvas

    Returns Err<unknown, undefined> | Ok<unknown, unknown>

    A Result indicating success or failure of the resize operation

    This method handles canvas resizing by destroying existing resources and recreating them with the new dimensions. It automatically handles WebXR canvas sizing when in VR mode.

    The method preserves all current pipeline settings (shadow, bloom, etc.) during resize.

    window.addEventListener('resize', () => {
    const result = pipeline.resize(window.innerWidth, window.innerHeight);
    if (result.isErr()) {
    console.error('Resize failed:', result.getErr());
    }
    });
  • Sets the contribution factor for diffuse IBL lighting.

    Parameters

    • value: number

      Contribution factor (0.0 to 1.0 or higher for over-exposure effects)

    Returns void

    This method controls how much the diffuse IBL texture contributes to the final lighting. A value of 0.0 disables diffuse IBL, while 1.0 provides full contribution. Values greater than 1.0 can be used for artistic over-exposure effects.

    // Reduce ambient lighting
    pipeline.setDiffuseIBLContribution(0.5);

    // Disable diffuse IBL
    pipeline.setDiffuseIBLContribution(0.0);

    // Over-expose for artistic effect
    pipeline.setDiffuseIBLContribution(2.0);
  • Sets the expressions to be rendered by the pipeline.

    Parameters

    • expressions: Expression[]

      Array of expressions containing render passes and entities to render

    • options: {
          isTransmission: boolean;
      } = ...

      Configuration options for expression setup

      • isTransmission: boolean

        Whether to enable transmission rendering for transparent objects (default: true)

    Returns void

    This method configures the expressions for both opaque and transparent rendering. When transmission is enabled, transparent objects are rendered in a separate pass to support advanced material effects like glass and water.

    The method automatically clones expressions for transparent rendering and configures shadow expressions if shadow mapping is enabled.

    const expressions = [sceneExpression, uiExpression];
    pipeline.setExpressions(expressions, { isTransmission: true });
  • Sets the rotation of the IBL environment in radians.

    Parameters

    • radian: number

      Rotation angle in radians

    Returns void

    This method allows rotating the IBL environment to match the desired lighting direction. This is useful when the IBL doesn't align with the scene's lighting requirements or for artistic control over the environment lighting.

    // Rotate IBL by 90 degrees
    pipeline.setIBLRotation(Math.PI / 2);

    // Rotate IBL by 180 degrees
    pipeline.setIBLRotation(Math.PI);

    // Animate IBL rotation
    let rotation = 0;
    setInterval(() => {
    rotation += 0.01;
    pipeline.setIBLRotation(rotation);
    }, 16);
  • Sets the IBL (Image-Based Lighting) cube textures for realistic lighting.

    Parameters

    • diffuse: CubeTexture

      Diffuse IBL cube texture for ambient lighting

    • specular: CubeTexture

      Specular IBL cube texture for reflections

    • Optionalsheen: CubeTexture

      Optional sheen IBL cube texture for fabric-like materials

    Returns void

    IBL textures provide realistic lighting by using pre-computed environment maps. The diffuse texture provides ambient lighting, while the specular texture provides reflections and specular highlights.

    The sheen texture is optional and used for materials with fabric-like properties.

    const diffuseCube = new Rn.CubeTexture();
    diffuseCube.baseUriToLoad = './assets/ibl/diffuse/diffuse';
    diffuseCube.hdriFormat = Rn.HdriFormat.RGBE_PNG;

    const specularCube = new Rn.CubeTexture();
    specularCube.baseUriToLoad = './assets/ibl/specular/specular';
    specularCube.hdriFormat = Rn.HdriFormat.RGBE_PNG;
    specularCube.mipmapLevelNumber = 10;

    pipeline.setIBLTextures(diffuseCube, specularCube);
  • Sets the contribution factor for specular IBL reflections.

    Parameters

    • value: number

      Contribution factor (0.0 to 1.0 or higher for over-exposure effects)

    Returns void

    This method controls how much the specular IBL texture contributes to reflections and specular highlights. A value of 0.0 disables specular IBL, while 1.0 provides full contribution. Values greater than 1.0 can create over-exposed reflections.

    // Subtle reflections
    pipeline.setSpecularIBLContribution(0.3);

    // No reflections
    pipeline.setSpecularIBLContribution(0.0);

    // Enhanced reflections
    pipeline.setSpecularIBLContribution(1.5);
  • Sets the tone mapping algorithm used for HDR to LDR conversion.

    Parameters

    • type: EnumIO

      The tone mapping algorithm to use

    Returns void

    Tone mapping is essential for converting high dynamic range rendering results to low dynamic range output that can be displayed on standard monitors.

    Available tone mapping algorithms:

    • KhronosPbrNeutral: Khronos PBR neutral tone mapping
    • Reinhard: Classic Reinhard tone mapping
    • GT_ToneMap: GT tone mapping (default)
    • ACES_Narkowicz: ACES tone mapping by Narkowicz
    • ACES_Hill: ACES tone mapping by Hill
    • ACES_Hill_Exposure_Boost: ACES Hill with exposure boost
    // Use ACES tone mapping for cinematic look
    pipeline.setToneMappingType(Rn.ToneMappingType.ACES_Hill);

    // Use Reinhard for classic look
    pipeline.setToneMappingType(Rn.ToneMappingType.Reinhard);

    // Use Khronos PBR neutral for accurate colors
    pipeline.setToneMappingType(Rn.ToneMappingType.KhronosPbrNeutral);
  • Initializes the rendering pipeline with the specified configuration.

    Parameters

    • canvasWidth: number

      The width of the rendering canvas in pixels

    • canvasHeight: number

      The height of the rendering canvas in pixels

    • options: {
          isBloom: undefined | boolean;
          isShadow: undefined | boolean;
          isSimple: undefined | boolean;
          shadowMapSize: undefined | number;
      } = {}

      Configuration options for the pipeline

      • isBloom: undefined | boolean

        Whether to enable bloom post-processing effect (default: false)

      • isShadow: undefined | boolean

        Whether to enable shadow mapping (default: false)

      • isSimple: undefined | boolean

        Whether to use simplified rendering without post-processing (default: false)

      • shadowMapSize: undefined | number

        Size of the shadow map texture in pixels (default: 1024)

    Returns Promise<Err<unknown, undefined> | Ok<unknown, unknown>>

    A Result indicating success or failure of the setup operation

    This method must be called before using any other pipeline methods. It creates all necessary frame buffers, render targets, and expressions based on the provided configuration.

    The method automatically detects WebXR capabilities and configures multi-view rendering when appropriate for VR applications.

    const result = await pipeline.setup(1920, 1080, {
    isShadow: true,
    isBloom: true,
    shadowMapSize: 2048
    });

    if (result.isErr()) {
    console.error('Pipeline setup failed:', result.getErr());
    }
  • Starts the main rendering loop with the provided draw function.

    Parameters

    • func: ((frame: Frame) => void)

      Function to be called each frame for rendering operations

        • (frame): void
        • Parameters

          Returns void

    Returns Err<unknown, undefined> | Ok<unknown, unknown>

    A Result indicating success or failure of starting the render loop

    This method begins the continuous rendering loop using the system's render loop mechanism. The provided function will be called every frame with the current frame object.

    The method automatically handles shadow system updates, expression management, and frame processing.

    const result = pipeline.startRenderLoop((frame) => {
    // Update scene
    Rn.System.process(frame);

    // Custom per-frame logic
    updateAnimations();
    handleInput();
    });

    if (result.isErr()) {
    console.error('Failed to start render loop:', result.getErr());
    }
  • Attempts to set a tag on this object. If the tag already exists, it will be replaced.

    Parameters

    • tag: Tag

      The tag object containing the name and value to set

    Returns boolean

    True if the tag was successfully set, false if the tag name contains invalid characters

  • Attempts to set a unique name for this object

    Parameters

    • name: string

      The desired unique name

    • toAddNameIfConflict: boolean

      If true, appends UID to make name unique when conflicts occur; if false, fails on conflict

    Returns boolean

    True if the name was successfully set, false if there was a conflict and toAddNameIfConflict was false

  • Validates that a tag string contains only allowed characters (alphanumeric and underscore)

    Parameters

    • val: string

      The string to validate

    Returns boolean

    True if the string contains only valid characters, false if it contains invalid characters

  • Retrieves an RnObject instance by its unique identifier

    Parameters

    • objectUid: number

      The unique identifier of the object to retrieve

    Returns undefined | RnObject

    The RnObject instance or undefined if not found or garbage collected

  • Searches for the first object that has a specific tag with the given value

    Parameters

    • tag: string

      The tag name to search for

    • value: string

      The tag value to match

    Returns undefined | WeakRef<RnObject>

    WeakRef to the first matching object, or undefined if not found