Skip to content

decode.webgpu.Class.GainMapNode

github-actions[bot] edited this page Oct 19, 2026 · 5 revisions

@monogrid/gainmap-js / decode/webgpu / GainMapNode

Class: GainMapNode

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:74

A TSL texture node holding the HDR image decoded from an SDR image + gain map.

The decode runs on the GPU into a HalfFloat render target, and only when something changed (textures loaded/swapped or any uniform value changed): sampling the node costs a single texture read, like any other texture.

The node updates itself before rendering whenever it is part of a rendered node graph (material, scene.backgroundNode, ...). When only its texture is used (node.value, e.g. scene.environment = node.value) call GainMapNode.decode yourself.

Re-decoding also flags the texture for PMREM regeneration, so environment maps are recomputed only when the image actually changes.

node.value gets its final size once loaded: three.js PMREMs don't follow texture resizes, so assign it to scene.environment (or pmremTexture()) after load.

Example

import { GainMapNode } from '@monogrid/gainmap-js/webgpu'
import { equirectUV } from 'three/tsl'

const hdr = new GainMapNode()
  .setTextures(sdrTexture, gainMapTexture)
  .setMetadata(metadata)

material.colorNode = hdr
scene.backgroundNode = hdr.sample(equirectUV())
hdr.maxDisplayBoost.value = 2 // re-decodes once, on the next frame

Extends

  • TextureNode

Constructors

Constructor

new GainMapNode(): GainMapNode

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:93

Returns

GainMapNode

Overrides

TextureNode.constructor

Properties

renderTarget

readonly renderTarget: RenderTarget

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:85

The render target holding the decoded HDR image


uniforms

readonly uniforms: GainMapNodeUniforms

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:80

Shared textures and uniforms

Accessors

gainMap

Get Signature

get gainMap(): Texture<unknown, TextureEventMap>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:134

The gain map recovery texture (linear)

Returns

Texture<unknown, TextureEventMap>


gainMapMax

Get Signature

get gainMapMax(): UniformNode<"vec3", Vector3>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:145

See

GainMapMetadata.gainMapMax

Returns

UniformNode<"vec3", Vector3>


gainMapMin

Get Signature

get gainMapMin(): UniformNode<"vec3", Vector3>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:143

See

GainMapMetadata.gainMapMin

Returns

UniformNode<"vec3", Vector3>


gamma

Get Signature

get gamma(): UniformNode<"vec3", Vector3>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:137

See

GainMapMetadata.gamma

Returns

UniformNode<"vec3", Vector3>


hdrCapacityMax

Get Signature

get hdrCapacityMax(): UniformNode<"float", number>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:149

See

GainMapMetadata.hdrCapacityMax

Returns

UniformNode<"float", number>


hdrCapacityMin

Get Signature

get hdrCapacityMin(): UniformNode<"float", number>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:147

See

GainMapMetadata.hdrCapacityMin

Returns

UniformNode<"float", number>


height

Get Signature

get height(): number

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:159

Height of the SDR image, 0 until loaded

Returns

number


maxDisplayBoost

Get Signature

get maxDisplayBoost(): UniformNode<"float", number>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:154

See

GainmapDecodingParameters.maxDisplayBoost

Remarks

Non Logarithmic space

Returns

UniformNode<"float", number>


offsetHdr

Get Signature

get offsetHdr(): UniformNode<"vec3", Vector3>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:141

See

GainMapMetadata.offsetHdr

Returns

UniformNode<"vec3", Vector3>


offsetSdr

Get Signature

get offsetSdr(): UniformNode<"vec3", Vector3>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:139

See

GainMapMetadata.offsetSdr

Returns

UniformNode<"vec3", Vector3>


sdr

Get Signature

get sdr(): Texture<unknown, TextureEventMap>

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:132

The SDR rendition texture (sRGB)

Returns

Texture<unknown, TextureEventMap>


value

Get Signature

get value(): Texture

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:246

Returns

Texture

Set Signature

set value(value): void

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:240

Parameters
value

Texture

Returns

void

Overrides

TextureNode.value


width

Get Signature

get width(): number

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:157

Width of the SDR image, 0 until loaded

Returns

number


type

Get Signature

get static type(): string

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:75

The type of the class. The value is usually the constructor name.

Returns

string

Methods

clone()

clone(): GainMapNode

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:254

Clones created by sample() & co. are plain TextureNodes reading this node's texture, they keep it updated before rendering as well

Returns

GainMapNode

Overrides

TextureNode.clone


decode()

decode(renderer): boolean

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:213

Decodes the image into GainMapNode.renderTarget, only if something changed since the last decode.

Called automatically when the node is part of a rendered node graph.

Parameters

renderer

WebGPURenderer

Returns

boolean

true if the image was decoded


dispose()

dispose(): void

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:265

Disposes the render target, the SDR and gain map textures

Returns

void

Overrides

TextureNode.dispose


setMetadata()

setMetadata(metadata): GainMapNode

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:182

Copies the gain map metadata into the uniforms. Also sets maxDisplayBoost to fully restore the HDR range.

Parameters

metadata

GainMapMetadata

Returns

GainMapNode


setTextures()

setTextures(sdr, gainMap): GainMapNode

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:168

Sets the SDR and gain map textures. The SDR texture is expected in sRGB color space, the gain map in linear.

Parameters

sdr

Texture

gainMap

Texture

Returns

GainMapNode


updateBefore()

updateBefore(frame): undefined

Defined in: src/decode/webgpu/nodes/GainMapNode.ts:235

Calls GainMapNode.decode once per render, before the node is evaluated.

Parameters

frame

NodeFrame

Returns

undefined

Overrides

TextureNode.updateBefore

Clone this wiki locally