-
-
Notifications
You must be signed in to change notification settings - Fork 36.3k
Description
Description
When passing multiple related uniforms around its handy to group them in structs:
const environmentInfoStruct = struct({
rotation: 'mat3',
intensity: 'float',
blur: 'float',
}, 'EnvironmentInfo' );
fn sampleEnvironment(
envMap: texture_2d<f32>,
envMapSampler: sampler,
env: EnvironmentInfo,
direction: vec3f,
uv: vec2f,
) -> vec3f {
///
}Yet it does not seem possible to pass uniforms as a single struct. Maybe there is an example I missed?
uniform node docs do not mention structs and there does not seem to be any special node for uniform structs.
three.js/src/nodes/core/UniformNode.js
Line 223 in 3ca54b0
| * @param {any|string} value - The value of this uniform or your type. Usually a JS primitive or three.js object (vector, matrix, color, texture). |
uniform( environmentInfoStruct( { /* values */ } ) )
uniform( { /* values */ } )
environmentInfoStruct( { /* values */ } )
All of the above does not seem to work.
Solution
Add support for passing structs as uniforms. uniform( /* struct value */ ) seems to be the most intuitive.
And it would be perfect if structs could be updated from a js object to avoid assigning every field. I'm not sure how it should be done syntactically. Along the lines of:
const envInfo = environmentInfoStruct( { /* values */ } );
envInfo.assign( { /* new values */ } );Alternatives
Pass each primitive in the struct as a separate uniform and group them at the start of the function:
envMapRotation: uniform( new Matrix3() ),
envMapIntensity: uniform( 1 ),
envMapBlur: uniform( 0 ),
---
let envInfo = EnvironmentInfo(
envMapRotation,
envMapIntensity,
envMapBlur,
);Additional context
No response