【Unity开发】低版本HDRenderPipeline升级到HDRP14.x版本问题笔记
- 1、 Shader兼容问题
- 1.1 Undefined area shadow filter algorithm
- 1.1.1 找到Shader中HLSLPROGRAM标记
- 1.1.2 添加Pragma指令,让Shader能够正确编译并选择适当的阴影过滤算法
- 1.1.3 为所有Pass添加area shadow算法编译指令
- 1.2 'LightLoop': cannot convert output parameter from 'struct LightLoopOutput' to 'float3' at
- 1.2.1 修正参数声明
- 1.2.2 修正函数中使用参数方法
- 1.2.3 修正变量取值方法
- 1.2.4 完整代码
1、 Shader兼容问题
1.1 Undefined area shadow filter algorithm
Shader error in 'Stream_HD': "Undefined area shadow filter algorithm" at /Prj_Unity/Scenes/XXX/Library/PackageCache/com.unity.render-pipelines.high-definition@14.0.11/Runtime/Lighting/Shadow/HDShadowAlgorithms.hlsl(53)
Compiling Subshader: 0, Pass: Forward, Fragment program with DECALS_OFF SHADOW_LOW USE_FPTL_LIGHTLIST
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DEBUG_DISPLAY DECALS_3RT DECALS_4RT DIRLIGHTMAP_COMBINED DYNAMICLIGHTMAP_ON INSTANCING_ON LIGHTMAP_ON SHADER_API_GLES30 SHADOWS_SHADOWMASK SHADOW_HIGH SHADOW_MEDIUM UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING USE_CLUSTERED_LIGHTLIST _ALPHATEST_ON _DOUBLESIDED_ON _ENABLE_FOG_ON_TRANSPARENT _SURFACE_TYPE_TRANSPARENT
1.1.1 找到Shader中HLSLPROGRAM标记
Pass
{Name "xxx"Tags{...}Cull [_CullModeForward]...HLSLPROGRAM就是这里
}
1.1.2 添加Pragma指令,让Shader能够正确编译并选择适当的阴影过滤算法
// Pragmas HDRP 10+ 版本的area shadow算法编译指令#pragma multi_compile _ DOTS_INSTANCING_ON#pragma instancing_options renderinglayer#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH
示例
Pass{Name "Forward"Tags { "LightMode"="Forward" }Blend [_SrcBlend] [_DstBlend], [_AlphaSrcBlend] [_AlphaDstBlend]Cull [_CullModeForward]ZTest [_ZTestDepthEqualForOpaque]ZWrite [_ZWrite]Stencil{Ref [_StencilRef]WriteMask [_StencilWriteMask]Comp AlwaysPass ReplaceFail KeepZFail Keep}ColorMask [_ColorMaskTransparentVel]HLSLPROGRAM// Pragmas HDRP 10+ 版本的area shadow算法编译指令#pragma multi_compile _ DOTS_INSTANCING_ON#pragma instancing_options renderinglayer#pragma multi_compile_fragment AREA_SHADOW_MEDIUM AREA_SHADOW_HIGH... 其他原代码
1.1.3 为所有Pass添加area shadow算法编译指令
找出Shader中所有的Pass,添加以上指令,就能解决"Undefined area shadow filter algorithm" 报错了。
1.2 ‘LightLoop’: cannot convert output parameter from ‘struct LightLoopOutput’ to ‘float3’ at
Shader error in 'Stream_HD': 'LightLoop': cannot convert output parameter from 'struct LightLoopOutput' to 'float3' at Pack/Shaders/Stream_HD.shader(4407) (on d3d11)Compiling Subshader: 0, Pass: Forward, Fragment program with AREA_SHADOW_MEDIUM DECALS_OFF SHADOW_LOW USE_FPTL_LIGHTLIST
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: AREA_SHADOW_HIGH DEBUG_DISPLAY DECALS_3RT DECALS_4RT DIRLIGHTMAP_COMBINED DOTS_INSTANCING_ON DYNAMICLIGHTMAP_ON INSTANCING_ON LIGHTMAP_ON SHADER_API_GLES30 SHADOWS_SHADOWMASK SHADOW_HIGH SHADOW_MEDIUM UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING USE_CLUSTERED_LIGHTLIST _ALPHATEST_ON _DOUBLESIDED_ON _ENABLE_FOG_ON_TRANSPARENT _SURFACE_TYPE_TRANSPARENT
1.2.1 修正参数声明
float3 diffuseLighting;
float3 specularLighting;
变更为
LightLoopOutput lightLoopOutput;
1.2.2 修正函数中使用参数方法
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
变更为
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput);
1.2.3 修正变量取值方法
diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
变更为
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
float3 specularLighting = lightLoopOutput.specularLighting;
diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();
1.2.4 完整代码
// 旧版本
/*float3 diffuseLighting;
float3 specularLighting;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, diffuseLighting, specularLighting);
diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();*/// 替换Unity HDRP 10+版本
LightLoopOutput lightLoopOutput;
LightLoop(V, posInput, preLightData, bsdfData, builtinData, featureFlags, lightLoopOutput);
float3 diffuseLighting = lightLoopOutput.diffuseLighting;
float3 specularLighting = lightLoopOutput.specularLighting;
diffuseLighting *= GetCurrentExposureMultiplier();
specularLighting *= GetCurrentExposureMultiplier();