At any given point I may have 2 objects that share mostly the same space (sometimes clones, sometimes sharing a single face), One will have DepthFunction Less
and the other LessEqual
on their respective materials.
When both object’s materials are StandardMaterials
or both are ShaderMaterials
there is no issue with how I want them to draw.
When one object has a Standard Material
and the other has ShaderMaterial
there is an insane amount of z/depth fighting between the two objects even though the object with DepthFunction Less
should be drawn over. The properties (as far as I know) being assigned to the materials are identical after construction.
Playerground:
Matching StandardMaterials (no issue): Babylon.js Playground
Matching ShaderMaterials (no issue): https://playground.babylonjs.com/#1OH09K#2652
Mismatched Materials (issue): https://playground.babylonjs.com/#1OH09K#2653
The need for the 2 materials comes from wanting some objects to use babylon’s default shader with lighting and clipping, but others do not have that requirement and/or have unique gl_frag_color calculations.
I have tried creating a simple version of the StandardMaterial
as a ShaderMaterial
by attempting to hook the lighting shader includes into a lightweight custom shader but I did not have much success.
The best solution would be one that allows me to resolve this z-fighting between the 2 different material types, or at least understand why its not possible to layer the different materials like this since it works as intended when the materials are of the same type.