Hi together,
this may be a bit specific but I try my best to generalize my issue/question.
Qustion / Issue
I ran into a problem with CreateScreenshotUsingRenderTargetAsync() using a custom PBR shader that has its own #ifdef block.
If I update the material (custom defines habe to be updated) shortly before taking the screenshot the target object is invisible within the screenshot. If I repeat the action it works as intended.
I event tried calling CreateScreenshotUsingRenderTargetAsync within scene.onAfterRenderObservable without any luck. Another idea was to wait until material.isReady() is set to true. However as far as I can tell it is never set to true.
Is there a way to ensure the shader is fully rebuild before the screenshot is taken? Or did I handle the implementation of custom #ifdev blocks wrong and should use another approach?
Playground
https://playground.babylonjs.com/#VMKSIU#12
- Basic custom material / shader with a
useCustomDefineproperty - Shader code contains a custom
#ifdefblock that changes the color if set - Material overrides the Builder() function to update the shader defines depending on the state of
useCustomDefineproperty - If
useCustomDefineis enabled the shader will draw each pixel in green - The button updates the
useCustomDefineand takes a screenshot
Desired Behavior: On the press of a button the material is updated and the screenshot contains the image of the updated sphere.
Observed Behavior: After pressing the button for the first time the screenshot does not contain any sphere. On the next clicks the screenshot works as expected.
Video:
Sadly this is not reproducible 100% of the time! Sometimes it will happen on every first click after I recompile the playground solution. Sometimes it works perfectly fine…