summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/Avatars/Auri/materials/OptimizedShaders/body/Includes/CGI_PoiWireframe.cginc
blob: 49c602c05a0eaee0853f52993f59d0813eb8c09d (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#ifndef POI_WIREFRAME
    #define POI_WIREFRAME
    
    UNITY_DECLARE_TEX2D_NOSAMPLER(_WireframeTexture); float4 _WireframeTexture_ST;
    float2 _WireframeTexturePan;
    float _WireframeSmoothing;
    float _WireframeThickness;
    float4 _WireframeColor;
    float _WireframeAlpha;
    float _WireframeEnable;
    float _WireframeWaveEnabled;
    float _WireframeWaveDensity;
    float _WireframeWaveSpeed;
    float _WireframeEdgeOpacity;
    float _WireframeFaceOpacity;
    half _WireframeEmissionAlpha;
    float _WireframeEmissionStrength;
    float _WireframeQuad;
    float _WireframeUV;
    
    #ifndef POI_SHADOW
        void applyWireframe(inout float3 wireframeEmission, inout float4 albedo)
        {
            
            if (_WireframeEnable)
            {
                float4 colorMap = UNITY_SAMPLE_TEX2D_SAMPLER(_WireframeTexture, _MainTex, TRANSFORM_TEX(poiMesh.uv[_WireframeUV], _WireframeTexture) + _Time.x * _WireframeTexturePan);
                float size = _WireframeThickness;
                half3 width = abs(ddx(poiMesh.barycentricCoordinates)) + abs(ddy(poiMesh.barycentricCoordinates));
                half3 eF = smoothstep(0, width * size, poiMesh.barycentricCoordinates);
                half minBary = size > 0 ? min(min(eF.x, eF.y), eF.z): 1;
                
                float4 wireframeColor = _WireframeColor * colorMap;

                albedo.a *= lerp(_WireframeEdgeOpacity, _WireframeFaceOpacity, minBary);
                albedo.rgb = lerp(lerp(albedo.rgb, wireframeColor.rgb, wireframeColor.a), albedo.rgb, minBary);
                wireframeEmission = wireframeColor.rgb * _WireframeEmissionStrength * (1 - minBary) * _WireframeColor.a;
            }
        }
        
        [maxvertexcount(3)]
        void wireframeGeom(triangle v2f IN[3], inout TriangleStream < v2f > tristream)
        {
            
            if(_WireframeQuad)
            {
                float e1 = length(IN[0].localPos - IN[1].localPos);
                float e2 = length(IN[1].localPos - IN[2].localPos);
                float e3 = length(IN[2].localPos - IN[0].localPos);
                
                float3 quad = 0;
                if(e1 > e2 && e1 > e3)
                    quad.y = 1.;
                else if(e2 > e3 && e2 > e1)
                    quad.x = 1;
                else
                quad.z = 1;
                
                IN[0].barycentricCoordinates = fixed3(1, 0, 0) + quad;
                IN[1].barycentricCoordinates = fixed3(0, 0, 1) + quad;
                IN[2].barycentricCoordinates = fixed3(0, 1, 0) + quad;
            }
            else
            {
                IN[0].barycentricCoordinates = fixed3(1, 0, 0);
                IN[1].barycentricCoordinates = fixed3(0, 1, 0);
                IN[2].barycentricCoordinates = fixed3(0, 0, 1);
            }
            
            
            
            tristream.Append(IN[0]);
            tristream.Append(IN[1]);
            tristream.Append(IN[2]);
        }
    #else
        
        float applyShadowWireframe(float2 uv, float3 barycentricCoordinates, float3 normal, float3 worldPos)
        {
            
            if(_WireframeEnable)
            {
                float wireframeFadeAlpha = _WireframeAlpha;
                float3 finalWireframeColor = 0;
                
                float3 barys;
                barys.xy = barycentricCoordinates;
                barys.z = 1 - barys.x - barys.y;
                float3 deltas = fwidth(barys);
                float3 smoothing = deltas * _WireframeSmoothing;
                float wireframeThickness = _WireframeThickness;
                float3 thickness = deltas * wireframeThickness;
                barys = smoothstep(thickness, thickness + smoothing, barys);
                float minBary = min(barys.x, min(barys.y, barys.z));
                
                return lerp(_WireframeEdgeOpacity, _WireframeFaceOpacity, minBary);
            }
        }
        
        [maxvertexcount(3)]
        void wireframeGeom(triangle V2FShadow IN[3], inout TriangleStream < V2FShadow > tristream)
        {
            IN[0].barycentricCoordinates = fixed3(1, 0, 0);
            IN[1].barycentricCoordinates = fixed3(0, 1, 0);
            IN[2].barycentricCoordinates = fixed3(0, 0, 1);
            tristream.Append(IN[0]);
            tristream.Append(IN[1]);
            tristream.Append(IN[2]);
        }
    #endif
#endif