summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/Editor/x64/Bakery/ftChecker.shader
blob: 4a8192965a5493be9110f313676d3e88fe239d5c (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
Shader "Hidden/ftChecker"
{
	Properties
	{
		_MainTex ("Texture", 2D) = "white" {}
	}

    SubShader {

        Tags { "RenderType"="Opaque" }
        LOD 200

        CGPROGRAM
        // Physically based Standard lighting model, and enable shadows on all light types
        #pragma surface surf Standard vertex:vert noinstancing

        // Use shader model 3.0 target, to get nicer looking lighting
        #pragma target 3.0

        sampler2D _MainTex;
        float bakeryLightmapSize;
        float3 bakeryLightmapID;

        struct Input {
            float2 texcoord1;
            float3 worldPos;
        };

        half _Glossiness;
        half _Metallic;
        fixed4 _Color;

        float2 pri( in float2 x )
        {
            // see https://www.shadertoy.com/view/MtffWs
            float2 h = frac(x/2.0)-0.5;
            return x*0.5 + h*(1.0-2.0*abs(h));
        }

        float2 tri( in float2 x )
        {
            float2 h = frac(x/2.0)-0.5;
            return 1.0-2.0*abs(h);
        }

        struct vinput
        {
            float4 vertex : POSITION;
            float2 texcoord1 : TEXCOORD1;
            float2 texcoord2 : TEXCOORD2;
            float3 normal : NORMAL0;
            float2 texcoord : TEXCOORD0;
            float4 tangent : TANGENT;
        };

        void vert (inout vinput v, out Input o)
        {
            UNITY_INITIALIZE_OUTPUT(Input,o);
            o.texcoord1 = v.texcoord1 * unity_LightmapST.xy + unity_LightmapST.zw;
        }

        void surf (Input IN, inout SurfaceOutputStandard o) {
            o.Albedo = 0;
            o.Smoothness = 0;

            //float width, height;
            //unity_Lightmap.GetDimensions(width, height);
            //float2 resolution = float2(width, height);

            // Filtered checker from https://www.shadertoy.com/view/llffWs
            float2 uv = IN.texcoord1 * bakeryLightmapSize * 0.5f;
            float2 uvDx = ddx(uv);
            float2 uvDy = ddy(uv);

            float2 w = max(abs(uvDx), abs(uvDy)) + 0.01;   // filter kernel
            float2 i = (tri(uv+0.5*w)-tri(uv-0.5*w))/w;    // analytical integral (box filter)
            float checker = 0.5 - 0.5*i.x*i.y;              // xor pattern

            float3 color = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, IN.texcoord1));
            color = lerp(saturate(color), checker * bakeryLightmapID, 0.5f);

            o.Emission = color;
        }
        ENDCG
    }
    FallBack "Diffuse"
}