Skip to content

Commit

Permalink
Fix incorrect WorldShadowRangeScale on initial lod
Browse files Browse the repository at this point in the history
  • Loading branch information
kirides committed Dec 7, 2020
1 parent 44b2746 commit 55b1102
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion D3D11Engine/D2DSettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ void D2DSettingsDialog::CloseButtonPressed( SV_Button* sender, void* userdata )

d->SetHidden( true );

Engine::GAPI->SaveMenuSettings( MENU_SETTINGS_FILE );
Engine::GAPI->SetEnableGothicInput( true );
}

Expand All @@ -422,6 +421,7 @@ void D2DSettingsDialog::ApplyButtonPressed( SV_Button* sender, void* userdata )
Engine::GraphicsEngine->OnResize( INT2( d->Resolutions[d->ResolutionSetting].Width, d->Resolutions[d->ResolutionSetting].Height ) );
}
Engine::GAPI->SaveRendererWorldSettings( settings );
Engine::GAPI->SaveMenuSettings( MENU_SETTINGS_FILE );
}

/** Checks if a change needs to reload the shaders */
Expand Down
13 changes: 2 additions & 11 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,24 +624,15 @@ XRESULT D3D11GraphicsEngine::OnBeginFrame() {

// Check for shadowmap resize
int s = Engine::GAPI->GetRendererState().RendererSettings.ShadowMapSize;
switch ( s ) {
case 0:
case 1: s = 512; break;
case 2: s = 1024; break;
case 3: s = 2048; break;
case 4: s = 4096; break;
case 5: s = 8192; break;
case 6: s = 16384; break;
}

if ( WorldShadowmap1->GetSizeX() != s ) {
int old = WorldShadowmap1->GetSizeX();
LogInfo() << "Shadowmapresolution changed to: " << s << "x" << s;
WorldShadowmap1 = std::make_unique<RenderToDepthStencilBuffer>(
GetDevice(), s, s, DXGI_FORMAT_R32_TYPELESS, nullptr, DXGI_FORMAT_D32_FLOAT,
DXGI_FORMAT_R32_FLOAT );

Engine::GAPI->GetRendererState().RendererSettings.WorldShadowRangeScale *= old / static_cast<float>(s);
Engine::GAPI->GetRendererState().RendererSettings.WorldShadowRangeScale =
Toolbox::GetRecommendedWorldShadowRangeScaleForSize(s);
}

// Force the mode
Expand Down
14 changes: 2 additions & 12 deletions D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3725,18 +3725,8 @@ XRESULT GothicAPI::LoadMenuSettings( const std::string& file ) {
s.FontFileMenu = GetPrivateProfileStringA( "FontRendering", "FontMenu", defaultRendererSettings.FontFileMenu, ini );

// Fix the shadow range
switch ( s.ShadowMapSize ) {
case 512:
case 1024:
s.WorldShadowRangeScale = 16.0f;
break;
case 2048:
s.WorldShadowRangeScale = 8.0f;
break;
default:
s.WorldShadowRangeScale = 4.0f;
break;
}
s.WorldShadowRangeScale = Toolbox::GetRecommendedWorldShadowRangeScaleForSize( s.ShadowMapSize );

// Fix the resolution if the players maximum resolution got lower
RECT r;
GetClientRect( GetDesktopWindow(), &r );
Expand Down
14 changes: 14 additions & 0 deletions D3D11Engine/Toolbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ struct zTBBox3D;
struct zTPlane;

namespace Toolbox {
FORCEINLINE float GetRecommendedWorldShadowRangeScaleForSize( int size ) {
constexpr int MAX_SHADOWMAP_SIZE = 16384;
return static_cast<float>( MAX_SHADOWMAP_SIZE / size );

/* // Equivalent to
switch ( size ) {
case 512: return 32.0f;
case 1024: return 16.0f;
case 2048: return 8.0f;
case 4096: return 4.0f;
case 8192: return 2.0f;
default: return 1.0f;
}*/
}

/** Checks if one of a series of strings is found within the input-string */
bool StringContainsOneOf( const std::string& string, const std::string* checkStrings, int numStrings );
Expand Down
2 changes: 1 addition & 1 deletion D3D11Engine/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#define stdext std
#endif

#define VERSION_NUMBER "17.7-dev15-fix1"
#define VERSION_NUMBER "17.7-dev15-fix2"
__declspec(selectany) const char* VERSION_NUMBER_STR = VERSION_NUMBER;

extern bool GMPModeActive;
Expand Down

0 comments on commit 55b1102

Please sign in to comment.