Skip to content

Instantly share code, notes, and snippets.

@aobond2
Last active October 1, 2021 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aobond2/0cc8e78d2c913deb4c1dea33694c7c2e to your computer and use it in GitHub Desktop.
Save aobond2/0cc8e78d2c913deb4c1dea33694c7c2e to your computer and use it in GitHub Desktop.
Cube shader
Shader "Custom/ObjectDiffuseStencil" {
Properties {
_Color("Color", Color) = (1,1,1,1)
_myDiffuse ("Diffuse Texture", 2D) = "white" {}
_myBump ("Bump Texture", 2D) = "bump" {}
_mySlider ("Bump Amount", Range(0,10)) = 1
_SRef("Stencil Ref", Float) = 1
[Enum(UnityEngine.Rendering.CompareFunction)] _SComp("Stencil Comp", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _SOp("Stencil Op", Float) = 2
}
SubShader {
Stencil {
Ref [_SRef]
Comp [_SComp]
Pass [SOp]
}
CGPROGRAM
#pragma surface surf Lambert
sampler2D _myDiffuse;
sampler2D _myBump;
half _mySlider;
float4 _Color;
struct Input {
float2 uv_myDiffuse;
float2 uv_myBump;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_myDiffuse, IN.uv_myDiffuse).rgb * _Color.rgb;
o.Normal = UnpackNormal(tex2D(_myBump, IN.uv_myBump));
o.Normal *= float3(_mySlider, _mySlider, 1);
}
ENDCG
}
Fallback "Diffuse"
}
Shader "Custom/StencilQuad"{
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_SRef("Stencil Ref", Float) = 1
[Enum(UnityEngine.Rendering.CompareFunction)] _SComp("Stencil Comp", Float) = 8
[Enum(UnityEngine.Rendering.StencilOp)] _SOp("Stencil Op", Float) = 2
}
SubShader {
Tags {"Queue" = "Geometry-1"}
ZWrite off
ColorMask 0
Stencil {
Ref [_SRef]
Comp [_SComp]
Pass [_SOp]
}
CGPROGRAM
#pragma surface surf Lambert
sampler2D _myDiffuse;
struct Input {
float2 uv_myDiffuse;
};
void surf(Input IN, inout SurfaceOutput o) {
o.Albedo = tex2D(_myDiffuse, IN.uv_myDiffuse).rgb;
}
ENDCG
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment