# Shader crash with OIT

**URL:** <https://forum.babylonjs.com/t/shader-crash-with-oit/40332>\
**Category:** Bugs\
**Created:** [April 28, 2023, 11:44am UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332 "2023-04-28T11:44:28Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 11:44am UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/1 "2023-04-28T11:44:28Z")

</div>

When turning OIT on, I get a shader code crash, that comes from a double definition _highp vec4 glFragColor;_

layout(location=0) out highp vec4 glFragData[SCENE\_MRT\_COUNT];  
**highp vec4 glFragColor;**  
layout(location=0) out vec2 depth;  
layout(location=1) out vec4 frontColor;  
layout(location=2) out vec4 backColor;  
#define MAX\_DEPTH 99999.0  
**highp vec4 glFragColor;**

I don’t use custom materials. It works in the playground, but not in our huge node-based project. Any idea, what can cause this? This creates the same result on Babylon 5.31 and 5.71. Thanks!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 12:13pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/2 "2023-04-28T12:13:52Z")

</div>

OIT is not supported with node materials because they don’t support the pre-pass renderer. We have an issue opened for this:

> <https://github.com/BabylonJS/Babylon.js/issues/13718>
>
> The prepass renderer only works with the standard and PBR materials.
> 
> It would… be nice to make node materials work with the prepass renderer, as node materials are used more and more often, and some effects do require materials to support the prepass renderer to work (like SSR, SSAO, ...).

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 12:17pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/3 "2023-04-28T12:17:33Z")

</div>

This is a misunderstanding, sorry. We use node.js. So the project is node-based. No node materials in use.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 12:51pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/4 "2023-04-28T12:51:42Z")

</div>

Sorry! So, it should not fail.

It seems you have something which is using the pre-pass renderer in addition to OIT in the same shader, which does not seem possible…

An external link would help, one that would show a working scene and where we could enable OIT afterwards (through the browser console, for eg).

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 12:57pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/5 "2023-04-28T12:57:02Z")

</div>

Thanks! What could be using the pre-pass renderer other than OIT?

To me, it looks like you add junks of code to the shader and a combination of two different properties combined creates the issue.

I cannot provide any external link, as this is such a huge project. If I turn off OIT, everything works, btw.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 1:53pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/6 "2023-04-28T13:53:10Z")

</div>

SSR, SSAO, sub-surface scattering PBR are using the pre-pass renderer by default.

Regarding SSR and SSAO, you can force using the geometry buffer renderer thanks to a parameter of their constructor. So, if you are using any of them, try forcing the geometry buffer renderer.

If you are using SS scattering, try turning it off.

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 2:22pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/7 "2023-04-28T14:22:25Z")

</div>

We are using none of those. Would it help, if I post the whole shader you generate?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 2:24pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/8 "2023-04-28T14:24:12Z")

</div>

Yes, please do so.

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 2:29pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/10 "2023-04-28T14:29:56Z")

</div>

BJS - [16:27:21]: #version 300 es  
#define WEBGL2  
#define MATERIALPLUGIN\_1  
#define DETAILDIRECTUV 0  
#define DETAIL\_NORMALBLENDMETHOD 0  
#define DIFFUSEDIRECTUV 0  
#define AMBIENTDIRECTUV 0  
#define OPACITYDIRECTUV 0  
#define EMISSIVEDIRECTUV 0  
#define SPECULARDIRECTUV 0  
#define BUMPDIRECTUV 0  
#define SPECULARTERM  
#define NORMAL  
#define VERTEXCOLOR  
#define NUM\_BONE\_INFLUENCERS 0  
#define BonesPerMesh 0  
#define LIGHTMAPDIRECTUV 0  
#define NUM\_MORPH\_INFLUENCERS 0  
#define ALPHABLEND  
#define PREPASS  
#define PREPASS\_IRRADIANCE\_INDEX -1  
#define PREPASS\_ALBEDO\_SQRT\_INDEX -1  
#define PREPASS\_DEPTH\_INDEX -1  
#define PREPASS\_NORMAL\_INDEX -1  
#define PREPASS\_POSITION\_INDEX -1  
#define PREPASS\_VELOCITY\_INDEX -1  
#define PREPASS\_REFLECTIVITY\_INDEX -1  
#define SCENE\_MRT\_COUNT 1  
#define VIGNETTEBLENDMODEMULTIPLY  
#define SAMPLER3DGREENDEPTH  
#define SAMPLER3DBGRMAP  
#define ORDER\_INDEPENDENT\_TRANSPARENCY  
#define CAMERA\_PERSPECTIVE  
#define LIGHT0  
#define DIRLIGHT0  
#define LIGHT1  
#define DIRLIGHT1

