Created
January 8, 2015 13:31
-
-
Save aras-p/95445a81e080acdd1fc6 to your computer and use it in GitHub Desktop.
View space Z shader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shader "Aaa" { | |
SubShader { | |
Cull Off ZTest Always ZWrite Off | |
Blend SrcAlpha OneMinusSrcAlpha | |
Pass { | |
CGPROGRAM | |
#pragma vertex vert | |
#pragma fragment frag | |
#include "UnityCG.cginc" | |
struct appdata_t { | |
float4 vertex : POSITION; | |
}; | |
struct v2f { | |
float4 vertex : SV_POSITION; | |
float z : TEXCOORD0; | |
}; | |
v2f vert (appdata_t v) | |
{ | |
v2f o; | |
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); | |
// view space position | |
float3 viewPos = mul(UNITY_MATRIX_MV, v.vertex).xyz; | |
// o.z will be zero at camera, positive values towards camera, negative values into view | |
o.z = viewPos.z; | |
return o; | |
} | |
fixed4 frag (v2f i) : SV_Target | |
{ | |
half alpha = -i.z * 0.1; | |
return fixed4(1,1,1,alpha); | |
} | |
ENDCG | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment