Skip to content

Commit ece1217

Browse files
authored
Create LerpColorNearToFarPlane.shader
1 parent 19adf77 commit ece1217

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// source: https://forum.unity3d.com/threads/depth-shader-invert-it.12692/#post-89430
2+
// lerp 2 colors between camera NearClipPlane to FarClipPlane
3+
4+
Shader "UnityCommunity/Debug/LerpColorNearToFarPlane"
5+
{
6+
Properties {
7+
_ColorNear ("Color Near", Color) = (1,0,0,1)
8+
_ColorFar ("Color Far", Color) = (0,1,0,1)
9+
}
10+
SubShader
11+
{
12+
Pass
13+
{
14+
CGPROGRAM
15+
#pragma vertex vert
16+
#pragma fragment frag
17+
#include "UnityCG.cginc"
18+
19+
struct appdata
20+
{
21+
float4 vertex : POSITION;
22+
};
23+
24+
struct v2f
25+
{
26+
float4 pos : SV_POSITION;
27+
float4 color : COLOR;
28+
};
29+
30+
uniform float4 _ColorNear;
31+
uniform float4 _ColorFar;
32+
33+
v2f vert(appdata v)
34+
{
35+
v2f o;
36+
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
37+
float depth;
38+
COMPUTE_EYEDEPTH(depth);
39+
float factor = depth * _ProjectionParams.w;
40+
o.color = lerp(_ColorNear, _ColorFar, factor);
41+
return o;
42+
}
43+
44+
fixed4 frag (v2f i) : SV_Target
45+
{
46+
return i.color;
47+
}
48+
49+
ENDCG
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)