Files
CartoonRPG/Assets/StixGames/GrassShader/Camera-DepthNormalTexture.shader

441 lines
9.2 KiB
Plaintext
Raw Normal View History

2025-06-05 22:59:18 +01:00
Shader "Hidden/Camera-DepthNormalTexture" {
Properties {
_MainTex ("", 2D) = "white" {}
_Cutoff ("", Float) = 0.5
_Color ("", Color) = (1,1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 nz : TEXCOORD0;
};
v2f vert( appdata_base v ) {
v2f o;
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
half4 frag(v2f i) : SV_Target {
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TransparentCutout" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
uniform float4 _MainTex_ST;
v2f vert( appdata_base v ) {
v2f o;
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = TRANSFORM_TEX(v.texcoord, _MainTex);
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
uniform half4 _Color;
half4 frag(v2f i) : SV_Target {
half4 texcol = tex2D( _MainTex, i.uv );
clip( texcol.a*_Color.a - _Cutoff );
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TreeBark" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityBuiltin3xTreeLibrary.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
v2f vert( appdata_full v ) {
v2f o;
TreeVertBark(v);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord.xy;
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
half4 frag( v2f i ) : SV_Target {
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TreeLeaf" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "UnityBuiltin3xTreeLibrary.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
v2f vert( appdata_full v ) {
v2f o;
TreeVertLeaf(v);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord.xy;
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
half4 frag( v2f i ) : SV_Target {
half alpha = tex2D(_MainTex, i.uv).a;
clip (alpha - _Cutoff);
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TreeOpaque" "DisableBatching"="True" }
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
float4 nz : TEXCOORD0;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
};
v2f vert( appdata v ) {
v2f o;
TerrainAnimateTree(v.vertex, v.color.w);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
half4 frag(v2f i) : SV_Target {
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TreeTransparentCutout" "DisableBatching"="True" }
Pass {
Cull Back
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
float4 texcoord : TEXCOORD0;
};
v2f vert( appdata v ) {
v2f o;
TerrainAnimateTree(v.vertex, v.color.w);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord.xy;
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
half4 frag(v2f i) : SV_Target {
half alpha = tex2D(_MainTex, i.uv).a;
clip (alpha - _Cutoff);
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
Pass {
Cull Front
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
float4 texcoord : TEXCOORD0;
};
v2f vert( appdata v ) {
v2f o;
TerrainAnimateTree(v.vertex, v.color.w);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord.xy;
o.nz.xyz = -COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
half4 frag(v2f i) : SV_Target {
half4 texcol = tex2D( _MainTex, i.uv );
clip( texcol.a - _Cutoff );
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="TreeBillboard" }
Pass {
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
v2f vert (appdata_tree_billboard v) {
v2f o;
TerrainBillboardTree(v.vertex, v.texcoord1.xy, v.texcoord.y);
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv.x = v.texcoord.x;
o.uv.y = v.texcoord.y > 0;
o.nz.xyz = float3(0,0,1);
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
half4 frag(v2f i) : SV_Target {
half4 texcol = tex2D( _MainTex, i.uv );
clip( texcol.a - 0.001 );
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="GrassBillboard" }
Pass {
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
half4 color : COLOR;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
v2f vert (appdata_full v) {
v2f o;
WavingGrassBillboardVert (v);
o.color = v.color;
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord.xy;
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
half4 frag(v2f i) : SV_Target {
half4 texcol = tex2D( _MainTex, i.uv );
half alpha = texcol.a * i.color.a;
clip( alpha - _Cutoff );
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader {
Tags { "RenderType"="Grass" }
Pass {
Cull Off
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
#include "TerrainEngine.cginc"
struct v2f {
float4 pos : SV_POSITION;
half4 color : COLOR;
float2 uv : TEXCOORD0;
float4 nz : TEXCOORD1;
};
v2f vert (appdata_full v) {
v2f o;
WavingGrassVert (v);
o.color = v.color;
#if UNITY_VERSION < 540
o.pos = UnityObjectToClipPos(v.vertex);
#else
o.pos = UnityObjectToClipPos(v.vertex);
#endif
o.uv = v.texcoord;
o.nz.xyz = COMPUTE_VIEW_NORMAL;
o.nz.w = COMPUTE_DEPTH_01;
return o;
}
uniform sampler2D _MainTex;
uniform half _Cutoff;
half4 frag(v2f i) : SV_Target {
half4 texcol = tex2D( _MainTex, i.uv );
half alpha = texcol.a * i.color.a;
clip( alpha - _Cutoff );
return EncodeDepthNormal (i.nz.w, i.nz.xyz);
}
ENDCG
}
}
SubShader{
Tags{ "RenderType" = "StixGamesGrass" }
LOD 1000
Pass
{
Cull Off
CGPROGRAM
#define RENDER_NORMAL_DEPTH
#pragma target 4.6
#pragma vertex vert
#pragma hull hullShader
#pragma domain domainShader
#pragma geometry geom
#pragma fragment frag
#pragma multi_compile_fog
#pragma multi_compile_fwdbase
// ================= Shader_feature block start =================
#pragma shader_feature SIMPLE_GRASS ONE_GRASS_TYPE TWO_GRASS_TYPES THREE_GRASS_TYPES FOUR_GRASS_TYPES
#pragma shader_feature GRASS_UNLIT_LIGHTING GRASS_UNSHADED_LIGHTING GRASS_PBR_INVERTED_LIGHTING GRASS_PBR_LIGHTING
#pragma shader_feature __ UNIFORM_DENSITY VERTEX_DENSITY
#pragma shader_feature __ GRASS_HEIGHT_SMOOTHING
#pragma shader_feature __ GRASS_WIDTH_SMOOTHING
#pragma shader_feature __ GRASS_ALPHA_SMOOTHING
#pragma shader_feature __ GRASS_OBJECT_MODE
#pragma shader_feature __ GRASS_TOP_VIEW_COMPENSATION
#pragma shader_feature __ GRASS_FOLLOW_SURFACE_NORMAL
#pragma shader_feature __ GRASS_USE_TEXTURE_ATLAS
#pragma shader_feature __ GRASS_IGNORE_GI_SPECULAR
#pragma shader_feature __ GRASS_RANDOM_DIR
#pragma shader_feature __ GRASS_CALC_GLOBAL_WIND
#pragma multi_compile __ GRASS_RENDERTEXTURE_INTERACTION
// ================= Shader_feature block end =================
#include "GrassIncludes.hlsl"
ENDCG
}
}
Fallback Off
}