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

feat: terrain blending fixes plus decals #327

Merged
merged 2 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 18 additions & 6 deletions package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ VS_OUTPUT main(VS_INPUT input)

typedef VS_OUTPUT PS_INPUT;

#if !defined(LANDSCAPE)
# undef TERRAIN_BLENDING
#endif

#if defined(DEFERRED)
struct PS_OUTPUT
{
Expand All @@ -406,6 +410,9 @@ struct PS_OUTPUT
# if defined(SNOW)
float4 Parameters : SV_Target7;
# endif
# if defined(TERRAIN_BLENDING)
float Depth : SV_Depth;
# endif
};
#else
struct PS_OUTPUT
Expand Down Expand Up @@ -916,10 +923,6 @@ float GetSnowParameterY(float texProjTmp, float alpha)
# include "WetnessEffects/WetnessEffects.hlsli"
# endif

# if !defined(LANDSCAPE)
# undef TERRAIN_BLENDING
# endif

# if defined(TERRAIN_BLENDING)
# include "TerrainBlending/TerrainBlending.hlsli"
# endif
Expand Down Expand Up @@ -972,7 +975,7 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace
float2 screenUV = ViewToUV(viewPosition, true, eyeIndex);
float screenNoise = InterleavedGradientNoise(screenUV * BufferDim);

# if defined(LANDSCAPE) && defined(TERRAIN_BLENDING)
# if defined(TERRAIN_BLENDING)
float depthSampled = GetTerrainOffsetDepth(screenUV, eyeIndex);
float depthComp = input.Position.z - depthSampled;

Expand All @@ -981,6 +984,9 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

float blendFactorTerrain = saturate((depthSampledLinear - depthPixelLinear) / 5.0);

if (input.Position.z == depthSampled)
blendFactorTerrain = 1;

clip(blendFactorTerrain);
blendFactorTerrain = saturate(blendFactorTerrain);

Expand Down Expand Up @@ -2032,8 +2038,14 @@ PS_OUTPUT main(PS_INPUT input, bool frontFace

# else

# if defined(LANDSCAPE) && defined(TERRAIN_BLENDING)
# if defined(TERRAIN_BLENDING)
psout.Diffuse.w = blendFactorTerrain;
# if defined(LOD_LAND_BLEND)
psout.Depth = lerp(lerp(depthSampled, input.Position.z, blendFactorTerrain > screenNoise), input.Position.z, lodBlendMul2 > 0.0);
# else
psout.Depth = lerp(depthSampled, input.Position.z, blendFactorTerrain > screenNoise);
# endif

# endif

psout.MotionVectors.zw = float2(0.0, psout.Diffuse.w);
Expand Down
3 changes: 2 additions & 1 deletion package/Shaders/Utility.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ VS_OUTPUT main(VS_INPUT input)
# endif

# if defined(OFFSET_DEPTH)
vsout.PositionCS.z += 5.0;
if (vsout.PositionCS.z < 4096)
vsout.PositionCS.z += 5.0;
# endif

# ifdef VR
Expand Down
13 changes: 10 additions & 3 deletions src/Features/TerrainBlending.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,14 @@ void TerrainBlending::TerrainShaderHacks()
} else {
auto dsv = terrainDepth.views[0];
context->OMSetRenderTargets(0, nullptr, dsv);
context->VSSetShader(GetTerrainVertexShader(), NULL, NULL);
auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton();
context->VSSetShader((ID3D11VertexShader*)shadowState->GetRuntimeData().currentVertexShader->shader, NULL, NULL);
}
renderAltTerrain = !renderAltTerrain;
}

if (renderTerrainWorld)
OverrideTerrainWorld();
}

void TerrainBlending::OverrideTerrainWorld()
Expand Down Expand Up @@ -235,8 +239,11 @@ void TerrainBlending::ResetTerrainDepth()

auto& mainDepth = renderer->GetDepthStencilData().depthStencils[RE::RENDER_TARGETS_DEPTHSTENCIL::kMAIN];

context->OMSetRenderTargets(0, NULL, mainDepth.views[0]);
context->VSSetShader(GetTerrainVertexShader(), NULL, NULL);
auto state = RE::BSGraphics::RendererShadowState::GetSingleton();
state->GetRuntimeData().stateUpdateFlags.set(RE::BSGraphics::ShaderFlags::DIRTY_RENDERTARGET);

auto shadowState = RE::BSGraphics::RendererShadowState::GetSingleton();
context->VSSetShader((ID3D11VertexShader*)shadowState->GetRuntimeData().currentVertexShader->shader, NULL, NULL);

context->CopyResource(terrainDepthTexture->resource.get(), mainDepth.texture);
}
Expand Down
2 changes: 0 additions & 2 deletions src/Features/TerrainBlending.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ struct TerrainBlending : Feature
singleton->ResetTerrainWorld();
singleton->renderTerrainWorld = inTerrain;
}
if (inTerrain)
singleton->OverrideTerrainWorld();
}
}
func(a_pass, a_technique, a_alphaTest, a_renderFlags);
Expand Down
Loading