Capítulo 785 de 859

Chapter 785: Uniform

Core Idea

Represents a uniform which is a global shader variable. They are passed to shader programs.

When declaring a uniform of a ShaderMaterial, it is declared by value or by object.

Since this class can only be used in context of ShaderMaterial, it is only supported in WebGLRenderer.

Key Concepts

  • boundary : number: Used to build the uniform buffer according to the STD140 layout. Derived uniforms will set this property to a data type specific value.
  • index : number: This property is set by UniformsGroup and marks the index position in the uniform array.
  • itemSize : number: The item size. Derived uniforms will set this property to a data type specific value.
  • name : string: The uniform's name.
  • offset : number: This property is set by UniformsGroup and marks the start position in the uniform buffer.
  • value : any: The uniform value.
  • value : any: The uniform's value.

Code Examples

uniforms: {
	time: { value: 1.0 },
	resolution: new Uniform( new Vector2() )
};
  • What it demonstrates: Typical usage of Uniform.

Reference Tables

Constructor

Signature
new Uniform( value : any )

Properties

PropertyDescription
.boundary : numberUsed to build the uniform buffer according to the STD140 layout. Derived uniforms will set this property to a data type specific value.
.index : numberThis property is set by UniformsGroup and marks the index position in the uniform array.
.itemSize : numberThe item size. Derived uniforms will set this property to a data type specific value.
.name : stringThe uniform's name.
.offset : numberThis property is set by UniformsGroup and marks the start position in the uniform buffer.
.value : anyThe uniform value.
.value : anyThe uniform's value.

Methods

MethodDescription
.clone() : UniformReturns a new uniform with copied values from this instance. If the value has a clone() method, the value is cloned as well.
.getValue() : anyReturns the uniform's value.
.setValue( value : any )Sets the uniform's value.

Key Takeaways

  1. Most relevant properties: boundary, index, itemSize, name.
  2. Key methods: clone, getValue, setValue.

Connects To