lcy
2025-01-02 c867ea92cce28ea0ceb312ef8e2f8e7e0888b1d6
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
// Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
// Upgrade NOTE: replaced '_World2Object' with 'unity_WorldToObject'
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
 
// Copyright Mechanist Games
 
Shader "Effect/Ghost"
{
    Properties
    {
        _NormTex ("Norm Texture", 2D) = "white" { }
        _TintColor ("Tint Color", Color) = (1, 1, 1, 1)
        _TintColor2 ("Tint Color 2", Color) = (1, 1, 1, 1)
    }
    
    Subshader
    {
        
        Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "LightMode" = "Always" }
        
        Pass
        {
            ZWrite On
            Blend SrcAlpha One
            Cull Back
            Lighting Off
            Fog
            {
                Mode Off
            }
            
            CGPROGRAM
            
            #pragma target 3.0
            #pragma vertex vert
            #pragma fragment frag
            
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma exclude_renderers flash
            
            #include "UnityCG.cginc"
            #include "SnxxzCG.cginc"
            
            struct vertexInput
            {
                half4 vertex: POSITION;
                half3 normal: NORMAL;
                half4 tangent: TANGENT;
                half2 texcoord: TEXCOORD0;
            };
            
            struct vertShader
            {
                // basics
                half4 pos: SV_POSITION;
                half2 uv1: TEXCOORD0;
                
                // frag lighting
                half3 nrm: TEXCOORD1;
                half3 tng: TEXCOORD2;
                half3 bin: TEXCOORD3;
                half3 cam: TEXCOORD4;
            };
            // properties
            uniform sampler2D _NormTex;
            uniform half4 _TintColor;
            uniform half4 _TintColor2;
            
            vertShader vert(vertexInput v)
            {
                vertShader o;
                half3 worldVertex = mul(unity_ObjectToWorld, v.vertex).xyz;
                
                // pos and uv tex coord
                o.pos = UnityObjectToClipPos(v.vertex);
                o.uv1 = v.texcoord;
                
                // frag lighting
                o.nrm = normalize(mul(half4(v.normal, 0.0), unity_WorldToObject).xyz);
                o.tng = normalize(mul(unity_ObjectToWorld, half4(v.tangent.xyz, 0.0)).xyz);
                o.bin = normalize(cross(o.nrm, o.tng) * v.tangent.w);
                o.cam = normalize(WorldSpaceViewDir(v.vertex));
                
                return o;
            }
            
            half4 frag(vertShader i): SV_Target
            {
                
                // textures
                half3 bumpmap = tex2D(_NormTex, i.uv1) - half3(0.5, 0.5, 0.5);
                
                // normals
                half3x3 matrixDIR = half3x3(i.tng, i.bin, i.nrm);
                half3 normDIR = normalize(mul(bumpmap, matrixDIR));
                
                // rim
                half rimlight = 1 - max(0, dot(i.cam, normDIR));
                half4 outcolor = lerp(_TintColor, _TintColor2, rimlight * 2);
                outcolor.a = rimlight;
                
                return outcolor;
            }
            
            ENDCG
            
        }
    }
}