Skip to content

Commit

Permalink
Graphics/urp/bugfix/uum 77906
Browse files Browse the repository at this point in the history
Fixes SpeeTree8 shader. Broken vertex shader and camera facing leaves.
  • Loading branch information
eh-unity authored and Evergreen committed Sep 19, 2024
1 parent a806f0b commit b516dcf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -118,30 +136,14 @@ 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)
{
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b516dcf

Please sign in to comment.