summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Pro/Includes/CGI_PoiPanosphere.cginc
blob: 7986c320b9adc327a8b6f8ce30c9a85e4359874e (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
#ifndef PANOSPHERE
    #define PANOSPHERE
    
    float _PanoEmission;
    float _PanoBlend;
    float4 _PanosphereColor;
    float3 _PanospherePan;
    float _PanoToggle;
    float _PanoCubeMapToggle;
    float _PanoInfiniteStereoToggle;
    
    float3 panoColor;
    float panoMask;
    
    #if defined(PROP_PANOSPHERETEXTURE) || !defined(OPTIMIZER_ENABLED)
        sampler2D _PanosphereTexture; float4 _PanosphereTexture_ST;
    #endif
    #if defined(PROP_PANOCUBEMAP) || !defined(OPTIMIZER_ENABLED)
        samplerCUBE _PanoCubeMap; half4 _PanoCubeMap_HDR;
    #endif
    #if defined(PROP_PANOMASK) || !defined(OPTIMIZER_ENABLED)
        POI_TEXTURE_NOSAMPLER(_PanoMask);
    #endif
    
    float2 projectIt(float3 coords)
    {
        float3 normalizedCoords = normalize(coords);
        float latitude = acos(normalizedCoords.y);
        float longitude = atan2(normalizedCoords.z, normalizedCoords.x);
        float2 sphereCoords = float2(longitude + _Time.y * _PanospherePan.x, latitude + _Time.y * _PanospherePan.y) * float2(1.0 / UNITY_PI, 1.0 / UNITY_PI);
        sphereCoords = float2(1.0, 1.0) - sphereCoords;
        return(sphereCoords + float4(0, 1 - unity_StereoEyeIndex, 1, 1.0).xy) * float4(0, 1 - unity_StereoEyeIndex, 1, 1.0).zw;
    }
    
    void applyPanosphereColor(inout float4 albedo, inout float3 panosphereEmission)
    {
        #if defined(PROP_PANOMASK) || !defined(OPTIMIZER_ENABLED)
            panoMask = POI2D_SAMPLER_PAN(_PanoMask, _MainTex, poiMesh.uv[_PanoMaskUV], _PanoMaskPan);
        #else
            panoMask = 1;
        #endif
        #ifdef POI_BLACKLIGHT
            if (_BlackLightMaskPanosphere != 4)
            {
                panoMask *= blackLightMask[_BlackLightMaskPanosphere];
            }
        #endif
        
        UNITY_BRANCH
        if(_PanoCubeMapToggle)
        {
            #if defined(PROP_PANOCUBEMAP) || !defined(OPTIMIZER_ENABLED)
                float3 cubeUV = mul(poiRotationMatrixFromAngles(_PanospherePan.xyz * _Time.y), float4(-poiCam.viewDir, 1));
                half4 cubemap = texCUBE(_PanoCubeMap, cubeUV);
                panoColor = DecodeHDR(cubemap, _PanoCubeMap_HDR) * _PanosphereColor.rgb;
            #else
                panoColor = _PanosphereColor.rgb;
            #endif
        }
        else
        {
            float2 uv = projectIt(normalize(lerp(getCameraPosition().xyz, poiCam.worldPos.xyz, _PanoInfiniteStereoToggle) - poiMesh.worldPos.xyz) * - 1);
            
            float2 ddxuv = ddx(uv);
            float2 ddyuv = ddy(uv);
            if(any(fwidth(uv) > .5))
            {
                ddxuv = ddyuv = 0.001;
            }
            #if defined(PROP_PANOSPHERETEXTURE) || !defined(OPTIMIZER_ENABLED)
                panoColor = tex2D(_PanosphereTexture, TRANSFORM_TEX(uv, _PanosphereTexture), ddxuv, ddyuv).rgb * _PanosphereColor.rgb;
            #else
                panoColor = _PanosphereColor.rgb;
            #endif
        }
        panosphereEmission = panoColor * _PanoBlend * panoMask * _PanoEmission;
        albedo.rgb = lerp(albedo.rgb, panoColor, _PanoBlend * .9999999 * panoMask);
    }
    
#endif