Skip to content

Instantly share code, notes, and snippets.

@maluoi
Last active August 12, 2020 20:10
Show Gist options
  • Save maluoi/3ecd1b87ea664d90f54dd44814f8ac31 to your computer and use it in GitHub Desktop.
Save maluoi/3ecd1b87ea664d90f54dd44814f8ac31 to your computer and use it in GitHub Desktop.
UnlitShadowedWavy.shader
Shader "Unlit/UnlitShadowed Wavy"
{
Properties
{
_MainTex ("Texture", 2D) = "white" {}
_SwaySpeed("Sway Speed", float) = .5
_WorldCoherence("Sway Coherence", float) = 0.1
_WindDirection("Wind Direction", Vector) = (1,1,0,0)
}
SubShader
{
LOD 100
Pass {
Tags{ "RenderType" = "Opaque" "LightMode" = "ForwardBase" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
#pragma shader_feature ___ FERRPUSH_USE_VERTCOLOR_ON
#include "UnityCG.cginc"
#include "Lighting.cginc"
#include "AutoLight.cginc"
#include "/Assets/Ferr/VegetationPusher/Shaders/FerrPushable.cginc"
struct v2f {
float2 uv : TEXCOORD0;
SHADOW_COORDS(1)
float4 pos : SV_POSITION;
};
sampler2D _MainTex;
float _SwaySpeed;
float _WorldCoherence;
float4 _WindDirection;
v2f vert (appdata_base v) {
v2f o;
float4 world = mul(UNITY_MATRIX_M, v.vertex);
float time = (_Time.y + (world.x + world.z) * _WorldCoherence) * _SwaySpeed;
world.xz += cos(time) * _WindDirection;
o.pos = mul(UNITY_MATRIX_VP, world);
o.uv = v.texcoord;
TRANSFER_SHADOW(o)
return o;
}
fixed4 frag (v2f i) : SV_Target {
fixed4 col = tex2D(_MainTex, i.uv);
fixed shadow = SHADOW_ATTENUATION(i);
col.rgb *= lerp(UNITY_LIGHTMODEL_AMBIENT, float3(1,1,1), shadow);
return col;
}
ENDCG
}
Pass
{
Tags{ "LightMode" = "ShadowCaster" }
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster
#pragma shader_feature ___ FERRPUSH_USE_VERTCOLOR_ON
#include "UnityCG.cginc"
#include "/Assets/Ferr/VegetationPusher/Shaders/FerrPushable.cginc"
struct v2f {
V2F_SHADOW_CASTER;
};
float _SwaySpeed;
float _WorldCoherence;
float4 _WindDirection;
v2f vert(appdata_base v) {
v2f o;
float4 world = mul(UNITY_MATRIX_M, v.vertex);
float time = (_Time.y + (world.x + world.z) * _WorldCoherence) * _SwaySpeed;
world.xz += cos(time) * _WindDirection;
o.pos = mul(UNITY_MATRIX_VP, world);
return o;
}
float4 frag(v2f i) : SV_Target {
SHADOW_CASTER_FRAGMENT(i)
}
ENDCG
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment