AlexB Posted June 19, 2018 Share Posted June 19, 2018 I'm having a really hard time figuring this out. I'm creating this material. this.material = new BABYLON.ShaderMaterial( part.url, this.viewService.scene, { vertex: '/shaders/v', fragment: '/shaders/f', }, { needAlphaBlending: true, needAlphaTesting: true, defines: [ '#extension GL_OES_standard_derivatives : enable', '#define IS_CLOWN_PASS 0', '#define IS_TRANSLUCENT false', '#define IS_METAL false', ], attributes: ['position', 'uv', 'normal'], uniforms: [ 'world', 'worldView', 'worldViewProjection', 'view', 'viewProjection', 'u_combinedTextures', 'texArr', ], } ); Then a few seconds later, in a totally different function, I'm attempting to update a uniform. this.material.setTextureArray('texArr', [ // red BABYLON.RawTexture.CreateRGBATexture(new Uint8Array([255, 0, 0, 255]), 1, 1, this.viewService.scene), // blue BABYLON.RawTexture.CreateRGBATexture(new Uint8Array([0, 0, 255, 255]), 1, 1, this.viewService.scene), ]); this.material.isReady(mesh); mesh.material = this.material; This works if I paste this code right below where I create the material. Otherwise it seems to not set the values (I use SpectorJS to inspect the uniforms). Some questions: Is there another command I need to call to get the material to update? Does every uniform need to be in the initial uniforms array? How does setting the uniforms directly differ from scene.registerBeforeRender and doing it there? Quote Link to comment Share on other sites More sharing options...
brianzinn Posted June 19, 2018 Share Posted June 19, 2018 Did you try this.material.markDirty() or this.material.markAsDirty( BABYLON.Material.TextureDirtyFlag)? Quote Link to comment Share on other sites More sharing options...
AlexB Posted June 19, 2018 Author Share Posted June 19, 2018 No, what's the syntax for that? Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 19, 2018 Share Posted June 19, 2018 I might be mistaken but: uniforms: [ 'world', 'worldView', 'worldViewProjection', 'view', 'viewProjection' ], samplers: [ 'u_combinedTextures', 'texArr[2]' ] Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 20, 2018 Share Posted June 20, 2018 Is there another command I need to call to get the material to update? The material should update on the next frame when you set the info. Does every uniform need to be in the initial uniforms array? Yes they should be listed in the initial one in order to get their location How does setting the uniforms directly differ from scene.registerBeforeRender and doing it there? The first time the effect is created it keeps a map of uniform names to glUniformLocation based on the name you provide. Calling setTextureArray before the first render will automatically append the uniform name before the first render hence resulting in the uniform name being cached and usable. If you do it after I guess the cache does not contain the location hence why it does not work. Hope this could help. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 20, 2018 Share Posted June 20, 2018 if its a sampler though, I'm almost positive it needs to be under the "samplers" argument on the constructor options. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 20, 2018 Share Posted June 20, 2018 Yup as PRyme said as well ? Quote Link to comment Share on other sites More sharing options...
AlexB Posted June 20, 2018 Author Share Posted June 20, 2018 This seems to be working, but only intermittently. Sometimes I will see my texture, but then I change some arbitrary code someone else and it'll stop working. It seems as though there is a race condition somewhere. When I inspect the scene using Spector, I don't always see the uniforms. I know for a fact that the material creator method is happening before the uniform setting method. I can also re-trigger the setter function so I don't think it's a race condition in my code. Quote Link to comment Share on other sites More sharing options...
Sebavan Posted June 20, 2018 Share Posted June 20, 2018 This is really weird and sounds like a bug. Could you create a repro in the playground ? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.