Class: UniformGroup

UniformGroup

Uniform group holds uniform map and some ID's for work

UniformGroup has two modes:

1: Normal mode Normal mode will upload the uniforms with individual function calls as required. This is the default mode for WebGL rendering.

2: Uniform buffer mode This mode will treat the uniforms as a uniform buffer. You can pass in either a buffer that you manually handle, or or a generic object that PixiJS will automatically map to a buffer for you. For maximum benefits, make Ubo UniformGroups static, and only update them each frame. This is the only way uniforms can be used with WebGPU.

Rules of UBOs:

  • UBOs only work with WebGL2, so make sure you have a fallback!
  • Only floats are supported (including vec[2,3,4], mat[2,3,4])
  • Samplers cannot be used in ubo's (a GPU limitation)
  • You must ensure that the object you pass in exactly matches in the shader ubo structure. Otherwise, weirdness will ensue!
  • The name of the ubo object added to the group must match exactly the name of the ubo in the shader.

When declaring your uniform options, you ust parse in the value and the type of the uniform. The types correspond to the WebGPU types UNIFORM_TYPES

Uniforms can be modified via the classes 'uniforms' property. It will contain all the uniforms declared in the constructor.

// UBO in shader:
uniform myCoolData { // Declaring a UBO...
    mat4 uCoolMatrix;
    float uFloatyMcFloatFace;
};
// A new Uniform Buffer Object...
const myCoolData = new UniformGroup({
    uCoolMatrix: {value:new Matrix(), type: 'mat4<f32>'},
    uFloatyMcFloatFace: {value:23, type: 'f32'},
}}

// modify the data
myCoolData.uniforms.uFloatyMcFloatFace = 42;
// Build a shader...
const shader = Shader.from(srcVert, srcFrag, {
    myCoolData // Name matches the UBO name in the shader. Will be processed accordingly.
})


new UniformGroup (uniformStructures, options)

Create a new Uniform group

Name Type Attributes Description
uniformStructures UNIFORMS

The structures of the uniform group

options UniformGroupOptions <optional>

The optional parameters of this uniform group

Implements

Members

defaultOptions UniformGroupOptions static

The default options used by the uniform group.

Properties:
Name Type Default Description
isStatic boolean false

if true, then you are responsible for when the data is uploaded to the GPU by calling update()

ubo boolean false

if true the UniformGroup is handled as an Uniform buffer object.

_resourceId

the resource id used internally by the renderer to build bind group keys

_resourceType string

a resource type, used to identify how to handle it when its in a bind group / shader resource

Default Value:
  • "uniformGroup"

_touched number

used internally to know if a uniform group was used in the last render pass

Default Value:
  • 0

buffer Buffer

an underlying buffer that will be uploaded to the GPU when using this UniformGroup

isStatic boolean

if true, then you are responsible for when the data is uploaded to the GPU. otherwise, the data is reuploaded each frame.

isUniformGroup boolean readonly

used ito identify if this is a uniform group

Default Value:
  • true

ubo boolean

true if it should be used as a uniform buffer object

uid number readonly

a unique id for this uniform group used through the renderer

uniforms ExtractUniformObject<UNIFORMS>

the uniforms as an easily accessible map of properties

uniformStructures UNIFORMS

the structures of the uniform group

Methods

update () void

Call this if you want the uniform groups data to be uploaded to the GPU only useful if isStatic is true.