Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ReadbackPass

This stage provides means to sample G-Buffers, in order to give access to world space coordinates, depth values and IDs. World space coordinates are calculated by sampling the depth value and unprojecting the normalized device coordinates. Depth and ID values are read from the GPU by rendering the requested pixel to a 1x1 texture and reading back the value from this texture. Note that depth and ID values are cached as long as no redraw (frame) was invoked.

Hierarchy

Index

Constructors

constructor

Properties

Protected _buffer

_buffer: Uint8Array = new Uint8Array(4)

Buffer to read into.

Protected _cache

_cache: boolean = false
see

cache

Protected _cachedDepths

_cachedDepths: Map<number, undefined | number> = new Map<GLsizei, GLfloat | undefined>()

Cache providing previously read depth values for a given position hash.

Protected _cachedIDs

_cachedIDs: Map<number, undefined | number> = new Map<GLsizei, GLsizei | undefined>()

Cache providing previously read id values for a given position hash.

Protected _context

_context: Context

Read-only access to the objects context, used to get context information and WebGL API access.

Protected _depthAttachment

_depthAttachment: GLenum = 0

Protected _depthFBO

_depthFBO: Framebuffer
see

depthFBO

Protected _framebuffer

_framebuffer: Framebuffer

Protected _idAttachment

_idAttachment: GLenum

Protected _idFBO

_idFBO: Framebuffer
see

idFBO

Protected _ndcTriangle

_ndcTriangle: NdcFillingTriangle

Geometry used to draw on. This is not provided by default to allow for geometry sharing. If no triangle is given, the ndc triangle will be created and managed internally.

Protected _ndcTriangleShared

_ndcTriangleShared: boolean = false

Tracks ownership of the ndc-filling triangle.

Protected _program

_program: Program

Protected _referenceSize

_referenceSize: GLsizei2 | undefined

Coordinate reference size @see coordinateReferenceSize.

Protected _texture

_texture: Texture2D

Properties required for 24bit depth readback workaround. If a valid depth format is available as renderable texture format, a single fragment is rasterized in order to encode the depth of at a specific location into uint8x3 format, rendered into a RGBA texture for readback. This workaround is currently necessary since reading back depth buffer data is not supported. All following protected properties are undefined when this workaround is not required (i.e., in IE11), since the depth texture is already rendered explicitly in a previous render pass.

Protected _uOffset

_uOffset: WebGLUniformLocation

Protected _uScale

_uScale: WebGLUniformLocation

readDepthAt

readDepthAt: function

Read the the depth of a fragment in normalized device coordinates. The implementation of this function is assigned at initialization based on the available WebGL features.

param

Horizontal coordinate for the upper left corner of the viewport origin.

param

Vertical coordinate for the upper left corner of the viewport origin.

Type declaration

    • (x: GLsizei, y: GLsizei): Uint8Array
    • Parameters

      • x: GLsizei
      • y: GLsizei

      Returns Uint8Array

Accessors

cache

  • set cache(value: boolean): void
  • Whether or not caching of requested depths and ids should be used to reduce performance impact.

    Parameters

    • value: boolean

    Returns void

coordinateReferenceSize

  • set coordinateReferenceSize(size: GLsizei2 | undefined): void
  • Sets the coordinate-reference size that is, if not undefined, used to scale incomming x and y coordinates.

    Parameters

    • size: GLsizei2 | undefined

      Size of the output, e.g., the canvas, the buffer is rendered to.

    Returns void

depthAttachment

  • set depthAttachment(attachment: GLenum): void
  • Sets the framebuffer's depthFBO depth attachment that is to be used for depth readback.

    Parameters

    • attachment: GLenum

      Depth attachment that is to be used for depth readback.

    Returns void

depthFBO

  • Sets the framebuffer object that is to be used for depth readback.

    Parameters

    • framebuffer: Framebuffer

      Framebuffer that is to be used for depth readback.

    Returns void

idAttachment

  • set idAttachment(attachment: GLenum): void
  • Sets the framebuffer's idFBO id attachment that is to be used for id readback.

    Parameters

    • attachment: GLenum

      ID attachment that is to be used for id readback.

    Returns void

idFBO

  • Sets the framebuffer object that is to be used for id readback.

    Parameters

    • framebuffer: Framebuffer

      Framebuffer that is to be used for id readback.

    Returns void

initialized

  • get initialized(): boolean

Methods

Protected assertInitialized

  • assertInitialized(): void
  • Asserts the objects initialization status to be true. Note that the implementation is cached and forwarded to either an empty function when initialized and to an acutal assert(false) otherwise.

    Returns void

Protected assertUninitialized

  • assertUninitialized(): undefined
  • Asserts the objects initialization status to be false. Note that the implementation is cached and forwarded to either an empty function when uninitialized and to an acutal assert(false) otherwise.

    Returns undefined

