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

    Class SmaaEffect

    The SMAA effect - Subpixel Morphological Anti-Aliasing (SMAA 1x), a technique smoothing the jagged edges of the rendered geometry. It finds the edges in the image, recognizes the shape of each aliased edge, and blends the pixels along it with their neighbours by the area the edge before aliasing would cover. Unlike temporal anti-aliasing it works within a single frame: it does not jitter the camera, needs no history and does not ghost, at the cost of not resolving detail finer than a pixel.

    The effect resolves the scene before the other effects read it, so that the depth of field, the bloom and the composition all work with the anti-aliased scene. It is not registered by default

    const smaa = new SmaaEffect(app.graphicsDevice);
    cameraFrame.addEffect(smaa);
    cameraFrame.update();

    The parameters default to the HIGH quality preset of the reference implementation. The presets, as threshold / maxSearchSteps / maxSearchStepsDiag / cornerRounding, are LOW: 0.15 / 4 / 0 / 100, MEDIUM: 0.1 / 8 / 0 / 100, HIGH: 0.1 / 16 / 8 / 25 and ULTRA: 0.05 / 32 / 16 / 25.

    It can be combined with multisampling, see rendering.samples of the camera frame, which smooths the edges further at a higher cost. Combined with TaaEffect, it resolves the scene in the order the effects are registered - after the built-in temporal anti-aliasing unless inserted before it with CameraFrame#insertEffectBefore.

    Based on the reference implementation of SMAA by Jorge Jimenez, Jose I. Echevarria, Belen Masia, Fernando Navarro and Diego Gutierrez, distributed under the MIT license.

    Hierarchy (View Summary)

    Index
    cameraFrame: CameraFrame | null = null

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

    cornerRounding: number = 25

    How much the sharp corners of the geometry are rounded, 0-100 range. Zero keeps them the sharpest, 100 smooths them like the rest of the edges. Defaults to 25.

    The graphics device.

    enabled: boolean = true

    Whether the effect is enabled. An effect can additionally disable itself from its own parameters, see CameraFrameEffect#active.

    maxSearchSteps: number = 16

    The maximum number of steps searching for the end of a horizontal or vertical edge, each step covering two pixels, 1-112 range. The ends of longer edges are not found, which smooths them less accurately. Defaults to 16.

    maxSearchStepsDiag: number = 8

    The maximum number of steps searching for the end of a diagonal edge, 0-20 range. Zero disables the detection of diagonal edges, which are then smoothed as horizontal and vertical ones. Defaults to 8.

    threshold: number = 0.1

    The brightness difference between neighbouring pixels above which they are separated by an edge, 0-0.5 range. Lower values smooth more edges, at a higher cost, and can smooth texture detail along with the geometry. Defaults to 0.1.

    • 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

    • Called every frame while the effect takes part in the frame, while the frame is being prepared and before any pass renders, with the values of that frame. Most effects do not need it: their configuration belongs in CameraFrameEffect#update, which runs only when the camera frame is updated. Values derived from the resolution, which can change without an update, are computed here from the sizes in the frame, or in the shader from sceneTextureSize. Anything which changes over time advances here by the time of the frame, its dt.

      Parameters

      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