From b87ee977a7e1857a0249528ae43647c4f4c45c70 Mon Sep 17 00:00:00 2001 From: lyuma <39946030+lyuma@users.noreply.github.com> Date: Fri, 31 May 2024 03:21:24 -0700 Subject: [PATCH] Use vertex NaN clipping on mobile --- Shaders/BoxClipTemplate.cginc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Shaders/BoxClipTemplate.cginc b/Shaders/BoxClipTemplate.cginc index 474a2f7..c5d9fc9 100644 --- a/Shaders/BoxClipTemplate.cginc +++ b/Shaders/BoxClipTemplate.cginc @@ -197,8 +197,14 @@ static float3 boxObjectSpaceCameraPosStereo = mul(unity_WorldToObject, float4(le static float3 boxObjectSpaceCameraPosStereo = boxObjectSpaceCameraPos; #endif +bool boxConditionCheck(float3 origvertpos); void boxPreprocessVertex(inout float4 vert, inout float3 norm, inout float4 tang) { vert.xyz *= (BOXCLIP_SCALE > 0 ? BOXCLIP_SCALE : 1); +#if defined(SHADER_API_MOBILE) || defined(SHADER_API_GLES30) + if (!boxConditionCheck(vert.xyz)) { + vert.xyz = sqrt(-vert.w); + } +#endif } void boxPreprocessVertex(inout float4 vert, inout float3 norm) { float4 tangent = 0; @@ -530,19 +536,27 @@ bool boxConditionCheck(float3 origvertpos) { } void boxConditionalClipLocal(float3 localPos) { +#if !defined(SHADER_API_MOBILE) && !defined(SHADER_API_GLES30) clip(boxConditionCheck(localPos) ? 0 : -1); +#endif } void boxConditionalClipLocal(float4 localPos) { +#if !defined(SHADER_API_MOBILE) && !defined(SHADER_API_GLES30) clip(boxConditionCheck(localPos.xyz) ? 0 : -1); +#endif } void boxConditionalClipWorld(float3 worldPos) { +#if !defined(SHADER_API_MOBILE) && !defined(SHADER_API_GLES30) clip(boxConditionCheck(mul(unity_WorldToObject, float4(worldPos, 1)).xyz) ? 0 : -1); +#endif } void boxConditionalClipWorld(float4 worldPos) { +#if !defined(SHADER_API_MOBILE) && !defined(SHADER_API_GLES30) clip(boxConditionCheck(mul(unity_WorldToObject, worldPos).xyz) ? 0 : -1); +#endif } bool geometry_check(float3 v1, float3 v2, float3 v3) {