Skip to content

Instantly share code, notes, and snippets.

@8bitniksis
Created May 2, 2024 20:28
Show Gist options
  • Save 8bitniksis/57da0aa2c8ea2656a39d73907998afc2 to your computer and use it in GitHub Desktop.
Save 8bitniksis/57da0aa2c8ea2656a39d73907998afc2 to your computer and use it in GitHub Desktop.
Shader which fixed issues with standard object if apply fade render query
Shader "Custom/Transparency "
{
Properties
{
_MainTex ("Base (RGB)", 2D) = "white" {}
_Color ("Color", Color) = (1,1,1)
}
SubShader
{
CGPROGRAM
#pragma surface surf Lambert noforwardadd
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
float4 screenPos;
};
float4 _Color;
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb * _Color;
float4x4 thresholdMatrix =
{ 1.0 / 17.0, 9.0 / 17.0, 3.0 / 17.0, 11.0 / 17.0,
13.0 / 17.0, 5.0 / 17.0, 15.0 / 17.0, 7.0 / 17.0,
4.0 / 17.0, 12.0 / 17.0, 2.0 / 17.0, 10.0 / 17.0,
16.0 / 17.0, 8.0 / 17.0, 14.0 / 17.0, 6.0 / 17.0
};
float4x4 _RowAccess = { 1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1 };
float2 pos = IN.screenPos.xy / IN.screenPos.w;
pos *= _ScreenParams.xy; // pixel position
clip(_Color.a - thresholdMatrix[fmod(pos.x, 4)] * _RowAccess[fmod(pos.y, 4)]);
}
ENDCG
}
Fallback "Diffuse"
}
@8bitniksis
Copy link
Author

Probably implement dither in standard Lit shader 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment