summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/Bakery/ftFarSphereDilate.shader
blob: 29a8d4284742f0b611a68cf1eb41218e157faafc (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
// 1px dilate

Shader "Hidden/ftFarSphereDilate"
{
    Properties
    {
    }
    SubShader
    {
        // No culling or depth
        Cull Off ZWrite Off ZTest Always

        Pass
        {
            CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"

            struct v2f
            {
                float4 vertex : SV_POSITION;
                float2 uv : TEXCOORD0;
            };

            v2f vert (uint id : SV_VertexID)
            {
                v2f o;
                float4 pos[6];
                pos[0] = float4(-1, -1, 0.5, 1);
                pos[1] = float4(-1,  1, 0.5, 1);
                pos[2] = float4(1,   1, 0.5, 1);

                pos[3] = float4(1,   1, 0.5, 1);
                pos[4] = float4(1,  -1, 0.5, 1);
                pos[5] = float4(-1,  -1, 0.5, 1);

                o.vertex = pos[id];
                o.uv = o.vertex.xy * 0.5f + 0.5f;
                o.uv.y = 1.0f - o.uv.y;
                return o;
            }

            sampler2D _MainTex;
            float _InvCubeSize;

            float4 frag (v2f i) : SV_Target
            {
                float4 c = tex2Dlod(_MainTex, float4(i.uv,0,0));
                if (c.a > 0) return c;

                int dilate = 1;
                for(int y=-dilate; y<=dilate; y++)
                {
                    for(int x=-dilate; x<=dilate; x++)
                    {
                        float4 c2 = tex2Dlod(_MainTex, float4(i.uv + float2(x,y) * _InvCubeSize,0,0));
                        if (c2.a > 0) c = c2;
                    }
                }

                return c;
            }
            ENDCG
        }
    }
}