coordsAt

  • coordsAt(x: GLsizei, y: GLsizei, zInNDC: number | undefined, viewProjectionInverse: mat4): vec3 | undefined
  • Retrieving the world space coordinate of a fragment.

    Parameters

    • x: GLsizei

      Horizontal coordinate for the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate for the upper left corner of the viewport origin.

    • zInNDC: number | undefined

      optional depth parameter (e.g., from previous query).

    • viewProjectionInverse: mat4

      matrix used to unproject the coordinate from ndc to world space.

    Returns vec3 | undefined

    • The unprojected world space coordinate at location x, y.

depthAt

  • depthAt(x: GLsizei, y: GLsizei): GLfloat | undefined
  • Retrieve the depth of a fragment in normalized device coordinates. The implementation of this function is assigned at initialization based on the available WebGL features. Please note that in order to get the far plane depth at just below 1.0, the clear depth should be set to: float24x1_from_uint8x3([255,255, 255]) = 0.9999999403953552 This will result in a readback of [255, 255, 255] and is the deepest depth value representable using a uint8x3. Using 1.0 should result in [256, 0, 0] and would be easy to detect, however, it is somehow clamped to [255, 0, 0] which is highly misleading and actual not nearly the far plane's depth. Thus, if [255, 255, 255] is read back, undefined will be returned by this query and thereby reduce the effective depth range by 1 over 255^3 - sorry.

    Parameters

    • x: GLsizei

      Horizontal coordinate for the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate for the upper left corner of the viewport origin.

    Returns GLfloat | undefined

Protected directReadDepthAt

  • directReadDepthAt(x: GLsizei, y: GLsizei): Uint8Array
  • Implements the direct readback of uint8x3 encoded depth values from a given framebuffer (see depthFBO and depthAttachment).

    Parameters

    • x: GLsizei

      Horizontal coordinate from the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate from the upper left corner of the viewport origin.

    Returns Uint8Array

    • An array with 4 uint8 entries, the first three of which encode the depth.

frame

  • frame(): void

Protected hash

  • hash(x: GLsizei, y: GLsizei): GLsizei
  • Create a numerical hash that can be used for efficient look-up (number preferred, no string for now). Note that the implementation assumes that we do not exceed 65k pixel in horizontal or vertical resolution soon.

    Parameters

    • x: GLsizei

      Horizontal coordinate from the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate from the upper left corner of the viewport origin.

    Returns GLsizei

idAt

  • idAt(x: GLsizei, y: GLsizei): GLsizei | undefined
  • Retrieve the id of an object at fragment position.

    Parameters

    • x: GLsizei

      Horizontal coordinate for the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate for the upper left corner of the viewport origin.

    Returns GLsizei | undefined

    • The id rendered at location x, y.

initialize

  • Specializes this pass's initialization. If required. ad screen-filling triangle geometry and a single program are created. All attribute and dynamic uniform locations are cached.

    Parameters

    • ndcTriangle: NdcFillingTriangle | undefined

      If specified, assumed to be used as shared geometry. If none is specified, a ndc-filling triangle will be created internally.

    • direct: boolean

      If depth is already uint8x3 encoded into a rgb/rgba target no readback workaround is required.

    Returns boolean

Protected onFrame

  • onFrame(): void
  • Frame implementation clearing depth and ID caches. To avoid unnecessary readbacks (potentially causing sync points), the requested and found IDs and depths are cached by position. Hence, these cached values have to be cleared whenever the framebuffers are written/rendered to.

    Returns void

renderThenReadDepthAt

  • renderThenReadDepthAt(x: GLsizei, y: GLsizei): Uint8Array
  • Implements the indirect readback of uint8x3 encoded depth values from a given framebuffer (see depthFBO and depthAttachment). This renders a single pixel (1x1 pixel viewport) with the depth fbo as texture and reads this afterwards. This is a fallback required when direct pixel read from depth attachments is not supported.

    Parameters

    • x: GLsizei

      Horizontal coordinate for the upper left corner of the viewport origin.

    • y: GLsizei

      Vertical coordinate for the upper left corner of the viewport origin.

    Returns Uint8Array

    • An array with 4 uint8 entries, the first three of which encode the depth.

uninitialize

  • uninitialize(): void
  • Specializes this stage's uninitialization. Program and geometry resources are released (if allocated). Cached uniform and attribute locations are invalidated.

    Returns void

Static Protected assertInitializedFalse

Static Protected assertUninitializedFalse

Static assert_initialized

Static assert_uninitialized

Static initialize

  • Method decorator for initialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be initialized, invokes its initialization with arbitrary number of parameters, and sets the initialization status to the initialization success (either false or true). In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to either a static, always-failing assert or an empty/undefined function.

    Returns MethodDecorator

Static maxClearDepth

  • maxClearDepth(): GLfloat
  • Returns the maximal depth value that can be encoded when using a uint8[3] - @seedepthAt.

    Returns GLfloat

Static uninitialize

  • Method decorator for uninitialization of Initializable inheritors. This decorator asserts the initialization status of the instance that is to be uninitialized, invokes its uninitialization, and falsifies the initialization status. In order to encourage the use of assertInitialized and assertUninitialized they are dynamically bound to a static, always-failing assert and an empty/undefined function respectively.

    Returns MethodDecorator