Skip to content

Instantly share code, notes, and snippets.

@RPDevJesco
Forked from Split82/Unity Decal Shader
Last active August 16, 2016 08:59
Show Gist options
  • Save RPDevJesco/d34d60cc5d223d1cae2d76a5b75c3d68 to your computer and use it in GitHub Desktop.
Save RPDevJesco/d34d60cc5d223d1cae2d76a5b75c3d68 to your computer and use it in GitHub Desktop.
Shader "Example/Decal"
{
Properties
{
_MainTex("Base (RGB)", 2D) = "white" {}
}
SubShader
{
Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+1" "ForceNoShadowCasting" = "True" }
LOD 200
Offset -1, -1
CGPROGRAM
#pragma surface surf Lambert decal:blend
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
void surf(Input IN, inout SurfaceOutput o)
{
half4 c = tex2D(_MainTex, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Diffuse"
}
@RPDevJesco
Copy link
Author

RPDevJesco commented Aug 16, 2016

Decal

Decal are commonly used to add details to materials at runtime (bullets impacts are for example). They are a great tool especially in deferred rendering as they alter the GBuffer before it is lit, thus saving on performance.

In a typical scenario Decal should probably be rendered after the opaque objects and should not be a shadow caster as seen in the shaderlab “Tags” in the example below.
-Split82

I fixed the errors that were present in the original code (line ending issues and rogue space inbetween - and 1 for the offset).
Changed brackets to better suit my coding style of choice and added a Fallback for Diffuse.

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