Unity - 记录解决 部分手机设备上 浮点精度 不足 导致 UV 采样断层严重的 BUG

news/2024/11/23 9:26:04/

文章目录

  • 环境
  • 目的
  • 问题
  • 解决
  • Project


环境

Unity : 2020.3.37f1
Pipeline : BRP


目的

备忘,便于日后索引


问题

正常手机显卡芯片的浮点解析进度上的效果(其实不用手机上,PC 上将 uv * scale 一个巨大的值也会出现的)
在这里插入图片描述

异常手机显卡芯片的浮点解析进度上的效果(其实不用手机上,PC 上将 uv * scale 一个巨大的值也会出现的)
在这里插入图片描述


解决

诊断发现是: UV 精度 scale 之后溢出了

这个 shader 是 网上的一位TA大佬 (听说是叫: 猫大 的TA大佬 写的,下面的 shader 可以看到是使用 ASE 连连看 生成的代码)

// Made with Amplify Shader Editor
// Available at the Unity Asset Store - http://u3d.as/y3X 
Shader "VFX/PandaShaderSampleV1.0"
{Properties{[Enum(UnityEngine.Rendering.BlendMode)]_Scr("Scr", Float) = 5[Enum(UnityEngine.Rendering.BlendMode)]_Dst("Dst", Float) = 10[Enum(UnityEngine.Rendering.CullMode)]_CullMode("CullMode", Float) = 0_MainTex("MainTex", 2D) = "white" {}[Toggle]_MainTexAR("MainTexAR", Float) = 0[HDR]_MainColor("MainColor", Color) = (1,1,1,1)_MainTexUSpeed("MainTexUSpeed", Float) = 0_MainTexVSpeed("MainTexVSpeed", Float) = 0[Toggle]_CustomMainTex("CustomMainTex", Float) = 0[Toggle(_FMASKTEX_ON)] _FMaskTex("FMaskTex", Float) = 0_MaskTex("MaskTex", 2D) = "white" {}[Toggle]_MaskTexAR("MaskTexAR", Float) = 1_MaskTexUSpeed("MaskTexUSpeed", Float) = 0_MaskTexVSpeed("MaskTexVSpeed", Float) = 0[Toggle(_FDISTORTTEX_ON)] _FDistortTex("FDistortTex", Float) = 0_DistortTex("DistortTex", 2D) = "white" {}[Toggle]_DistortTexAR("DistortTexAR", Float) = 1_DistortFactor("DistortFactor", Range( 0 , 1)) = 0_DistortTexUSpeed("DistortTexUSpeed", Float) = 0_DistortTexVSpeed("DistortTexVSpeed", Float) = 0[Toggle]_DistortMainTex("DistortMainTex", Float) = 0[Toggle]_DistortMaskTex("DistortMaskTex", Float) = 0[Toggle]_DistortDissolveTex("DistortDissolveTex", Float) = 0[Toggle(_FDISSOLVETEX_ON)] _FDissolveTex("FDissolveTex", Float) = 0_DissolveTex("DissolveTex", 2D) = "white" {}[Toggle]_DissolveTexAR("DissolveTexAR", Float) = 1[HDR]_DissolveColor("DissolveColor", Color) = (1,1,1,1)[Toggle]_CustomDissolve("CustomDissolve", Float) = 0_DissolveFactor("DissolveFactor", Range( 0 , 1)) = 0_DissolveSoft("DissolveSoft", Range( 0 , 1)) = 0.1_DissolveWide("DissolveWide", Range( 0 , 1)) = 0.05_DissolveTexUSpeed("DissolveTexUSpeed", Float) = 0_DissolveTexVSpeed("DissolveTexVSpeed", Float) = 0_MainAlpha("MainAlpha", Range( 0 , 10)) = 1[Toggle(_FFNL_ON)] _FFnl("FFnl", Float) = 0[Toggle(_FDEPTH_ON)] _FDepth("FDepth", Float) = 0[HDR]_FnlColor("FnlColor", Color) = (1,1,1,1)_FnlScale("FnlScale", Range( 0 , 2)) = 0_FnlPower("FnlPower", Range( 1 , 10)) = 1[Toggle]_ReFnl("ReFnl", Float) = 0[Enum(Alpha,0,Add,1)]_BlendMode("BlendMode", Float) = 0_DepthFade("DepthFade", Range( 0 , 10)) = 1[HideInInspector] _texcoord2( "", 2D ) = "white" {}[HideInInspector] _texcoord( "", 2D ) = "white" {}[HideInInspector] __dirty( "", Int ) = 1}SubShader{Tags{ "RenderType" = "Transparent"  "Queue" = "Transparent+0" "IsEmissive" = "true"  }Cull [_CullMode]ZWrite OffZTest LEqualBlend [_Scr] [_Dst], One OneMinusSrcAlphaCGPROGRAM#include "UnityShaderVariables.cginc"#include "UnityCG.cginc"#pragma target 3.0#pragma shader_feature_local _FDISSOLVETEX_ON#pragma shader_feature_local _FDISTORTTEX_ON#pragma shader_feature_local _FFNL_ON#pragma shader_feature_local _FMASKTEX_ON#pragma shader_feature_local _FDEPTH_ON#pragma surface surf Unlit keepalpha noshadow noambient novertexlights nolightmap  nodynlightmap nodirlightmap nofog nometa noforwardadd #undef TRANSFORM_TEX#define TRANSFORM_TEX(tex,name) float4(tex.xy * name##_ST.xy + name##_ST.zw, tex.z, tex.w)struct Input{float4 vertexColor : COLOR;float2 uv_texcoord;float4 uv2_texcoord2;float3 worldPos;half3 worldNormal;float4 screenPos;};uniform half _Dst;uniform half _CullMode;uniform half _BlendMode;uniform half _Scr;uniform float4 _MainColor;uniform sampler2D _MainTex;uniform half _MainTexUSpeed;uniform half _MainTexVSpeed;uniform half _CustomMainTex;uniform float4 _MainTex_ST;uniform half _DistortMainTex;uniform half _DistortTexAR;uniform sampler2D _DistortTex;uniform half _DistortTexUSpeed;uniform half _DistortTexVSpeed;uniform float4 _DistortTex_ST;uniform half _DistortFactor;uniform float4 _DissolveColor;uniform half _CustomDissolve;uniform half _DissolveFactor;uniform half _DissolveWide;uniform half _DissolveSoft;uniform half _DissolveTexAR;uniform sampler2D _DissolveTex;uniform half _DissolveTexUSpeed;uniform half _DissolveTexVSpeed;uniform float4 _DissolveTex_ST;uniform half _DistortDissolveTex;uniform half _MainAlpha;uniform half _ReFnl;uniform half4 _FnlColor;uniform half _FnlScale;uniform half _FnlPower;uniform half _MainTexAR;uniform half _MaskTexAR;uniform sampler2D _MaskTex;uniform half _MaskTexUSpeed;uniform half _MaskTexVSpeed;uniform float4 _MaskTex_ST;uniform half _DistortMaskTex;UNITY_DECLARE_DEPTH_TEXTURE( _CameraDepthTexture );uniform float4 _CameraDepthTexture_TexelSize;uniform half _DepthFade;inline half4 LightingUnlit( SurfaceOutput s, half3 lightDir, half atten ){return half4 ( 0, 0, 0, s.Alpha );}void surf( Input i , inout SurfaceOutput o ){float Scr106 = _Scr;half2 appendResult4_g42 = (half2(_MainTexUSpeed , _MainTexVSpeed));float2 uv_MainTex = i.uv_texcoord * _MainTex_ST.xy + _MainTex_ST.zw;half2 temp_output_3_0_g39 = uv_MainTex;half2 appendResult4_g33 = (half2(_DistortTexUSpeed , _DistortTexVSpeed));float2 uv_DistortTex = i.uv_texcoord * _DistortTex_ST.xy + _DistortTex_ST.zw;// jave.lin : 修复前//half2 panner5_g33 = ( 1.0 * _Time.y * appendResult4_g33 + uv_DistortTex);// jave.lin : 修复后half2 panner5_g33 = ( 1.0 * frac(_Time.y * appendResult4_g33) + uv_DistortTex);half4 tex2DNode7_g33 = tex2D( _DistortTex, panner5_g33 );half Distort148 = ( ( _DistortTexAR == 0.0 ? tex2DNode7_g33.a : tex2DNode7_g33.r ) * _DistortFactor );#ifdef _FDISTORTTEX_ONhalf2 staticSwitch316 = ( _DistortMainTex == 0.0 ? temp_output_3_0_g39 : ( temp_output_3_0_g39 + Distort148 ) );#elsehalf2 staticSwitch316 = uv_MainTex;#endifhalf2 appendResult330 = (half2(i.uv2_texcoord2.x , i.uv2_texcoord2.y));// jave.lin : 修复前//half2 panner5_g42 = ( 1.0 * _Time.y * appendResult4_g42 + (( _CustomMainTex )?( ( staticSwitch316 + appendResult330 ) ):( staticSwitch316 )));// jave.lin : 修复后half2 panner5_g42 = ( 1.0 * frac(_Time.y * appendResult4_g42) + (( _CustomMainTex )?( ( staticSwitch316 + appendResult330 ) ):( staticSwitch316 )));half4 tex2DNode7_g42 = tex2D( _MainTex, panner5_g42 );half4 MainTexColor215 = ( _MainColor * tex2DNode7_g42 );half temp_output_275_0 = (-_DissolveWide + ((( _CustomDissolve )?( i.uv2_texcoord2.z ):( _DissolveFactor )) - 0.0) * (1.0 - -_DissolveWide) / (1.0 - 0.0));half temp_output_277_0 = ( _DissolveSoft + 0.0001 );half temp_output_272_0 = (-temp_output_277_0 + (( temp_output_275_0 + _DissolveWide ) - 0.0) * (1.0 - -temp_output_277_0) / (1.0 - 0.0));half2 appendResult4_g41 = (half2(_DissolveTexUSpeed , _DissolveTexVSpeed));float2 uv_DissolveTex = i.uv_texcoord * _DissolveTex_ST.xy + _DissolveTex_ST.zw;half2 temp_output_3_0_g40 = uv_DissolveTex;#ifdef _FDISTORTTEX_ONhalf2 staticSwitch314 = ( _DistortDissolveTex == 0.0 ? temp_output_3_0_g40 : ( temp_output_3_0_g40 + Distort148 ) );#elsehalf2 staticSwitch314 = uv_DissolveTex;#endif// jave.lin : 修复前//half2 panner5_g41 = ( 1.0 * _Time.y * appendResult4_g41 + staticSwitch314);// jave.lin : 修复后half2 panner5_g41 = ( 1.0 * frac(_Time.y * appendResult4_g41) + staticSwitch314);half4 tex2DNode7_g41 = tex2D( _DissolveTex, panner5_g41 );half temp_output_308_20 = ( _DissolveTexAR == 0.0 ? tex2DNode7_g41.a : tex2DNode7_g41.r );half smoothstepResult264 = smoothstep( temp_output_272_0 , ( temp_output_272_0 + temp_output_277_0 ) , temp_output_308_20);half Alpha337 = _MainAlpha;half4 lerpResult223 = lerp( MainTexColor215 , _DissolveColor , ( _DissolveColor.a * ( 1.0 - smoothstepResult264 ) * Alpha337 ));#ifdef _FDISSOLVETEX_ONhalf4 staticSwitch298 = lerpResult223;#elsehalf4 staticSwitch298 = MainTexColor215;#endifhalf4 temp_cast_0 = (0.0).xxxx;half Refnl339 = _ReFnl;float3 ase_worldPos = i.worldPos;half3 ase_worldViewDir = normalize( UnityWorldSpaceViewDir( ase_worldPos ) );half3 ase_worldNormal = i.worldNormal;half fresnelNdotV279 = dot( ase_worldNormal, ase_worldViewDir );half fresnelNode279 = ( 0.0 + _FnlScale * pow( 1.0 - fresnelNdotV279, _FnlPower ) );half temp_output_283_0 = saturate( fresnelNode279 );half4 FnlMainColor286 = ( _FnlColor * temp_output_283_0 * _FnlColor.a );half4 temp_cast_1 = (0.0).xxxx;#ifdef _FFNL_ONhalf4 staticSwitch300 = ( Refnl339 == 0.0 ? FnlMainColor286 : temp_cast_1 );#elsehalf4 staticSwitch300 = temp_cast_0;#endiffloat4 MainColor98 = ( i.vertexColor * ( staticSwitch298 + staticSwitch300 ) );float MainTexAlpha138 = ( _MainColor.a * ( _MainTexAR == 0.0 ? tex2DNode7_g42.a : tex2DNode7_g42.r ) );half2 appendResult4_g44 = (half2(_MaskTexUSpeed , _MaskTexVSpeed));float2 uv_MaskTex = i.uv_texcoord * _MaskTex_ST.xy + _MaskTex_ST.zw;half2 temp_output_3_0_g43 = uv_MaskTex;#ifdef _FDISTORTTEX_ONhalf2 staticSwitch312 = ( _DistortMaskTex == 0.0 ? temp_output_3_0_g43 : ( temp_output_3_0_g43 + Distort148 ) );#elsehalf2 staticSwitch312 = uv_MaskTex;#endif// jave.lin : 修复前//half2 panner5_g44 = ( 1.0 * _Time.y * appendResult4_g44 + staticSwitch312);// jave.lin : 修复后half2 panner5_g44 = ( 1.0 * frac(_Time.y * appendResult4_g44) + staticSwitch312);half4 tex2DNode7_g44 = tex2D( _MaskTex, panner5_g44 );#ifdef _FMASKTEX_ONhalf staticSwitch291 = ( _MaskTexAR == 0.0 ? tex2DNode7_g44.a : tex2DNode7_g44.r );#elsehalf staticSwitch291 = 1.0;#endifhalf temp_output_270_0 = (-temp_output_277_0 + (temp_output_275_0 - 0.0) * (1.0 - -temp_output_277_0) / (1.0 - 0.0));half smoothstepResult256 = smoothstep( temp_output_270_0 , ( temp_output_270_0 + temp_output_277_0 ) , temp_output_308_20);half DissolveAlpha212 = smoothstepResult256;#ifdef _FDISSOLVETEX_ONhalf staticSwitch299 = DissolveAlpha212;#elsehalf staticSwitch299 = 1.0;#endifhalf ReFnlAlpha318 = ( 1.0 - temp_output_283_0 );#ifdef _FFNL_ONhalf staticSwitch319 = ( Refnl339 == 0.0 ? 1.0 : ReFnlAlpha318 );#elsehalf staticSwitch319 = 1.0;#endiffloat4 ase_screenPos = float4( i.screenPos.xyz , i.screenPos.w + 0.00000000001 );half4 ase_screenPosNorm = ase_screenPos / ase_screenPos.w;ase_screenPosNorm.z = ( UNITY_NEAR_CLIP_VALUE >= 0 ) ? ase_screenPosNorm.z : ase_screenPosNorm.z * 0.5 + 0.5;float screenDepth348 = LinearEyeDepth(SAMPLE_DEPTH_TEXTURE( _CameraDepthTexture, ase_screenPosNorm.xy ));half distanceDepth348 = abs( ( screenDepth348 - LinearEyeDepth( ase_screenPosNorm.z ) ) / ( _DepthFade ) );#ifdef _FDEPTH_ONhalf staticSwitch350 = saturate( distanceDepth348 );#elsehalf staticSwitch350 = 1.0;#endiffloat MainAlpha97 = saturate( ( MainTexAlpha138 * staticSwitch291 * i.vertexColor.a * Alpha337 * staticSwitch299 * staticSwitch319 * staticSwitch350 ) );o.Emission = ( Scr106 == 5.0 ? MainColor98 : ( MainColor98 * MainAlpha97 ) ).rgb;half temp_output_100_0 = MainAlpha97;o.Alpha = temp_output_100_0;}ENDCG}CustomEditor "SampleGUI"
}

上面的 shader 代码中,搜索: “修复后”,机可查看到类似下面的代码:


...// jave.lin : 修复前//half2 panner5_g33 = ( 1.0 * _Time.y * appendResult4_g33 + uv_DistortTex);// jave.lin : 修复后half2 panner5_g33 = ( 1.0 * frac(_Time.y * appendResult4_g33) + uv_DistortTex);
...// jave.lin : 修复前//half2 panner5_g42 = ( 1.0 * _Time.y * appendResult4_g42 + (( _CustomMainTex )?( ( staticSwitch316 + appendResult330 ) ):( staticSwitch316 )));// jave.lin : 修复后half2 panner5_g42 = ( 1.0 * frac(_Time.y * appendResult4_g42) + (( _CustomMainTex )?( ( staticSwitch316 + appendResult330 ) ):( staticSwitch316 )));
...// jave.lin : 修复前//half2 panner5_g41 = ( 1.0 * _Time.y * appendResult4_g41 + staticSwitch314);// jave.lin : 修复后half2 panner5_g41 = ( 1.0 * frac(_Time.y * appendResult4_g41) + staticSwitch314);
...// jave.lin : 修复前//half2 panner5_g44 = ( 1.0 * _Time.y * appendResult4_g44 + staticSwitch312);// jave.lin : 修复后half2 panner5_g44 = ( 1.0 * frac(_Time.y * appendResult4_g44) + staticSwitch312);
...

这种优化方式也有局限性的,因为我们的 sampler 的 filer mode 是 repeat,所以 uv 值域可以控制再 -1 ~ 1 即可,因为可以使用 frac 来优化,也可以 fmod(val, 1.0) 但是这个过于费,因为使用 frac 就OK

这个问题的是100%必现的,最终发布到出问题的手机上验证,修复了


其实这个解决方法,我以前在学习 B站上的 庄懂 TA巨佬 就有分享过
现在想起帮助还是挺大的


Project

backup : Testing_Effect_Error_4_RenderDoc_UV精度不足、断层的修复.rar


http://www.ppmy.cn/news/175512.html

相关文章

汇川MD380变频器系列,各种型号,原理图,pcb,BOM等

汇川MD380变频器系列,各种型号,原理图,pcb,BOM等 MD380系列变频器与MD320系列应用场合一致,电机控制性能较MD320变频器有明显提高,并可实现异步电机和永磁同步机控制,增加了用户可编程功能及后台…

原来美的冰箱内部也有这等画手~

#V计划 - 第一回 密室逃脱之冰雪迷雾 是什么让虾行者🦐 冰天雪地中坚定前行?是什么牛肉君🥩青春健壮发圈炫耀?答案竟是…… #万物皆可微晶

inovance变频器说明书参数设置_汇川(INOVANCE)MD310变频器说明书.pdf

MD310系列变频器用户手册 前言 前言 首先感谢您购买汇川技术开发生产的MD310 系列变频器! MD310 系列变频器是一款通用紧缩型多功能变频器,采用开环矢量和V/F 控制方式,以高性能的电流 矢量控制技术可实现异步电机控制,功率范围覆…

直流变频电风扇是如何制作的呢?

永磁同步电风扇生产过程 01 电风扇 一、简介 炎炎厦日中,头顶上这精美装饰的电风扇是如何制作的呢?下面让我们到生产车间一探究竟吧。 说实在的,对于工程制作非常感兴趣的我,从这个短片中还是学习到了很多的神奇的生产工艺。 二…

MusicFree一款小而美的播放器

前言 现在由于版权限制,基本不可能在一款音乐应用上找到所有想听的歌 所以不少朋友便下载了多个App来使用,不仅占用大量内存空间,来回切换也很麻烦 今天便给大家分享一款小而美的聚合音乐播放器 本体仅有不足30M,但却可以收听…

美的成立了半导体公司!

2月2日消息,企查查APP显示,1月26日,美垦半导体技术有限公司成立,注册资本2亿元人民币。股权穿透显示,该公司由美的集团和佛山市美的空调工业投资有限公司共同控股,分别持股95%、5%。 美垦半导体技术有限公司…

2016年美的校招面试

美的的面试流程: 网申-简历刷选-第一轮面试-结构化面试-签约恳谈 网申这个不用说啦,现在基本上每个公司都需要网申,网申之后有个小测评,很简单,相当于性格测试吧,就十来个题。 简历刷选:虽说是…