View difference between Paste ID: XwmfE9SE and xLmcqPuP
SHOW: | | - or go back to the newest paste.
1
// by Joyce @MinionsArt
2
// https://twitter.com/i/web/status/894576554411470848
3
// http://archive.is/avJyM
4
// https://pastebin.com/xLmcqPuP
5
6
Shader "Toon/Lit Swaying" {
7
	Properties {
8
		_Color ("Main Color", Color) = (0.5,0.5,0.5,1)
9
		_MainTex ("Base (RGB)", 2D) = "white" {}
10
		_Ramp ("Toon Ramp (RGB)", 2D) = "gray" {} 
11
		_Speed ("MoveSpeed", Range(20,50)) = 25 // speed of the swaying
12
			_Rigidness("Rigidness", Range(1,50)) = 25 // lower makes it look more "liquid" higher makes it look rigid
13
		_SwayMax("Sway Max", Range(0, 0.1)) = .005 // how far the swaying goes
14
		_YOffset("Y offset", float) = 0.5// y offset, below this is no animation
15
			
16
	}
17
18
	SubShader {
19
		Tags { "RenderType"="Opaque" "DisableBatching" = "True" }// disable batching lets us keep object space
20
		LOD 200
21
22
		
23
CGPROGRAM
24
#pragma surface surf ToonRamp vertex:vert addshadow // addshadow applies shadow after vertex animation
25
26
sampler2D _Ramp;
27
28
// custom lighting function that uses a texture ramp based
29
// on angle between light direction and normal
30
#pragma lighting ToonRamp exclude_path:prepass
31
inline half4 LightingToonRamp (SurfaceOutput s, half3 lightDir, half atten)
32
{
33
	#ifndef USING_DIRECTIONAL_LIGHT
34
	lightDir = normalize(lightDir);
35
	#endif
36
	
37
	half d = dot (s.Normal, lightDir)*0.5 + 0.5;
38
	half3 ramp = tex2D (_Ramp, float2(d,d)).rgb;
39
	
40
	half4 c;
41
	c.rgb = s.Albedo * _LightColor0.rgb * ramp * (atten * 2);
42
	c.a = 0;
43
	return c;
44
}
45
46
47
sampler2D _MainTex;
48
float4 _Color;
49
50
float _Speed;
51
float _SwayMax;
52
float _YOffset;
53
float _Rigidness;
54
55
56
struct Input {
57
	float2 uv_MainTex : TEXCOORD0;
58
};
59
void vert(inout appdata_full v)// 
60
{
61
	float3 wpos = mul(unity_ObjectToWorld, v.vertex).xyz;// world position
62
	float x = sin(wpos.x / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// x axis movements
63
	float z = sin(wpos.z / _Rigidness + (_Time.x * _Speed)) *(v.vertex.y - _YOffset) * 5;// z axis movements
64
	v.vertex.x += step(0,v.vertex.y - _YOffset) * x * _SwayMax;// apply the movement if the vertex's y above the YOffset
65
	v.vertex.z += step(0,v.vertex.y - _YOffset) * z * _SwayMax;
66
	
67
}
68
69
void surf (Input IN, inout SurfaceOutput o) {
70
	half4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
71
	o.Albedo = c.rgb;
72
	o.Alpha = c.a;
73
}
74
ENDCG
75
76
	} 
77
78
	Fallback "Diffuse"
79
}