You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
519 lines
11 KiB
519 lines
11 KiB
Shader "Hidden/Sprite-CameraDepthTexture" {
|
|
|
|
// Use this shader to render a Depth texture for a camera with soft edged Sprites (using camera.RenderWithShader with replacement tag "RenderType")
|
|
// Note the depth is encoded into the pixels RGB not the full RGBA (alpha is needed for blending)
|
|
|
|
Properties {
|
|
_MainTex ("", 2D) = "white" {}
|
|
_Cutoff ("", Float) = 0.5
|
|
_Color ("", Color) = (1,1,1,1)
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="Sprite" }
|
|
Pass {
|
|
Cull Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "CGIncludes/ShaderShared.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_base v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = calculateTextureCoord(v.texcoord);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = calculateTexturePixel(i.uv );
|
|
float alpha = texcol.a*_Color.a;
|
|
clip( alpha - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), alpha);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="SpriteViewSpaceFixedNormal" }
|
|
Pass {
|
|
Cull Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "CGIncludes/ShaderShared.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_base v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = calculateTextureCoord(v.texcoord);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = calculateTexturePixel(i.uv );
|
|
float alpha = texcol.a*_Color.a;
|
|
clip( alpha - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), alpha);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="SpriteModelSpaceFixedNormal" }
|
|
Pass {
|
|
Cull Off
|
|
Blend SrcAlpha OneMinusSrcAlpha
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "CGIncludes/ShaderShared.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_base v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = calculateTextureCoord(v.texcoord);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = calculateTexturePixel(i.uv );
|
|
float alpha = texcol.a*_Color.a;
|
|
clip( alpha - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), alpha);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="Opaque" }
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_base v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TransparentCutout" }
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
uniform float4 _MainTex_ST;
|
|
v2f vert( appdata_base v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
uniform fixed4 _Color;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = tex2D( _MainTex, i.uv );
|
|
clip( texcol.a*_Color.a - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TreeBark" }
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "Lighting.cginc"
|
|
#include "UnityBuiltin3xTreeLibrary.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_full v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TreeVertBark(v);
|
|
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord.xy;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
fixed4 frag( v2f i ) : SV_Target {
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TreeLeaf" }
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "Lighting.cginc"
|
|
#include "UnityBuiltin3xTreeLibrary.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert( appdata_full v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TreeVertLeaf(v);
|
|
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord.xy;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag( v2f i ) : SV_Target {
|
|
half alpha = tex2D(_MainTex, i.uv).a;
|
|
|
|
clip (alpha - _Cutoff);
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TreeOpaque" "DisableBatching"="True" }
|
|
Pass {
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
struct appdata {
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
fixed4 color : COLOR;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
v2f vert( appdata v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TerrainAnimateTree(v.vertex, v.color.w);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TreeTransparentCutout" "DisableBatching"="True" }
|
|
Pass {
|
|
Cull Back
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
struct appdata {
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
fixed4 color : COLOR;
|
|
float4 texcoord : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
v2f vert( appdata v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TerrainAnimateTree(v.vertex, v.color.w);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord.xy;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
half alpha = tex2D(_MainTex, i.uv).a;
|
|
|
|
clip (alpha - _Cutoff);
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
Pass {
|
|
Cull Front
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
struct appdata {
|
|
float4 vertex : POSITION;
|
|
float3 normal : NORMAL;
|
|
fixed4 color : COLOR;
|
|
float4 texcoord : TEXCOORD0;
|
|
UNITY_VERTEX_INPUT_INSTANCE_ID
|
|
};
|
|
v2f vert( appdata v ) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TerrainAnimateTree(v.vertex, v.color.w);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord.xy;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = tex2D( _MainTex, i.uv );
|
|
clip( texcol.a - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="TreeBillboard" }
|
|
Pass {
|
|
Cull Off
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
v2f vert (appdata_tree_billboard v) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv.x = v.texcoord.x;
|
|
o.uv.y = v.texcoord.y > 0;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = tex2D( _MainTex, i.uv );
|
|
clip( texcol.a - 0.001 );
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="GrassBillboard" }
|
|
Pass {
|
|
Cull Off
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
fixed4 color : COLOR;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
v2f vert (appdata_full v) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
WavingGrassBillboardVert (v);
|
|
o.color = v.color;
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord.xy;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = tex2D( _MainTex, i.uv );
|
|
fixed alpha = texcol.a * i.color.a;
|
|
clip( alpha - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
SubShader {
|
|
Tags { "RenderType"="Grass" }
|
|
Pass {
|
|
Cull Off
|
|
CGPROGRAM
|
|
#pragma target 3.0
|
|
#pragma vertex vert
|
|
#pragma fragment frag
|
|
#include "UnityCG.cginc"
|
|
#include "CGIncludes/ShaderMaths.cginc"
|
|
#include "TerrainEngine.cginc"
|
|
struct v2f {
|
|
float4 pos : SV_POSITION;
|
|
fixed4 color : COLOR;
|
|
float2 uv : TEXCOORD0;
|
|
float depth : TEXCOORD1;
|
|
UNITY_VERTEX_OUTPUT_STEREO
|
|
};
|
|
|
|
v2f vert (appdata_full v) {
|
|
v2f o;
|
|
UNITY_SETUP_INSTANCE_ID(v);
|
|
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
|
|
WavingGrassVert (v);
|
|
o.color = v.color;
|
|
o.pos = UnityObjectToClipPos(v.vertex);
|
|
o.uv = v.texcoord;
|
|
o.depth = COMPUTE_DEPTH_01;
|
|
return o;
|
|
}
|
|
uniform sampler2D _MainTex;
|
|
uniform fixed _Cutoff;
|
|
fixed4 frag(v2f i) : SV_Target {
|
|
fixed4 texcol = tex2D( _MainTex, i.uv );
|
|
fixed alpha = texcol.a * i.color.a;
|
|
clip( alpha - _Cutoff );
|
|
return fixed4(EncodeFloatRGB (i.depth), 1);
|
|
}
|
|
ENDCG
|
|
}
|
|
}
|
|
|
|
Fallback Off
|
|
}
|