Engine API Reference - v2.24.0-beta.13
    Preparing search index...

    Class DofEffect

    The Depth of Field (DOF) effect, a technique used to simulate the optical effect where objects at certain distances appear sharp while others are blurred, enhancing the perception of focus and depth in the rendered scene.

    The blur is generated by passes the effect owns, from the scene depth and the scene color, and mixed into the scene in linear HDR space, before tone mapping.

    Every CameraFrame constructs and registers one, available as CameraFrame#dof.

    Hierarchy (View Summary)

    Index
    blurRadius: number = 3

    The radius of the blur effect, typically 2-10 range. Defaults to 3.

    blurRingPoints: number = 5

    The number of points in each ring of the blur effect, typically 3-8 range. Defaults to 5.

    blurRings: number = 4

    The number of rings in the blur effect, typically 3-8 range. Defaults to 4.

    cameraFrame: CameraFrame | null = null

    The camera frame the effect is registered with, or null.

    The graphics device.

    enabled: boolean = false

    Whether DoF is enabled. Defaults to false.

    focusDistance: number = 100

    The distance at which the focus is set. Defaults to 100.

    focusRange: number = 10

    The range around the focus distance where the focus is sharp. Defaults to 10.

    highQuality: boolean = true

    Whether the high quality implementation is used, which blurs the full resolution scene instead of a half resolution copy of it. This will have a higher performance cost, but will produce better quality results. Defaults to true.

    nearBlur: boolean = false

    Whether the near blur is enabled. Defaults to false.

    • get cameraExposureScale(): number

      Gets the scale the effect applies to the exposure of the camera this frame, multiplying the exposure of the scene, or of the physical camera with physical units - for effects adapting the exposure to what the camera sees. Read every frame while the effect takes part, after CameraFrameEffect#frameUpdate; the camera frame applies the product of the scales of the effects taking part, and the camera renders with its own exposure again once none does. Defaults to 1.

      // an effect brightening the image by one stop
      get cameraExposureScale() {
      return 2;
      }

      Returns number

    • get chunkName(): string

      Gets the name the compose chunk can be overridden under in ShaderChunks, the same way as the built-in chunks. Derived from the id as compose<Id>PS unless given.

      Returns string

    • get defineName(): string

      Gets the define set on the compose shader while the effect is active: the id in upper snake case, colorEnhance giving COLOR_ENHANCE.

      Returns string

    • get entryPoint(): string

      Gets the name of the function the composition calls at the effect's slot. Derived from the id as apply<Id> unless given. The signature depends on the slot: colour slots take (vec3 color, vec2 uv) and return the colour, COMPOSESLOT_SCENE takes and returns a vec4.

      Returns string

    • get requires(): string[]

      Gets the frame resources the effect needs, the FRAMERESOURCE_* constants - for its passes, or for its compose chunk, such as the scene depth. The camera frame provides them while the effect is active. Requirements which depend on the device are computed when constructing the effect; override this as a getter when they depend on a parameter, and the camera frame provides what it returns from the next CameraFrame#update.

      Returns string[]

    • get slot(): string | null

      Gets the compose slot the entry function is called at, or null for an effect that does not take part in the composition.

      Returns string | null

    • Destroys the effect, removing it from its camera frame if it is still registered and releasing everything it owns, the passes it created included. Subclasses which create resources in their constructor release them in an override, calling super.destroy(). The removal takes effect for the frames rendered after the next CameraFrame#update, which is due before the next frame renders.

      Returns void

    • Sets a define on the compose shader. The define persists until changed, so fixed defines can be set once in the constructor and those depending on the parameters from CameraFrameEffect#update. A value of false, null or undefined removes it. Changing a define rebuilds the compose shader.

      Parameters

      • name: string

        The define name.

      • value: any

        The value.

      Returns void