Hello,
i stumbled upon following issue: i am using CustomMaterial
with custom uniforms and custom shader parts. This is my PG demo. Everything works fine, until engine.resize()
is called - in the playground just resize the editor. After that my uniforms are black.
What i have found is that this happens when:
- i use
DefaultRenderingPipeline
with hdr = true
, or fxaaEnabled = true
- i use
GlowLayer
- i create second scene for same engine
When i don’t use any of these, then the textures are correct after resize.
Anything that i am missing in my CustomMaterial
so that my uniforms survive the resize?
Thanks
L
You should bind your uniforms on onBindObservable
and not on onCompiled
(which means the uniforms will be bound only a single time):
https://playground.babylonjs.com/#2LX5WU#17
2 Likes
Yea that works, thanks. Isn’t setting uniform each frame a heavy operation though? They don’t change that often in my application, so there is no need to update them every frame. I update them with material.onBindObservable.addOnce
. Maybe i should use engine.onResize
callback and set them each time engine is resized?
I don’t know when the uniforms can become invalidated, I will let @sebavan answer about this!
So uniform stick to their shader so all good but we have a cache in effects preventing to update them if unecessary so you could bind as often as you want. That said if in webgl2 it is a UBO, those can be shared on the material so need their value per bind
3 Likes