#define SHADER\_NAME fragment:default  
precision highp float;  
uniform vec4 vEyePosition;  
uniform vec4 vDiffuseColor;  
uniform vec4 vSpecularColor;  
uniform vec3 vEmissiveColor;  
uniform vec3 vAmbientColor;  
uniform float visibility;  
uniform mat4 view;  
#define ADDITIONAL\_FRAGMENT\_DECLARATION

layout(location=0) out highp vec4 glFragData[SCENE\_MRT\_COUNT];  
highp vec4 glFragColor;

layout(location=0) out vec2 depth;  
layout(location=1) out vec4 frontColor;  
layout(location=2) out vec4 backColor;  
#define MAX\_DEPTH 99999.0  
highp vec4 glFragColor;  
uniform sampler2D oitDepthSampler;  
uniform sampler2D oitFrontColorSampler;  
#define CUSTOM\_FRAGMENT\_BEGIN  
#define RECIPROCAL\_PI2 0.15915494  
in vec3 vPositionW;  
in vec3 vNormalW;  
in vec4 vColor;  
const float PI=3.1415926535897932384626433832795;  
const float HALF\_MIN=5.96046448e-08;  
const float LinearEncodePowerApprox=2.2;  
const float GammaEncodePowerApprox=1.0/LinearEncodePowerApprox;  
const vec3 LuminanceEncodeApprox=vec3(0.2126,0.7152,0.0722);  
const float Epsilon=0.0000001;  
#define saturate(x) clamp(x,0.0,1.0)  
#define absEps(x) abs(x)+Epsilon  
#define maxEps(x) max(x,Epsilon)  
#define saturateEps(x) clamp(x,Epsilon,1.0)  
mat3 transposeMat3(mat3 inMatrix) {  
vec3 i0=inMatrix[0];  
vec3 i1=inMatrix[1];  
vec3 i2=inMatrix[2];  
mat3 outMatrix=mat3(  
vec3(i0.x,i1.x,i2.x),  
vec3(i0.y,i1.y,i2.y),  
vec3(i0.z,i1.z,i2.z)  
);  
return outMatrix;  
}  
mat3 inverseMat3(mat3 inMatrix) {  
float a00=inMatrix[0][0],a01=inMatrix[0][1],a02=inMatrix[0][2];  
float a10=inMatrix[1][0],a11=inMatrix[1][1],a12=inMatrix[1][2];  
float a20=inMatrix[2][0],a21=inMatrix[2][1],a22=inMatrix[2][2];  
float b01=a22_a11-a12_a21;  
float b11=-a22_a10+a12_a20;  
float b21=a21_a10-a11_a20;  
float det=a00_b01+a01_b11+a02_b21;  
return mat3(b01,(-a22_a01+a02_a21),(a12_a01-a02_a11),  
b11,(a22_a00-a02_a20),(-a12_a00+a02_a10),  
b21,(-a21_a00+a01_a20),(a11_a00-a01_a10))/det;  
}  
float toLinearSpace(float color)  
{  
return pow(color,LinearEncodePowerApprox);  
}  
vec3 toLinearSpace(vec3 color)  
{  
return pow(color,vec3(LinearEncodePowerApprox));  
}  
vec4 toLinearSpace(vec4 color)  
{  
return vec4(pow(color.rgb,vec3(LinearEncodePowerApprox)),color.a);  
}  
float toGammaSpace(float color)  
{  
return pow(color,GammaEncodePowerApprox);  
}  
vec3 toGammaSpace(vec3 color)  
{  
return pow(color,vec3(GammaEncodePowerApprox));  
}  
vec4 toGammaSpace(vec4 color)  
{  
return vec4(pow(color.rgb,vec3(GammaEncodePowerApprox)),color.a);  
}  
float square(float value)  
{  
return value_value;  
}  
vec3 square(vec3 value)  
{  
return value_value;  
}  
float pow5(float value) {  
float sq=value_value;  
return sq_sq_value;  
}  
float getLuminance(vec3 color)  
{  
return clamp(dot(color,LuminanceEncodeApprox),0.,1.);  
}  
float getRand(vec2 seed) {  
return fract(sin(dot(seed.xy ,vec2(12.9898,78.233)))_43758.5453);  
}  
float dither(vec2 seed,float varianceAmount) {  
float rand=getRand(seed);  
float normVariance=varianceAmount/255.0;  
float dither=mix(-normVariance,normVariance,rand);  
return dither;  
}  
const float rgbdMaxRange=255.0;  
vec4 toRGBD(vec3 color) {  
float maxRGB=maxEps(max(color.r,max(color.g,color.b)));  
float D =max(rgbdMaxRange/maxRGB,1.);  
D =clamp(floor(D)/255.0,0.,1.);  
vec3 rgb=color.rgb_D;  
rgb=toGammaSpace(rgb);  
return vec4(clamp(rgb,0.,1.),D);  
}  
vec3 fromRGBD(vec4 rgbd) {  
rgbd.rgb=toLinearSpace(rgbd.rgb);  
return rgbd.rgb/rgbd.a;  
}  
vec3 parallaxCorrectNormal( vec3 vertexPos,vec3 origVec,vec3 cubeSize,vec3 cubePos ) {  
vec3 invOrigVec=vec3(1.0,1.0,1.0)/origVec;  
vec3 halfSize=cubeSize_0.5;  
vec3 intersecAtMaxPlane=(cubePos+halfSize-vertexPos)invOrigVec;  
vec3 intersecAtMinPlane=(cubePos-halfSize-vertexPos)invOrigVec;  
vec3 largestIntersec=max(intersecAtMaxPlane,intersecAtMinPlane);  
float distance=min(min(largestIntersec.x,largestIntersec.y),largestIntersec.z);  
vec3 intersectPositionWS=vertexPos+origVecdistance;  
return intersectPositionWS-cubePos;  
}  
uniform vec4 vLightData0;  
uniform vec4 vLightDiffuse0;  
uniform vec4 vLightSpecular0;  
uniform vec4 vLightData1;  
uniform vec4 vLightDiffuse1;  
uniform vec4 vLightSpecular1;  
struct lightingInfo  
{  
vec3 diffuse;  
vec3 specular;  
};  
lightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {  
lightingInfo result;  
vec3 lightVectorW;  
float attenuation=1.0;  
if (lightData.w==0.)  
{  
vec3 direction=lightData.xyz-vPositionW;  
attenuation=max(0.,1.0-length(direction)/range);  
lightVectorW=normalize(direction);  
}  
else  
{  
lightVectorW=normalize(-lightData.xyz);  
}  
float ndl=max(0.,dot(vNormal,lightVectorW));  
result.diffuse=ndldiffuseColor_attenuation;  
vec3 angleW=normalize(viewDirectionW+lightVectorW);  
float specComp=max(0.,dot(vNormal,angleW));  
specComp=pow(specComp,max(1.,glossiness));  
result.specular=specComp_specularColor_attenuation;  
return result;  
}  
lightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float glossiness) {  
lightingInfo result;  
vec3 direction=lightData.xyz-vPositionW;  
vec3 lightVectorW=normalize(direction);  
float attenuation=max(0.,1.0-length(direction)/range);  
float cosAngle=max(0.,dot(lightDirection.xyz,-lightVectorW));  
if (cosAngle\>=lightDirection.w)  
{  
cosAngle=max(0.,pow(cosAngle,lightData.w));  
attenuation\*=cosAngle;  
float ndl=max(0.,dot(vNormal,lightVectorW));  
result.diffuse=ndl_diffuseColor_attenuation;  
vec3 angleW=normalize(viewDirectionW+lightVectorW);  
float specComp=max(0.,dot(vNormal,angleW));  
specComp=pow(specComp,max(1.,glossiness));  
result.specular=specComp_specularColor_attenuation;  
return result;  
}  
result.diffuse=vec3(0.);  
result.specular=vec3(0.);  
return result;  
}  
lightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float glossiness) {  
lightingInfo result;  
float ndl=dot(vNormal,lightData.xyz)_0.5+0.5;  
result.diffuse=mix(groundColor,diffuseColor,ndl);  
vec3 angleW=normalize(viewDirectionW+lightData.xyz);  
float specComp=max(0.,dot(vNormal,angleW));  
specComp=pow(specComp,max(1.,glossiness));  
result.specular=specComp_specularColor;  
return result;  
}  
#define inline  
vec3 computeProjectionTextureDiffuseLighting(sampler2D projectionLightSampler,mat4 textureProjectionMatrix){  
vec4 strq=textureProjectionMatrix_vec4(vPositionW,1.0);  
strq/=strq.w;  
vec3 textureColor=texture(projectionLightSampler,strq.xy).rgb;  
return textureColor;  
}  
 #define CUSTOM\_IMAGEPROCESSINGFUNCTIONS\_DEFINITIONS  
