WebXR AR - Opacity Blending
There is some issue with the way opacity is blended when using WebXR AR session. This happens in the emulator and on devices (Android, Quest 3, etc).
It looks like alpha is not accumulated, but the last rendered fragment alpha is written.
Camera clear color is 0,0,0,0. Body CSS background color is 0,0,0,0. Canvas background color is 0,0,0,0.
Test URL: https://playcanv.as/e/b/70c1ec2f
Normal:
In WebXR:
Yeah this is a general rendering issue (not specific to GS) when generating any render target that will be blended with premulitplied alpha. The problem is material's "normal" blending type must be changed to accommodate premultiplied alpha render target.
You could change all the alpha blended materials in your scene, but this is hugely cumbersome. Ideally the engine would natively support a Premultiplied Render Target mode or similar and handle it internally.
I've solved problem this in the past by monkey-patching Material.blendType setter to modify the resulting alpha blend:
this._blendState.setAlphaBlend(BLENDEQUATION_ADD, BLENDMODE_ONE, BLENDMODE_ONE_MINUS_SRC_ALPHA);
Not a great solution.
I wonder whether we could change the NORMAL blend type to output premultiplied alpha values like above. The current NORMAL blend type doesn't generate a useful alpha channel anyway and I don't think developers will be depending on it.
cc @mvaligursky
Just to add, material blend modes currently set alpha blend state to match color blend state. NORMAL blend state is:
this._blendState.setAlphaBlend(BLENDEQUATION_ADD, BLENDMODE_SRC_ALPHA, BLENDMODE_ONE_MINUS_SRC_ALPHA);
See here.