From b516dcfa5191502b3174605dd3d21058bd916674 Mon Sep 17 00:00:00 2001 From: Erik Hakala Date: Thu, 19 Sep 2024 04:19:38 +0000 Subject: [PATCH] Graphics/urp/bugfix/uum 77906 Fixes SpeeTree8 shader. Broken vertex shader and camera facing leaves. --- .../Shaders/Nature/SpeedTree8.shader | 8 ++-- .../Shaders/Nature/SpeedTree8Passes.hlsl | 40 ++++++++++--------- .../Scenes/060_SpeedTree_LeafFacing.unity | 8 ++-- 3 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader index 6e2353cb556..64cbed64bcc 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8.shader @@ -77,9 +77,9 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" #pragma shader_feature_local_vertex _WINDQUALITY_NONE _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM #pragma shader_feature_local EFFECT_BILLBOARD + #pragma shader_feature_local EFFECT_BUMP #pragma shader_feature_local_fragment EFFECT_HUE_VARIATION #pragma shader_feature_local_fragment EFFECT_SUBSURFACE - #pragma shader_feature_local_fragment EFFECT_BUMP #pragma shader_feature_local_fragment EFFECT_EXTRA_TEX #define ENABLE_WIND @@ -152,9 +152,9 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" #pragma shader_feature_local_vertex _WINDQUALITY_NONE _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM #pragma shader_feature_local EFFECT_BILLBOARD + #pragma shader_feature_local EFFECT_BUMP #pragma shader_feature_local_fragment EFFECT_HUE_VARIATION #pragma shader_feature_local_fragment EFFECT_SUBSURFACE - #pragma shader_feature_local_fragment EFFECT_BUMP #pragma shader_feature_local_fragment EFFECT_EXTRA_TEX #define ENABLE_WIND @@ -184,7 +184,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" #pragma multi_compile_instancing #pragma instancing_options assumeuniformscaling maxcount:50 - #pragma shader_feature_local_vertex _WINDQUALITY_NONE _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALMlity and backface normal mode enum keywords) + #pragma shader_feature_local_vertex _WINDQUALITY_NONE _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM #pragma shader_feature_local EFFECT_BILLBOARD #define ENABLE_WIND @@ -245,7 +245,7 @@ Shader "Universal Render Pipeline/Nature/SpeedTree8" #pragma fragment SpeedTree8FragDepthNormal #pragma shader_feature_local_vertex _WINDQUALITY_NONE _WINDQUALITY_FAST _WINDQUALITY_BETTER _WINDQUALITY_BEST _WINDQUALITY_PALM - #pragma shader_feature_local_fragment EFFECT_BUMP + #pragma shader_feature_local EFFECT_BUMP #pragma multi_compile _ LOD_FADE_CROSSFADE #pragma multi_compile_instancing diff --git a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl index 12829d1f443..ebbf1cbb8b1 100644 --- a/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl +++ b/Packages/com.unity.render-pipelines.universal/Shaders/Nature/SpeedTree8Passes.hlsl @@ -97,8 +97,26 @@ struct SpeedTreeFragmentInput void InitializeData(inout SpeedTreeVertexInput input, float lodValue) { -#if defined(LOD_FADE_PERCENTAGE) && (!defined(LOD_FADE_CROSSFADE) && !defined(EFFECT_BILLBOARD)) - input.vertex.xyz = lerp(input.vertex.xyz, input.texcoord2.xyz, lodValue); +#if !defined(EFFECT_BILLBOARD) + #if defined(LOD_FADE_PERCENTAGE) && (!defined(LOD_FADE_CROSSFADE)) + input.vertex.xyz = lerp(input.vertex.xyz, input.texcoord2.xyz, lodValue); + #endif + + // geometry type + float geometryType = (int) (input.texcoord3.w + 0.25); + bool leafTwo = false; + if (geometryType > GEOM_TYPE_FACINGLEAF) + { + geometryType -= 2; + leafTwo = true; + } + + // leaf facing + if (geometryType == GEOM_TYPE_FACINGLEAF) + { + float3 anchor = float3(input.texcoord1.zw, input.texcoord2.w); + input.vertex.xyz = DoLeafFacing(input.vertex.xyz, anchor); + } #endif // wind @@ -118,14 +136,6 @@ void InitializeData(inout SpeedTreeVertexInput input, float lodValue) float3 windyPosition = input.vertex.xyz; #ifndef EFFECT_BILLBOARD - // geometry type - float geometryType = (int)(input.texcoord3.w + 0.25); - bool leafTwo = false; - if (geometryType > GEOM_TYPE_FACINGLEAF) - { - geometryType -= 2; - leafTwo = true; - } // leaves if (geometryType > GEOM_TYPE_FROND) @@ -133,15 +143,7 @@ void InitializeData(inout SpeedTreeVertexInput input, float lodValue) // remove anchor position float3 anchor = float3(input.texcoord1.zw, input.texcoord2.w); windyPosition -= anchor; - - if (geometryType == GEOM_TYPE_FACINGLEAF) - { - // face camera-facing leaf to camera - float offsetLen = length(windyPosition); - windyPosition = mul(windyPosition.xyz, (float3x3)UNITY_MATRIX_IT_MV); // inv(MV) * windyPosition - windyPosition = normalize(windyPosition) * offsetLen; // make sure the offset vector is still scaled - } - + // leaf wind #if defined(_WINDQUALITY_FAST) || defined(_WINDQUALITY_BETTER) || defined(_WINDQUALITY_BEST) #ifdef _WINDQUALITY_BEST diff --git a/Tests/SRPTests/Projects/UniversalGraphicsTest_Terrain/Assets/Scenes/060_SpeedTree_LeafFacing.unity b/Tests/SRPTests/Projects/UniversalGraphicsTest_Terrain/Assets/Scenes/060_SpeedTree_LeafFacing.unity index e4f89a0ba85..f454dff0748 100644 --- a/Tests/SRPTests/Projects/UniversalGraphicsTest_Terrain/Assets/Scenes/060_SpeedTree_LeafFacing.unity +++ b/Tests/SRPTests/Projects/UniversalGraphicsTest_Terrain/Assets/Scenes/060_SpeedTree_LeafFacing.unity @@ -630,7 +630,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &581908187 Transform: m_ObjectHideFlags: 0 @@ -722,7 +722,7 @@ Camera: m_TargetDisplay: 0 m_TargetEye: 3 m_HDR: 1 - m_AllowMSAA: 1 + m_AllowMSAA: 0 m_AllowDynamicResolution: 0 m_ForceIntoRT: 0 m_OcclusionCulling: 1 @@ -803,11 +803,11 @@ MonoBehaviour: TargetWidth: 960 TargetHeight: 540 TargetMSAASamples: 4 - PerPixelCorrectnessThreshold: 0.001 + PerPixelCorrectnessThreshold: 0 PerPixelGammaThreshold: 0.003921569 PerPixelAlphaThreshold: 0.003921569 RMSEThreshold: 0 - AverageCorrectnessThreshold: 0.0001 + AverageCorrectnessThreshold: 0.001 IncorrectPixelsThreshold: 0.0000038146973 UseHDR: 0 UseBackBuffer: 0