How can I set a uniform of type ‘samplerCube’ in a custom shader given an asset of type ‘cubemap’ ?
description: 'reflection cubemap'
graphicsDevice.scope.resolve("uSomeMatrix").setValue(myMat4.data); // works
graphicsDevice.scope.resolve("uSomeFloat").setValue(1.0); // works
// but how to set samplerCube?
//graphicsDevice.scope.resolve("uSomeSamplerCube").setValue(this.reflectionTexture); // does not work
//graphicsDevice.scope.resolve("uSomeSamplerCube").setValue(this.reflectionTexture.data); // does not work
//graphicsDevice.scope.resolve("uSomeSamplerCube").setValue(this.reflectionTexture.resource); // does not work
//graphicsDevice.scope.resolve("uSomeSamplerCube").setValue(this.reflectionTexture.resources); // does not work
so, how do I properly set a samplerCube uniform on the graphics device before rendering?
Okay, well anyway you you are setting uniforms through graphicsDevice.scope it should work the same way as setting it through material. Just a question - what do you mean exactly by ‘does not work’? When you try textureCube() in GLSL, is your mesh all black? I had this same issue and figured out it was due to using default playcanvas cubemap (heliport) as my input cubemap for the shader, when the cubemap was prefiltered and in Playcanvas render settings it had Mip value set to 2. When changed back to 1, it worked.
The model does not render at all and I’m getting the following GLSL errors:
[.Offscreen-For-WebGL-000001F27635CC70]RENDER WARNING: there is no texture bound to the unit 0
[.Offscreen-For-WebGL-000001F27635CC70]GL ERROR :GL_INVALID_OPERATION : glTexImage2D: <- error from previous GL command
[.Offscreen-For-WebGL-000001F27635CC70]GL ERROR :GL_INVALID_OPERATION : glFramebufferTexture2D: <- error from previous GL command
WebGL: too many errors, no more errors will be reported to the console for this context.
It doesn’t really matter whether or not I use ‘refraction’ in the final gl_FragColor (so if I return for example col + refraction, the result is the same). The shader compiles, but the model doesn’t render and I’m getting above warnings/errors. If I uncomment the line with the textureCube() call, then my model renders yellow as expected (uSomeTexture is a 1x1 pixel yellow texture) and there are no warnings/errors.
//edit: IFF I prefilter the cubemap, the app won’t start at all and I’m getting a
Error loading scripts. Open the browser console for details.
with the following in the console:
Uncaught RangeError: Invalid typed array length: 32
at new Uint32Array (<anonymous>)
at TextureHandler.open (playcanvas-stable.dbg.js:34825)
at ResourceLoader.<anonymous> (playcanvas-stable.dbg.js:33939)
at Object.callback (playcanvas-stable.dbg.js:34764)
at Object._onSuccess (playcanvas-stable.dbg.js:20888)
at Object._onReadyStateChange (playcanvas-stable.dbg.js:20850)
at Object.<anonymous> (playcanvas-stable.dbg.js:20805)
Got the same error. Cubemap here is much more difficult to use than Unity
By changing the cubemap’s textures’ compression setting, delete and re-prefilter, switching scene’s skybox, it somehow fixed tthe “Uncaught RangeError: Invalid typed array length: 32” problem. but i still can’t make my shader use the correct lod of cubemap