hwj35
2025-01-07 a3a4a858a80724140e36648e9d75f16366cf5ae0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
// Copyright Mechanist Games
 
Shader "Environment/Flag"
{
    Properties
    {
        _MainTex ("Color Texture", 2D) = "white" { }
        
        _WindSpd ("Wind Speed (25)", Float) = 25
        _WindAmt ("Wind Amount (1)", Float) = 1
        _WindStr ("Wind Distance (0.2)", Float) = 0.2
        _Side ("Sideways Offset", Range(0, 2)) = 1
        
        _RippSpd ("Ripple Speed", Float) = 100
        _RippAmt ("Ripple Amount (4.0)", Float) = 4
        _RippStr ("Ripple Distance (0.1)", Float) = 0.1
        _RippBrt ("Ripple Brightness", Range(0.2, 2)) = 1
        
        _ClothVector ("Cloth Vector", Vector) = (1, 1, 1, 1)
        
        _TransparencyLM ("Lightmap Transparency", 2D) = "black" { }
    }
    
    Subshader
    {
        LOD 100
        
        Tags
        { "Queue" = "Geometry"
            // "RenderType" = "Opaque" "IgnoreProjector" = "True" "LightMode" = "Always"
        }
        
        Pass
        {
            Cull Back
            Lighting Off
            //Fog{ Mode Off }
            
            CGPROGRAM
            
            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment frag
            
            #pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
            #pragma multi_compile QUALITY_LOW QUALITY_MED QUALITY_HGH
            
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma exclude_renderers flash
            #pragma multi_compile_fog
            
            #include "UnityCG.cginc"
            #include "SnxxzCG.cginc"
            
            struct VertInput
            {
                half4 vertex: POSITION;
                half3 normal: NORMAL;
                half4 color: COLOR;
                half2 texcoord0: TEXCOORD0;
                half2 texcoord1: TEXCOORD1;
            };
            
            struct vertShader
            {
                half4 pos: SV_POSITION;
                half2 uv1: TEXCOORD0;
                half2 uv2: TEXCOORD1;
                fixed shn: TEXCOORD2;
                UNITY_FOG_COORDS(n)
            };
            
            // resources
            uniform sampler2D _MainTex;
            
            // properties
            uniform float _WindSpd;
            uniform float _WindAmt;
            uniform float _WindStr;
            uniform float _RippSpd;
            uniform float _RippAmt;
            uniform float _RippStr;
            uniform float _RippBrt;
            uniform float _Side;
            uniform float3 _ClothVector;
            
            vertShader vert(VertInput v)
            {
                vertShader o;
                float3 worldVertex = mul(unity_ObjectToWorld, v.vertex).xyz;
                
                // wind
                float Coef = _WindSpd * _Time.x + worldVertex.y * _WindAmt + (worldVertex.x + worldVertex.z) * _Side;
                float2 clothWind = float2(sin(Coef), cos(Coef)) * v.color.a * _WindStr;
                
                // rippling
                Coef = _RippSpd * _Time.x + worldVertex.y * _RippAmt - (worldVertex.x + worldVertex.z) * _Side;
                float2 clothRipp = float2(sin(Coef), cos(Coef)) * v.color.a * _RippStr;
                
                // apply animations
                float2 clothMove = clothWind + clothRipp;
                float3 clothTotal = float3(clothMove.x, clothMove.x, clothMove.y) * _ClothVector;
                v.vertex.xyz += clothTotal;
                
                // ripple shine
                o.shn = _RippBrt * smoothstep(-0.2, 0.2, clothRipp.x + clothRipp.y);
                
                // pos and uv tex coord
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv1 = v.texcoord0;
                o.uv2 = inlineLightmapTransform(v.texcoord1);
                
                UNITY_TRANSFER_FOG(o, o.pos);
                
                return o;
            }
            
            fixed4 frag(vertShader i): SV_Target
            {
                
                fixed3 lightmap = inlineLightmapBasic(i.uv2);
                fixed4 baseTex = tex2D(_MainTex, i.uv1);
                
                fixed3 outcolor = baseTex.rgb;
                outcolor *= lightmap;
                outcolor *= 0.8 + i.shn * baseTex.a;
                
                UNITY_APPLY_FOG(i.fogCoord, outcolor);
                
                return float4(outcolor.rgb, 1);
            }
            ENDCG
            
        }
    }
}