vec4 applyImageProcessing(vec4 result) {  
 #define CUSTOM\_IMAGEPROCESSINGFUNCTIONS\_UPDATERESULT\_ATSTART  
result.rgb=toGammaSpace(result.rgb);  
result.rgb=saturate(result.rgb);  
 #define CUSTOM\_IMAGEPROCESSINGFUNCTIONS\_UPDATERESULT\_ATEND  
return result;  
}  
 #define CUSTOM\_FRAGMENT\_DEFINITIONS  
void main(void) {  
 #define CUSTOM\_FRAGMENT\_MAIN\_BEGIN  
vec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);  
vec4 baseColor=vec4(1.,1.,1.,1.);  
vec3 diffuseColor=vDiffuseColor.rgb;  
float alpha=vDiffuseColor.a;  
vec3 normalW=normalize(vNormalW);  
vec2 uvOffset=vec2(0.0,0.0);  
baseColor.rgb_=vColor.rgb;  
#define CUSTOM\_FRAGMENT\_UPDATE\_DIFFUSE  
vec3 baseAmbientColor=vec3(1.,1.,1.);  
#define CUSTOM\_FRAGMENT\_BEFORE\_LIGHTS  
float glossiness=vSpecularColor.a;  
vec3 specularColor=vSpecularColor.rgb;  
vec3 diffuseBase=vec3(0.,0.,0.);  
lightingInfo info;  
vec3 specularBase=vec3(0.,0.,0.);  
float shadow=1.;  
info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0.rgb,vLightDiffuse0.a,glossiness);  
shadow=1.;  
diffuseBase+=info.diffuse_shadow;  
specularBase+=info.specular_shadow;  
info=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1.rgb,vLightDiffuse1.a,glossiness);  
shadow=1.;  
diffuseBase+=info.diffuse_shadow;  
specularBase+=info.specular_shadow;  
vec4 refractionColor=vec4(0.,0.,0.,1.);  
vec4 reflectionColor=vec4(0.,0.,0.,1.);  
vec3 emissiveColor=vEmissiveColor;  
vec3 finalDiffuse=clamp(diffuseBase_diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)baseColor.rgb;  
vec3 finalSpecular=specularBasespecularColor;  
vec4 color=vec4(finalDiffuse_baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);  
#define CUSTOM\_FRAGMENT\_BEFORE\_FOG  
color.rgb=max(color.rgb,0.);  
color.a\*=visibility;  
#define CUSTOM\_FRAGMENT\_BEFORE\_FRAGCOLOR  
float writeGeometryInfo=color.a\>0.4 ? 1.0 : 0.0;  
glFragData[0]=color;  
glFragColor=color;  
float fragDepth=gl\_FragCoord.z;  
ivec2 fragCoord=ivec2(gl\_FragCoord.xy);  
vec2 lastDepth=texelFetch(oitDepthSampler,fragCoord,0).rg;  
vec4 lastFrontColor=texelFetch(oitFrontColorSampler,fragCoord,0);  
depth.rg=vec2(-MAX\_DEPTH);  
frontColor=lastFrontColor;  
backColor=vec4(0.0);  
float nearestDepth=-lastDepth.x;  
float furthestDepth=lastDepth.y;  
float alphaMultiplier=1.0-lastFrontColor.a;  
if (fragDepth\<nearestDepth || fragDepth\>furthestDepth) {  
return;  
}  
if (fragDepth\>nearestDepth && fragDepth\<furthestDepth) {  
depth.rg=vec2(-fragDepth,fragDepth);  
return;  
}  
if (fragDepth==nearestDepth) {  
frontColor.rgb+=color.rgb_color.a_alphaMultiplier;  
frontColor.a=1.0-alphaMultiplier\*(1.0-color.a);  
} else {  
backColor+=color;  
}  
#define CUSTOM\_FRAGMENT\_MAIN\_END  
}

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 2:31pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/11 "2023-04-28T14:31:23Z")

