summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/Bakery/examples/shaders/Baked_Alpha_meta.shader
blob: 14099e2b951187bfca0b224dada1fbfe47ef4546 (plain)
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
Shader "Bakery/Example shader with Alpha Meta Pass"
{
    Properties
    {
        _MainTex ("Albedo", 2D) = "white" { }
        _BumpMap ("Normal map", 2D) = "bump" { }
        [HideInInspector] BAKERY_META_ALPHA_ENABLE ("Enable Bakery alpha meta pass", Float) = 1.0
    }
    SubShader
    {
        Tags {"RenderType"="Transparent"}

        Pass
        {
            CGPROGRAM
            #pragma vertex vs
            #pragma fragment ps
            #include "UnityCG.cginc"

            sampler2D _MainTex, _BumpMap;

            struct pi
            {
                float4 Position : SV_POSITION;
                float2 TexCoords : TEXCOORD0;
                float2 TexCoords2 : TEXCOORD1;
            };

            void vs(in appdata_full IN, out pi OUT)
            {
                OUT.Position = UnityObjectToClipPos(IN.vertex);
                OUT.TexCoords = IN.texcoord.xy;
                OUT.TexCoords2 = IN.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
            }

            float4 ps( in pi IN ) : COLOR
            {
                float4 tex = tex2D(_MainTex, IN.TexCoords);
                float3 lm = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.TexCoords2));
                tex.rgb *= lm;
                float2 alpha2 = cos(abs(frac(IN.TexCoords*10)*2-1));
                float alpha = alpha2.x * alpha2.y;
                clip(alpha-0.5);
                return tex;
            }
            ENDCG
        }

        Pass
        {
            // Alpha map enabled Bakery-specific meta pass

            Name "META_BAKERY"

            Tags {"LightMode"="Meta"}
            Cull Off
            CGPROGRAM

            #include "UnityStandardMeta.cginc"

            // Include Bakery meta pass
            #include "../../BakeryMetaPass.cginc"

            float4 frag_customMeta (v2f_bakeryMeta i): SV_Target
            {
                UnityMetaInput o;
                UNITY_INITIALIZE_OUTPUT(UnityMetaInput, o);

                // Output custom alpha to Bakery
                if (unity_MetaFragmentControl.w)
                {
                    // Calculate custom alpha
                    float2 alpha2 = cos(abs(frac(i.uv*10)*2-1));
                    float alpha = alpha2.x * alpha2.y;

                    // Output
                    return alpha;
                }

                // Regular Unity meta pass
                o.Albedo = tex2D(_MainTex, i.uv);
                return UnityMetaFragment(o);
            }

            // Must use vert_bakerymt vertex shader
            #pragma vertex vert_bakerymt
            #pragma fragment frag_customMeta
            ENDCG
        }
    }
}