summaryrefslogtreecommitdiff
path: root/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc
diff options
context:
space:
mode:
authortylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
committertylermurphy534 <tylermurphy534@gmail.com>2022-11-06 15:12:42 -0500
commiteb84bb298d2b95aec7b2ae12cbf25ac64f25379a (patch)
treeefd616a157df06ab661c6d56651853431ac6b08b /VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc
downloadunityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.gz
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.tar.bz2
unityprojects-eb84bb298d2b95aec7b2ae12cbf25ac64f25379a.zip
move to self host
Diffstat (limited to 'VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc')
-rw-r--r--VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc111
1 files changed, 111 insertions, 0 deletions
diff --git a/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc
new file mode 100644
index 00000000..f8c75c53
--- /dev/null
+++ b/VRCSDK3AvatarsLegacy/Assets/_PoiyomiShaders/Shaders/Includes/CGI_PoiWireframe.cginc
@@ -0,0 +1,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;
+ uint _WireframeUV;
+
+ #ifndef POI_SHADOW
+ void applyWireframe(inout float3 wireframeEmission, inout float4 albedo)
+ {
+ UNITY_BRANCH
+ 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)
+ {
+ UNITY_BRANCH
+ 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)
+ {
+ UNITY_BRANCH
+ 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 \ No newline at end of file