Skip to main content

Class: HistogramTexture

Calculate a histogram from a source texture.

Internally, a cascade of shaders is run: the first shader calculates a separate histogram for each part of the screen, and then a series of reduction shaders combine the partial histograms.

The number of buckets in the histogram is configurable.

The range of values to spread across the buckets is also configurable. The range may be specified by the cpu, or dynamically provided some other shader writing to a two element GPUBuffer.

Optionally, the sum for each bucket can also collected in parallel with the frequency counts in the histogram. The sums are reported in a separate buffer.

Hierarchy

  • HasReactive

    HistogramTexture

Implements

Constructors

constructor

new HistogramTexture(params): HistogramTexture

Parameters

NameType
paramsHistogramTextureParams

Returns

HistogramTexture

Overrides

HasReactive.constructor

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:132

Properties

blockSize

blockSize: Vec2

length of block to read per thread when reading from the source texture

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:92


bucketSums

bucketSums: boolean

optinally calculate sums for each bucket in addition to counts

Default Value

false

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:123


bufferBlockLength

bufferBlockLength: undefined | number

number of histograms to read per thread when reducing from buffer to buffer

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:95


device

device: GPUDevice

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:128


forceWorkgroupSize

forceWorkgroupSize: undefined | Vec2

Override to set compute workgroup size e.g. for testing.

Default Value

maxComputeInvocationsPerWorkgroup of the GPUDevice (256)

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:118


histogramOps

histogramOps: HistogramModule

wgsl macros for histogram reduction and histogram size. Typically call histogramModule()

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:100


label

Optional label: string

Debug label attached to gpu objects for error reporting

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:126


minMaxBuffer

Optional minMaxBuffer: GPUBuffer

buffer containing min and max values for the histogram range (or use range)

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:113


range

Optional range: Vec2

range of histogram values (or provide minMaxBuffer)

Default Value

[0, 255]

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:110


source

source: GPUTexture

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:89


sourceComponent

sourceComponent: LoadComponent | ComponentName

select or synthesize a component from the source texture

Default Value

"r"

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:105

Accessors

result

get result(): GPUBuffer

accumulated histogram (frequency counts)

Returns

GPUBuffer

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:158


sumsResult

get sumsResult(): GPUBuffer

accumulated bucket counts, only valid if bucketSums is true

Returns

GPUBuffer

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:167

Methods

commands

commands(commandEncoder): void

Add compute or render passes for this shader to the provided GPUCommandEncoder

Parameters

NameType
commandEncoderGPUCommandEncoder

Returns

void

Implementation of

ComposableShader.commands

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:137


destroy

destroy(): void

Returns

void

Implementation of

ComposableShader.destroy

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:141


histogram

histogram(): Promise<number[]>

Execute the histogram immediately and copy the results back to the CPU. (results are copied from the HistogramTexture.result GPUBuffer)

To use HistogramTexture in concert with external shaders, instead use HistogramTexture.commands or ShaderGroup.

Returns

Promise<number[]>

a single histogram in an array

Defined in

packages/stoneberry/src/histogram-texture/HistogramTexture.ts:153