Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: dyndolod 3d trees shading #588

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -1010,13 +1010,22 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
{
PS_OUTPUT psout;
uint eyeIndex = GetEyeIndexPS(input.Position, VPOSOffset);

float3 viewPosition = mul(CameraView[eyeIndex], float4(input.WorldPosition.xyz, 1)).xyz;
float2 screenUV = ViewToUV(viewPosition, true, eyeIndex);
float screenNoise = InterleavedGradientNoise(input.Position.xy, FrameCount);

bool inWorld = ExtraShaderDescriptor & _InWorld;

float nearFactor = smoothstep(4096.0 * 2.5, 0.0, viewPosition.z);

# if defined(SKINNED) || !defined(MODELSPACENORMALS)
float3x3 tbn = float3x3(input.TBN0.xyz, input.TBN1.xyz, input.TBN2.xyz);

# if !defined(TREE_ANIM) && !defined(LOD)
// Fix incorrect vertex normals on double-sided meshes
if (!frontFace)
tbn = -tbn;
tbn = lerp(tbn, -tbn, nearFactor);
# endif

float3x3 tbnTr = transpose(tbn);
Expand All @@ -1031,12 +1040,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
# endif // defined (LANDSCAPE)
# endif

float3 viewPosition = mul(CameraView[eyeIndex], float4(input.WorldPosition.xyz, 1)).xyz;
float2 screenUV = ViewToUV(viewPosition, true, eyeIndex);
float screenNoise = InterleavedGradientNoise(input.Position.xy, FrameCount);

bool inWorld = ExtraShaderDescriptor & _InWorld;

# if defined(TERRAIN_BLENDING)
float depthSampled = TerrainBlending::GetTerrainOffsetDepth(screenUV, eyeIndex);
float depthComp = input.Position.z - depthSampled;
Expand Down Expand Up @@ -1743,8 +1746,6 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float porosity = 1.0;

float nearFactor = smoothstep(4096.0 * 2.5, 0.0, viewPosition.z);

# if defined(SKYLIGHTING)
# if defined(VR)
float3 positionMSSkylight = input.WorldPosition.xyz + CameraPosAdjust[eyeIndex].xyz - CameraPosAdjust[0].xyz;
Expand Down
Loading