Hi All,
First of all: Congratulations for the new 7.0 release! It looks awesome! Can’t wait to play with Gaussian Splatting.
I’m back with a question / bug report about the combination of
order-independent transparency
using a custom shader
which uses needAlphaBlending.
This breaks the shader (GL_INVALID_OPERATION: Active draw buffers with missing fragment shader outputs.) I looked into the OIT fragment shader files and was able to fix the GL_INVALID_OPERATION error by setting the missing outputs (depth, frontColor, backColor), but since I don’t fully understand the details if this OIT implementation, I could not get it to render correctly.
It’s a bit complicated because you will have to implement the necessary code in your custom shader to support OIT. You should take example on the standard material and look for the ORDER_INDEPENDENT_TRANSPARENCY define. You will also have to add #include<oitDeclaration> and #include<oitFragment> in your shader. Again, look how it is done in the default material (shaders/default.vertex.fx and shaders/default.fragment.fx).
I create a new CustomMaterial, and then I inject some stuff into the default shader.
Check out the vertex code and search for “CUSTOM_VERTEX_”. Then you will find all possible insertion points.
The same applies to fragment shader, but search for (you guessed it) “CUSTOM_FRAGMENT_” instead.
After that I add an observer to the material’s onBindObservable which sets the according bindings right before rendering the object.
Dear Babylon developers, please chime in and let me know if anything can be improved or clarified.
Thanks so much for helping out. For certain reasons, I have to stick to the shaderMaterial.
Please have a look at https://playground.babylonjs.com/#FHIIKI#9.
My goal is to create a simple shadermaterial WITH OIT support.
What I’m missing here is how to setup oitDepthSampler oitFrontColorSampler. @Evgeni_Popov - can you help? This might be interesting for many users.
You can reuse the existing OIT shader code by using the same #includes than the ones used in the PBR / standard materials. Also, you have to declare the oitDepthSampler and oitFrontColorSampler samplers when you create your material (line 72). To bind the samplers, simply call scene.depthPeelingRenderer.bind(shaderMaterial.getEffect()) (line 80):