I have a shader that is using a struct with a sampler2D field. I've had to make a change in three.js to make it work. Perhaps the change should be included in three.js?
I'm getting this crash:
Uncaught TypeError: Cannot read property 'allocTextureUnit' of undefined
at SingleUniform.setValueT1 [as setValue] (three.js:4505)
at StructuredUniform.setValue (three.js:4697)
at Function.WebGLUniforms.upload (three.js:4826)
at setProgram (three.js:22170)
at WebGLRenderer.renderBufferDirect (three.js:20964)
at renderObject (three.js:21722)
at renderObjects (three.js:21695)
at WebGLRenderer.render (three.js:21463)
at render (app.js:2758)
at Object.execute (app.js:2760)
This is from build/three.js (0.86 from npm) (removed some whitespace):
StructuredUniform.prototype.setValue = function ( gl, value ) {
// Note: Don't need an extra 'renderer' parameter, since samplers
// are not allowed in structured uniforms.
var seq = this.seq;
for ( var i = 0, n = seq.length; i !== n; ++ i ) {
var u = seq[ i ];
u.setValue( gl, value[ u.id ] );
}
};
If I do add renderer as parameter and pass it along to u.setValue, everything works as expected:
StructuredUniform.prototype.setValue = function ( gl, value, renderer ) {
var seq = this.seq;
for ( var i = 0, n = seq.length; i !== n; ++ i ) {
var u = seq[ i ];
u.setValue( gl, value[ u.id ], renderer );
}
};
Now, about the comment. Is it true that samplers in structs are not allowed? Because it really does work after this change. Is there a difference between browsers, OSs or GPUs regarding this? My understanding after browsing around a bit, is that samplers in structs are allowed as long as the struct is a uniform. So I think three.js should allow this too.
Radeon Pro 560 4096 MB
EDIT: spelling & grammar
@tschw what do you think?
I did some further investigation. It seams like samplers in structs are allowed in Chrome on Windows too, but not in Edge. So I guess I'll have to rewrite my shaders anyway.
UPDATE:
I've opened a bug with Edge: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12874198/
I'm planning on rewriting my shader with an array of samplers instead and keeping the array index in the struct.
Why was this closed?
UPDATE: Typo
Because sounds like it's a bug in Edge and not in the library...?
No, there is a bug in Edge which causes it to not support samplers in (uniform) structs. However, all other browsers support it. But threejs does not allow it, in any browser. The simple change I made (seen above) makes it work with threejs though.
Most helpful comment
No, there is a bug in Edge which causes it to not support samplers in (uniform) structs. However, all other browsers support it. But threejs does not allow it, in any browser. The simple change I made (seen above) makes it work with threejs though.