</div>

The shader compiler crashes because of the double definition of highp vec4 glFragColor;

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 2:37pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/12 "2023-04-28T14:37:53Z")

</div>

It seems you are using a `CustomMaterial`:

```auto
#define SHADER_NAME fragment:custom_2

```

The name “custom\_” is generated by the `CustomMaterial` class.

Also, this shader uses the `distEffectScale` and `jawDistance` uniforms if that helps you find the material in your project. Are you doing any special things in this material, like redefining `isReadyForSubMesh` for example?

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 2:54pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/13 "2023-04-28T14:54:31Z")

</div>

You were too fast. I exchanged that custom material with a standard material and replaced the post. You see now  
#define SHADER\_NAME fragment:default  
without the custom uniforms.

isReadyForSubMesh is not used or overwritten.

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 2:57pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/14 "2023-04-28T14:57:08Z")

</div>

So far, I only see these two non-standard lines after the material is given:

mesh.freezeWorldMatrix();  
mesh.doNotSyncBoundingInfo = true;

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 3:06pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/15 "2023-04-28T15:06:34Z")

</div>

Are some materials frozen? Are you setting a scene performance priority mode other than `BackwardCompatible`?

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 3:15pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/16 "2023-04-28T15:15:07Z")

</div>

Freeze has been used, I turned it off → same crash

