Constant()
new Constant()
Constant is a container for const declarations.
They work in two ways with the override attribute.
- Source:
- Constant.js, line 3
Members
name
The name that the Constant will have on the WGSL side.
- Source:
- Constant.js, line 55
Example
myConstant.name = 'MYCONST'; // wgsl let newVal = MYCONST + 3;js
override
A constant override is a constant you can change per shader. By default, POINTS interpolates constant declarations inside the WGSL string shader like this:
const MYCONST:u32 = 10;
These declarations are added by default to all shaders in the pipeline and in all render passes. These can not be changed.
With overrides you can have the same constant in different shaders with different values. The default value is passed to each pipeline and then it can be overwritten in a specific shader by hand.
- Source:
- Constant.js, line 123
Example
```js
// js side
constants.PI.setOverride(true).setValue(3.14);
```
```wgsl
// wgsl side
override MYCONST:u32 = 3.1415;
```
shaderStage
Tells WebGPU to which shader it can only be used.
- Source:
- Constant.js, line 136
type
Get or set the type of the constant.
It can be inferred automatically by just passing the value, but if
something more specific is required, then you should use type.
- Source:
- Constant.js, line 90
Example
myConstant.type = 'u32';
value
Get or set the value that the constant will have on the WGSL side.
- Source:
- Constant.js, line 70
Methods
setOverride()
A constant override is a constant you can change per shader. By default, POINTS interpolates constant declarations inside the WGSL string shader like this:
const MYCONST:u32 = 10;
These declarations are added by default to all shaders in the pipeline and in all render passes. These can not be changed.
With overrides you can have the same constant in different shaders with different values. The default value is passed to each pipeline and then it can be overwritten in a specific shader by hand.
- Source:
- Constant.js, line 191
Example
```js
// js side
constants.PI.setOverride(true).setValue(3.14);
```
```wgsl
// wgsl side
override MYCONST:u32 = 3.1415;
```
setShaderStage(value) → Constant
Tells WebGPU to which shader it can only be used.
Parameters:
| Name | Type | Description |
|---|---|---|
value
|
GPUShaderStage |
- Source:
- Constant.js, line 202
Returns:
- Type:
- Constant
setType(value)
Set the data type of the Constant.
Parameters:
| Name | Type | Description |
|---|---|---|
value
|
String | WGSL data type of the constant |
- Source:
- Constant.js, line 161
Example
myUniform.setType('u32')
setValue(value) → Constant
Sets the value of a Constant
Parameters:
| Name | Type | Description |
|---|---|---|
value
|
|
- Source:
- Constant.js, line 146
Returns:
- Type:
- Constant