OvertakingLegend/Assets/Amazing Assets/Curved World/Shaders/Templates/Terrain/Details/WavingGrass.txt

878 lines
24 KiB
Plaintext
Raw Permalink Normal View History

2025-03-24 03:08:22 +00:00
//Shader "Hidden/Amazing Assets/Curved World/Nature/Terrain/#BEND_NAME_SMALL# #ID#/Details/WavingDoublePass"
Shader "Hidden/TerrainEngine/Details/WavingDoublePass"
{
Properties {
_WavingTint ("Fade Color", Color) = (0.700000,0.600000,0.500000,0.000000)
_MainTex ("Base (RGB) Alpha (A)", 2D) = "white" { }
_WaveAndDistance ("Wave and distance", Vector) = (12.000000,3.600000,1.000000,1.000000)
_Cutoff ("Cutoff", Float) = 0.500000
}
SubShader {
LOD 200
Tags { "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "RenderType"="CurvedWorld_Grass" "DisableBatching"="true" }
Pass {
Name "FORWARD"
Tags { "LIGHTMODE"="FORWARDBASE" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "RenderType"="CurvedWorld_Grass" "DisableBatching"="true" }
Cull Off
ColorMask RGB
CGPROGRAM
// compile directives
#pragma vertex vert_surf
#pragma fragment frag_surf
#pragma multi_compile_instancing
#pragma multi_compile_fog
#pragma multi_compile_fwdbase
#include "HLSLSupport.cginc"
#define UNITY_INSTANCED_LOD_FADE
#define UNITY_INSTANCED_SH
#define UNITY_INSTANCED_LIGHTMAPSTS
#include "UnityShaderVariables.cginc"
#include "UnityShaderUtilities.cginc"
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "TerrainEngine.cginc"
#define CURVEDWORLD_BEND_TYPE_#BEND_NAME_BIG#
#define CURVEDWORLD_BEND_ID_#ID#
//#define CURVEDWORLD_NORMAL_TRANSFORMATION_ON
#include "../../../../Core/CurvedWorldTransform.cginc"
sampler2D _MainTex;
fixed _Cutoff;
struct Input {
float2 uv_MainTex;
fixed4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
clip (o.Alpha - _Cutoff);
o.Alpha *= IN.color.a;
}
// vertex-to-fragment interpolation data
// no lightmaps:
#ifndef LIGHTMAP_ON
// half-precision fragment shader registers:
#ifdef UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS
#define FOG_COMBINED_WITH_WORLD_POS
struct v2f_surf {
UNITY_POSITION(pos);
float2 pack0 : TEXCOORD0; // _MainTex
float3 worldNormal : TEXCOORD1;
float4 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
#if UNITY_SHOULD_SAMPLE_SH
half3 sh : TEXCOORD3; // SH
#endif
UNITY_LIGHTING_COORDS(4,5)
#if SHADER_TARGET >= 30
float4 lmap : TEXCOORD6;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif
// high-precision fragment shader registers:
#ifndef UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS
struct v2f_surf {
UNITY_POSITION(pos);
float2 pack0 : TEXCOORD0; // _MainTex
float3 worldNormal : TEXCOORD1;
float3 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
#if UNITY_SHOULD_SAMPLE_SH
half3 sh : TEXCOORD3; // SH
#endif
UNITY_FOG_COORDS(4)
UNITY_SHADOW_COORDS(5)
#if SHADER_TARGET >= 30
float4 lmap : TEXCOORD6;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif
#endif
// with lightmaps:
#ifdef LIGHTMAP_ON
// half-precision fragment shader registers:
#ifdef UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS
#define FOG_COMBINED_WITH_WORLD_POS
struct v2f_surf {
UNITY_POSITION(pos);
float2 pack0 : TEXCOORD0; // _MainTex
float3 worldNormal : TEXCOORD1;
float4 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
float4 lmap : TEXCOORD3;
UNITY_LIGHTING_COORDS(4,5)
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif
// high-precision fragment shader registers:
#ifndef UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS
struct v2f_surf {
UNITY_POSITION(pos);
float2 pack0 : TEXCOORD0; // _MainTex
float3 worldNormal : TEXCOORD1;
float3 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
float4 lmap : TEXCOORD3;
UNITY_FOG_COORDS(4)
UNITY_SHADOW_COORDS(5)
#ifdef DIRLIGHTMAP_COMBINED
float3 tSpace0 : TEXCOORD6;
float3 tSpace1 : TEXCOORD7;
float3 tSpace2 : TEXCOORD8;
#endif
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
#endif
#endif
float4 _MainTex_ST;
// vertex shader
v2f_surf vert_surf (appdata_full v) {
UNITY_SETUP_INSTANCE_ID(v);
v2f_surf o;
UNITY_INITIALIZE_OUTPUT(v2f_surf,o);
UNITY_TRANSFER_INSTANCE_ID(v,o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
WavingGrassVert (v);
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
#ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(v.vertex, v.normal, v.tangent)
#else
CURVEDWORLD_TRANSFORM_VERTEX(v.vertex)
#endif
#endif
o.pos = UnityObjectToClipPos(v.vertex);
o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
#if defined(LIGHTMAP_ON) && defined(DIRLIGHTMAP_COMBINED)
fixed3 worldTangent = UnityObjectToWorldDir(v.tangent.xyz);
fixed tangentSign = v.tangent.w * unity_WorldTransformParams.w;
fixed3 worldBinormal = cross(worldNormal, worldTangent) * tangentSign;
#endif
#if defined(LIGHTMAP_ON) && defined(DIRLIGHTMAP_COMBINED) && !defined(UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS)
o.tSpace0 = float4(worldTangent.x, worldBinormal.x, worldNormal.x, worldPos.x);
o.tSpace1 = float4(worldTangent.y, worldBinormal.y, worldNormal.y, worldPos.y);
o.tSpace2 = float4(worldTangent.z, worldBinormal.z, worldNormal.z, worldPos.z);
#endif
o.worldPos.xyz = worldPos;
o.worldNormal = worldNormal;
o.color = v.color;
#ifdef DYNAMICLIGHTMAP_ON
o.lmap.zw = v.texcoord2.xy * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
#endif
#ifdef LIGHTMAP_ON
o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
#endif
// SH/ambient and vertex lights
#ifndef LIGHTMAP_ON
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
o.sh = 0;
// Approximated illumination from non-important point lights
#ifdef VERTEXLIGHT_ON
o.sh += Shade4PointLights (
unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
unity_LightColor[0].rgb, unity_LightColor[1].rgb, unity_LightColor[2].rgb, unity_LightColor[3].rgb,
unity_4LightAtten0, worldPos, worldNormal);
#endif
o.sh = ShadeSHPerVertex (worldNormal, o.sh);
#endif
#endif // !LIGHTMAP_ON
UNITY_TRANSFER_LIGHTING(o,v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader
#ifdef FOG_COMBINED_WITH_TSPACE
UNITY_TRANSFER_FOG_COMBINED_WITH_TSPACE(o,o.pos); // pass fog coordinates to pixel shader
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
UNITY_TRANSFER_FOG_COMBINED_WITH_WORLD_POS(o,o.pos); // pass fog coordinates to pixel shader
#else
UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader
#endif
return o;
}
// fragment shader
fixed4 frag_surf (v2f_surf IN) : SV_Target {
UNITY_SETUP_INSTANCE_ID(IN);
// prepare and unpack data
Input surfIN;
#ifdef FOG_COMBINED_WITH_TSPACE
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
#else
UNITY_EXTRACT_FOG(IN);
#endif
UNITY_INITIALIZE_OUTPUT(Input,surfIN);
surfIN.uv_MainTex.x = 1.0;
surfIN.color.x = 1.0;
surfIN.uv_MainTex = IN.pack0.xy;
float3 worldPos = IN.worldPos.xyz;
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPos));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
surfIN.color = IN.color;
#ifdef UNITY_COMPILER_HLSL
SurfaceOutput o = (SurfaceOutput)0;
#else
SurfaceOutput o;
#endif
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Gloss = 0.0;
fixed3 normalWorldVertex = fixed3(0,0,1);
o.Normal = IN.worldNormal;
normalWorldVertex = IN.worldNormal;
// call surface function
surf (surfIN, o);
// compute lighting & shadowing factor
UNITY_LIGHT_ATTENUATION(atten, IN, worldPos)
fixed4 c = 0;
// Setup lighting environment
UnityGI gi;
UNITY_INITIALIZE_OUTPUT(UnityGI, gi);
gi.indirect.diffuse = 0;
gi.indirect.specular = 0;
gi.light.color = _LightColor0.rgb;
gi.light.dir = lightDir;
// Call GI (lightmaps/SH/reflections) lighting function
UnityGIInput giInput;
UNITY_INITIALIZE_OUTPUT(UnityGIInput, giInput);
giInput.light = gi.light;
giInput.worldPos = worldPos;
giInput.atten = atten;
#if defined(LIGHTMAP_ON) || defined(DYNAMICLIGHTMAP_ON)
giInput.lightmapUV = IN.lmap;
#else
giInput.lightmapUV = 0.0;
#endif
#if UNITY_SHOULD_SAMPLE_SH && !UNITY_SAMPLE_FULL_SH_PER_PIXEL
giInput.ambient = IN.sh;
#else
giInput.ambient.rgb = 0.0;
#endif
giInput.probeHDR[0] = unity_SpecCube0_HDR;
giInput.probeHDR[1] = unity_SpecCube1_HDR;
#if defined(UNITY_SPECCUBE_BLENDING) || defined(UNITY_SPECCUBE_BOX_PROJECTION)
giInput.boxMin[0] = unity_SpecCube0_BoxMin; // .w holds lerp value for blending
#endif
#ifdef UNITY_SPECCUBE_BOX_PROJECTION
giInput.boxMax[0] = unity_SpecCube0_BoxMax;
giInput.probePosition[0] = unity_SpecCube0_ProbePosition;
giInput.boxMax[1] = unity_SpecCube1_BoxMax;
giInput.boxMin[1] = unity_SpecCube1_BoxMin;
giInput.probePosition[1] = unity_SpecCube1_ProbePosition;
#endif
LightingLambert_GI(o, giInput, gi);
// realtime lighting: call lighting function
c += LightingLambert (o, gi);
UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog
UNITY_OPAQUE_ALPHA(c.a);
return c;
}
ENDCG
}
Pass {
Name "FORWARD"
Tags { "LIGHTMODE"="FORWARDADD" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "RenderType"="CurvedWorld_Grass" "DisableBatching"="true" }
ZWrite Off
Cull Off
Blend One One
ColorMask RGB
CGPROGRAM
// compile directives
#pragma vertex vert_surf
#pragma fragment frag_surf
#pragma multi_compile_instancing
#pragma multi_compile_fog
#pragma skip_variants INSTANCING_ON
#pragma multi_compile_fwdadd_fullshadows
#include "HLSLSupport.cginc"
#define UNITY_INSTANCED_LOD_FADE
#define UNITY_INSTANCED_SH
#define UNITY_INSTANCED_LIGHTMAPSTS
#include "UnityShaderVariables.cginc"
#include "UnityShaderUtilities.cginc"
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "TerrainEngine.cginc"
#define CURVEDWORLD_BEND_TYPE_#BEND_NAME_BIG#
#define CURVEDWORLD_BEND_ID_#ID#
//#define CURVEDWORLD_NORMAL_TRANSFORMATION_ON
#include "../../../../Core/CurvedWorldTransform.cginc"
sampler2D _MainTex;
fixed _Cutoff;
struct Input {
float2 uv_MainTex;
fixed4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
clip (o.Alpha - _Cutoff);
o.Alpha *= IN.color.a;
}
// vertex-to-fragment interpolation data
struct v2f_surf {
UNITY_POSITION(pos);
float2 pack0 : TEXCOORD0; // _MainTex
float3 worldNormal : TEXCOORD1;
float3 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
UNITY_LIGHTING_COORDS(3,4)
UNITY_FOG_COORDS(5)
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _MainTex_ST;
// vertex shader
v2f_surf vert_surf (appdata_full v) {
UNITY_SETUP_INSTANCE_ID(v);
v2f_surf o;
UNITY_INITIALIZE_OUTPUT(v2f_surf,o);
UNITY_TRANSFER_INSTANCE_ID(v,o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
WavingGrassVert (v);
#if defined(CURVEDWORLD_IS_INSTALLED) && !defined(CURVEDWORLD_DISABLED_ON)
#ifdef CURVEDWORLD_NORMAL_TRANSFORMATION_ON
CURVEDWORLD_TRANSFORM_VERTEX_AND_NORMAL(v.vertex, v.normal, v.tangent)
#else
CURVEDWORLD_TRANSFORM_VERTEX(v.vertex)
#endif
#endif
o.pos = UnityObjectToClipPos(v.vertex);
o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos.xyz = worldPos;
o.worldNormal = worldNormal;
o.color = v.color;
UNITY_TRANSFER_LIGHTING(o,v.texcoord1.xy); // pass shadow and, possibly, light cookie coordinates to pixel shader
UNITY_TRANSFER_FOG(o,o.pos); // pass fog coordinates to pixel shader
return o;
}
// fragment shader
fixed4 frag_surf (v2f_surf IN) : SV_Target {
UNITY_SETUP_INSTANCE_ID(IN);
// prepare and unpack data
Input surfIN;
#ifdef FOG_COMBINED_WITH_TSPACE
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
#else
UNITY_EXTRACT_FOG(IN);
#endif
UNITY_INITIALIZE_OUTPUT(Input,surfIN);
surfIN.uv_MainTex.x = 1.0;
surfIN.color.x = 1.0;
surfIN.uv_MainTex = IN.pack0.xy;
float3 worldPos = IN.worldPos.xyz;
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPos));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
surfIN.color = IN.color;
#ifdef UNITY_COMPILER_HLSL
SurfaceOutput o = (SurfaceOutput)0;
#else
SurfaceOutput o;
#endif
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Gloss = 0.0;
fixed3 normalWorldVertex = fixed3(0,0,1);
o.Normal = IN.worldNormal;
normalWorldVertex = IN.worldNormal;
// call surface function
surf (surfIN, o);
UNITY_LIGHT_ATTENUATION(atten, IN, worldPos)
fixed4 c = 0;
// Setup lighting environment
UnityGI gi;
UNITY_INITIALIZE_OUTPUT(UnityGI, gi);
gi.indirect.diffuse = 0;
gi.indirect.specular = 0;
gi.light.color = _LightColor0.rgb;
gi.light.dir = lightDir;
gi.light.color *= atten;
c += LightingLambert (o, gi);
c.a = 0.0;
UNITY_APPLY_FOG(_unity_fogCoord, c); // apply fog
UNITY_OPAQUE_ALPHA(c.a);
return c;
}
ENDCG
}
Pass {
Name "ShadowCaster"
Tags { "LIGHTMODE"="SHADOWCASTER" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "SHADOWSUPPORT"="true" "RenderType"="CurvedWorld_Grass" "DisableBatching"="true" }
Cull Off
ColorMask RGB
CGPROGRAM
// compile directives
#pragma vertex vert_surf
#pragma fragment frag_surf
#pragma multi_compile_instancing
#pragma skip_variants FOG_LINEAR FOG_EXP FOG_EXP2
#pragma multi_compile_shadowcaster
#include "HLSLSupport.cginc"
#define UNITY_INSTANCED_LOD_FADE
#define UNITY_INSTANCED_SH
#define UNITY_INSTANCED_LIGHTMAPSTS
#include "UnityShaderVariables.cginc"
#include "UnityShaderUtilities.cginc"
#include "UnityCG.cginc"
#include "Lighting.cginc"
#define INTERNAL_DATA
#define WorldReflectionVector(data,normal) data.worldRefl
#define WorldNormalVector(data,normal) normal
#include "TerrainEngine.cginc"
#define CURVEDWORLD_BEND_TYPE_#BEND_NAME_BIG#
#define CURVEDWORLD_BEND_ID_#ID#
#include "../../../../Core/CurvedWorldTransform.cginc"
sampler2D _MainTex;
fixed _Cutoff;
struct Input {
float2 uv_MainTex;
fixed4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb;
o.Alpha = c.a;
clip (o.Alpha - _Cutoff);
o.Alpha *= IN.color.a;
}
// vertex-to-fragment interpolation data
struct v2f_surf {
V2F_SHADOW_CASTER;
float2 pack0 : TEXCOORD1; // _MainTex
float3 worldPos : TEXCOORD2;
fixed4 color : COLOR0;
UNITY_VERTEX_INPUT_INSTANCE_ID
UNITY_VERTEX_OUTPUT_STEREO
};
float4 _MainTex_ST;
// vertex shader
v2f_surf vert_surf (appdata_full v) {
UNITY_SETUP_INSTANCE_ID(v);
v2f_surf o;
UNITY_INITIALIZE_OUTPUT(v2f_surf,o);
UNITY_TRANSFER_INSTANCE_ID(v,o);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
WavingGrassVert (v);
CURVEDWORLD_TRANSFORM_VERTEX(v.vertex);
o.pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz;
float3 worldNormal = UnityObjectToWorldNormal(v.normal);
o.worldPos.xyz = worldPos;
o.color = v.color;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
return o;
}
// fragment shader
fixed4 frag_surf (v2f_surf IN) : SV_Target {
UNITY_SETUP_INSTANCE_ID(IN);
// prepare and unpack data
Input surfIN;
#ifdef FOG_COMBINED_WITH_TSPACE
UNITY_EXTRACT_FOG_FROM_TSPACE(IN);
#elif defined (FOG_COMBINED_WITH_WORLD_POS)
UNITY_EXTRACT_FOG_FROM_WORLD_POS(IN);
#else
UNITY_EXTRACT_FOG(IN);
#endif
UNITY_INITIALIZE_OUTPUT(Input,surfIN);
surfIN.uv_MainTex.x = 1.0;
surfIN.color.x = 1.0;
surfIN.uv_MainTex = IN.pack0.xy;
float3 worldPos = IN.worldPos.xyz;
#ifndef USING_DIRECTIONAL_LIGHT
fixed3 lightDir = normalize(UnityWorldSpaceLightDir(worldPos));
#else
fixed3 lightDir = _WorldSpaceLightPos0.xyz;
#endif
surfIN.color = IN.color;
#ifdef UNITY_COMPILER_HLSL
SurfaceOutput o = (SurfaceOutput)0;
#else
SurfaceOutput o;
#endif
o.Albedo = 0.0;
o.Emission = 0.0;
o.Specular = 0.0;
o.Alpha = 0.0;
o.Gloss = 0.0;
fixed3 normalWorldVertex = fixed3(0,0,1);
// call surface function
surf (surfIN, o);
SHADOW_CASTER_FRAGMENT(IN)
}
ENDCG
}
}
SubShader {
LOD 200
Tags { "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "RenderType"="CurvedWorld_Grass" }
Pass {
Tags { "LIGHTMODE"="Vertex" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "RenderType"="CurvedWorld_Grass" }
Cull Off
ColorMask RGB
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#pragma multi_compile_fog
#define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
// ES2.0/WebGL can not do loops with non-constant-expression iteration counts :(
#if defined(SHADER_API_GLES)
#define LIGHT_LOOP_LIMIT 8
#else
#define LIGHT_LOOP_LIMIT unity_VertexLightParams.x
#endif
// Some ES3 drivers (e.g. older Adreno) have problems with the light loop
#if defined(SHADER_API_GLES3) && !defined(SHADER_API_DESKTOP) && (defined(SPOT) || defined(POINT))
#define LIGHT_LOOP_ATTRIBUTE UNITY_UNROLL
#else
#define LIGHT_LOOP_ATTRIBUTE
#endif
#define ENABLE_SPECULAR 1
// Compile specialized variants for when positional (point/spot) and spot lights are present
#pragma multi_compile __ POINT SPOT
// Compute illumination from one light, given attenuation
half3 computeLighting (int idx, half3 dirToLight, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half shininess, half atten, inout half3 specColor) {
half NdotL = max(dot(eyeNormal, dirToLight), 0.0);
// diffuse
half3 color = NdotL * diffuseColor.rgb * unity_LightColor[idx].rgb;
return color * atten;
}
// Compute attenuation & illumination from one light
half3 computeOneLight(int idx, float3 eyePosition, half3 eyeNormal, half3 viewDir, half4 diffuseColor, half shininess, inout half3 specColor) {
float3 dirToLight = unity_LightPosition[idx].xyz;
half att = 1.0;
#if defined(POINT) || defined(SPOT)
dirToLight -= eyePosition * unity_LightPosition[idx].w;
// distance attenuation
float distSqr = dot(dirToLight, dirToLight);
att /= (1.0 + unity_LightAtten[idx].z * distSqr);
if (unity_LightPosition[idx].w != 0 && distSqr > unity_LightAtten[idx].w) att = 0.0; // set to 0 if outside of range
distSqr = max(distSqr, 0.000001); // don't produce NaNs if some vertex position overlaps with the light
dirToLight *= rsqrt(distSqr);
#if defined(SPOT)
// spot angle attenuation
half rho = max(dot(dirToLight, unity_SpotDirection[idx].xyz), 0.0);
half spotAtt = (rho - unity_LightAtten[idx].x) * unity_LightAtten[idx].y;
att *= saturate(spotAtt);
#endif
#endif
att *= 0.5; // passed in light colors are 2x brighter than what used to be in FFP
return min (computeLighting (idx, dirToLight, eyeNormal, viewDir, diffuseColor, shininess, att, specColor), 1.0);
}
#define CURVEDWORLD_BEND_TYPE_#BEND_NAME_BIG#
#define CURVEDWORLD_BEND_ID_#ID#
#include "../../../../Core/CurvedWorldTransform.cginc"
// uniforms
int4 unity_VertexLightParams; // x: light count, y: zero, z: one (y/z needed by d3d9 vs loop instruction)
float4 _MainTex_ST;
// vertex shader input data
struct appdata {
float3 pos : POSITION;
float3 normal : NORMAL;
half4 color : COLOR;
float3 uv0 : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
// vertex-to-fragment interpolators
struct v2f {
fixed4 color : COLOR0;
float2 uv0 : TEXCOORD0;
#if USING_FOG
fixed fog : TEXCOORD1;
#endif
float4 pos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
// vertex shader
v2f vert (appdata IN) {
v2f o;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 vPosition = float4(IN.pos, 1);
CURVEDWORLD_TRANSFORM_VERTEX(vPosition);
IN.pos = vPosition.xyz;
half4 color = IN.color;
float3 eyePos = mul (UNITY_MATRIX_MV, float4(IN.pos,1)).xyz;
half3 eyeNormal = normalize (mul ((float3x3)UNITY_MATRIX_IT_MV, IN.normal).xyz);
half3 viewDir = 0.0;
// lighting
half3 lcolor = half4(0,0,0,1).rgb + color.rgb * glstate_lightmodel_ambient.rgb;
half3 specColor = 0.0;
half shininess = 0 * 128.0;
LIGHT_LOOP_ATTRIBUTE for (int il = 0; il < LIGHT_LOOP_LIMIT; ++il) {
lcolor += computeOneLight(il, eyePos, eyeNormal, viewDir, color, shininess, specColor);
}
color.rgb = lcolor.rgb;
color.a = color.a;
o.color = saturate(color);
// compute texture coordinates
o.uv0 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
// fog
#if USING_FOG
float fogCoord = length(eyePos.xyz); // radial fog distance
UNITY_CALC_FOG_FACTOR_RAW(fogCoord);
o.fog = saturate(unityFogFactor);
#endif
// transform position
o.pos = UnityObjectToClipPos(IN.pos);
return o;
}
// textures
sampler2D _MainTex;
fixed _Cutoff;
// fragment shader
fixed4 frag (v2f IN) : SV_Target {
fixed4 col;
fixed4 tex, tmp0, tmp1, tmp2;
// SetTexture #0
tex = tex2D (_MainTex, IN.uv0.xy);
col.rgb = tex * IN.color;
col *= 2;
col.a = tex.a;
// alpha test
if (col.a <= _Cutoff) clip(-1);
// fog
#if USING_FOG
col.rgb = lerp (unity_FogColor.rgb, col.rgb, IN.fog);
#endif
return col;
}
// texenvs
//! TexEnv0: 02010103 01050004 [_MainTex]
ENDCG
}
Pass {
Tags { "LIGHTMODE"="VertexLM" "QUEUE"="Geometry+200" "IGNOREPROJECTOR"="true" "RenderType"="CurvedWorld_Opaque" }
Cull Off
ColorMask RGB
CGPROGRAM
#define FOG_LINEAR_KEYWORD_DECLARED 1
#define FOG_EXP_KEYWORD_DECLARED 1
#define FOG_EXP2_KEYWORD_DECLARED 1
#include "HLSLSupport.cginc"
#define UNITY_INSTANCED_LOD_FADE
#define UNITY_INSTANCED_SH
#define UNITY_INSTANCED_LIGHTMAPSTS
#define UNITY_INSTANCED_RENDERER_BOUNDS
#include "UnityShaderVariables.cginc"
#include "UnityShaderUtilities.cginc"
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#pragma multi_compile_fog
#define USING_FOG (defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2))
#define CURVEDWORLD_BEND_TYPE_#BEND_NAME_BIG#
#define CURVEDWORLD_BEND_ID_#ID#
#include "../../../../Core/CurvedWorldTransform.cginc"
float4 _MainTex_ST;
struct appdata
{
float3 pos : POSITION;
float3 uv1 : TEXCOORD1;
float3 uv0 : TEXCOORD0;
UNITY_VERTEX_INPUT_INSTANCE_ID
};
struct v2f
{
float2 uv0 : TEXCOORD0;
float2 uv1 : TEXCOORD1;
#if USING_FOG
fixed fog : TEXCOORD2;
#endif
float4 pos : SV_POSITION;
UNITY_VERTEX_OUTPUT_STEREO
};
v2f vert(appdata IN)
{
v2f o;
UNITY_SETUP_INSTANCE_ID(IN);
UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
float4 vPosition = float4(IN.pos, 1);
CURVEDWORLD_TRANSFORM_VERTEX(vPosition);
IN.pos = vPosition.xyz;
o.uv0 = IN.uv1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
o.uv1 = IN.uv0.xy * _MainTex_ST.xy + _MainTex_ST.zw;
#if USING_FOG
float3 eyePos = UnityObjectToViewPos(IN.pos);
float fogCoord = length(eyePos.xyz);
UNITY_CALC_FOG_FACTOR_RAW(fogCoord);
o.fog = saturate(unityFogFactor);
#endif
o.pos = UnityObjectToClipPos(IN.pos);
return o;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 col;
fixed4 tex = UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.uv0.xy);
half3 bakedColor = DecodeLightmap(tex);
tex = tex2D(_MainTex, IN.uv1.xy);
col.rgb = tex.rgb * bakedColor;
col.a = 1.0f;
#if USING_FOG
col.rgb = lerp(unity_FogColor.rgb, col.rgb, IN.fog);
#endif
return col;
}
ENDCG
}
}
Fallback Off
}