No BackwardCompatible and no scene performance priorities.

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 3:23pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/17 "2023-04-28T15:23:28Z")

</div>

Thanks to your inputs, I was able to reproduce the bug!

> **[Babylon.js Playground](https://playground.babylonjs.com/#0T5X2Z%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

This PR will fix the problem:

> <https://github.com/BabylonJS/Babylon.js/pull/13781>
>
> See https://forum.babylonjs.com/t/shader-crash-with-oit/40332/15

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 3:26pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/18 "2023-04-28T15:26:27Z")

</div>

Cool! As we don’t use SSRRenderingPipeline - what can I do now to avoid this issue?

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 3:29pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/19 "2023-04-28T15:29:57Z")

</div>

I used SSR only to enable the pre-pass renderer in the example. I don’t know what enables the pre-pass renderer in your case, but the fix should be the same (at least I hope!).

---

<div class="post-metadata">

**Author:** ![8thdwarf](https://avatars.discourse-cdn.com/v4/letter/8/b487fb/32.png) [@8thdwarf](https://forum.babylonjs.com/u/8thdwarf)\
**Post date:** [April 28, 2023, 3:30pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/20 "2023-04-28T15:30:49Z")

</div>

Ok, so I keep searching or wait for the PR. Thanks!

---

<div class="post-metadata">

**Author:** ![Evgeni\_Popov](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/evgeni_popov/32/4432_2.png) [@Evgeni\_Popov](https://forum.babylonjs.com/u/Evgeni_Popov)\
**Post date:** [April 28, 2023, 3:35pm UTC](https://forum.babylonjs.com/t/shader-crash-with-oit/40332/21 "2023-04-28T15:35:24Z")

</div>

I updated the PG above with the fix:

> **[Babylon.js Playground](https://playground.babylonjs.com/#0T5X2Z%232)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

So, try to copy/paste this code in your project, so that it overrides the default `Material.alpha` getter/setter:

```javascript
Object.defineProperty(BABYLON.Material.prototype, "alpha", {
    get: function () {
        return this._alpha;
    },
    set: function (value) {
        if (this._alpha === value) {
            return;
        }

        const oldValue = this._alpha;
        this._alpha = value;

        // Only call dirty when there is a state change (no alpha / alpha)
        if (oldValue === 1 || value === 1) {
            this.markAsDirty(BABYLON.Material.MiscDirtyFlag + BABYLON.Material.PrePassDirtyFlag);
        }
    },
    enumerable: true,
    configurable: true,
});

```

Put a `console.log` inside the setter to make sure you are using the updated version!

[Next page](https://forum.babylonjs.com/t/shader-crash-with-oit/40332.md?page=2)
