summaryrefslogtreecommitdiff
path: root/VRCSDK3Worlds/Assets/Bakery/ftFarSphereRenderBase.cginc
blob: 2c12619f75bbdb784ac3a23f9a0efac36f855a95 (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
struct appdata
{
    float4 vertex : POSITION;
    float2 uv : TEXCOORD0;
    float3 normal : NORMAL0;
};

struct v2f
{
    float4 vertex : SV_POSITION;
    float2 uv : TEXCOORD0;
    float3 normal : TEXCOORD1;
    float3 worldPos : TEXCOORD2;
};

sampler2D _MainTex;
float4 _MainTex_ST;
//float4 _Color;
//float4x4 cullMatrices[64];
//float cullMatricesCount;

float2 texelOffset;

v2f vert (appdata v)
{
    v2f o;

    o.vertex = mul(unity_ObjectToWorld, v.vertex);
    o.worldPos = o.vertex.xyz;

    o.vertex = mul(UNITY_MATRIX_VP, float4(o.vertex.xyz,1));
    o.vertex.xy += texelOffset * o.vertex.w;

    o.uv = TRANSFORM_TEX(v.uv, _MainTex);

    o.normal = normalize(mul((float3x3)unity_ObjectToWorld, v.normal));

    return o;
}

struct MRT
{
    float4 AlbedoAlpha : SV_Target0;
    float4 Normal : SV_Target1;
};

MRT frag (v2f IN)
{
    /*
    for(int i=0; i<cullMatricesCount; i++)
    {
        float3 w = mul(cullMatrices[i], float4(IN.worldPos,1)).xyz;
        w = abs(w * 2);
        bool outside = (max(max(w.x, w.y), w.z) > 1);
        if (!outside) discard;
    }
    */

    MRT mrt;
    mrt.AlbedoAlpha = tex2D(_MainTex, IN.uv);// * _Color;
#ifdef OPAQUE
    mrt.AlbedoAlpha.a = 1;
#else
    mrt.AlbedoAlpha.a = max(mrt.AlbedoAlpha.a, 1.0f / 255.0f); // 0 is reserved for projClip
#endif
    mrt.Normal = float4(IN.normal * 0.5 + 0.5, 1);

    return mrt;
}