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

Render fog zones in Gothic 1 #153

Merged
merged 1 commit into from
Feb 12, 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
16 changes: 14 additions & 2 deletions D3D11Engine/D3D11PFX_HeightFog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,35 @@ XRESULT D3D11PFX_HeightFog::Render( RenderToTextureBuffer* fxbuffer ) {
cb.HF_WeightZFar = std::min( cb.HF_WeightZFar, atmoMax );
cb.HF_WeightZNear = std::min( cb.HF_WeightZNear, atmoMin );

#ifndef BUILD_GOTHIC_1_08k
float fogDensityFactor = 2;
float fogDensityFactorRain = (1.0f - Engine::GAPI->GetFogOverride());
#else
float fogDensityFactor = pow( 15000.0f / Engine::GAPI->GetFarZ(), 4.0f );
float fogDensityFactorRain = 1.0f;
#endif

if ( Engine::GAPI->GetFogOverride() > 0.0f ) {
// Make sure the camera is inside the fog when in fog zone
height = Toolbox::lerp( height, Engine::GAPI->GetCameraPosition().y + 10000, Engine::GAPI->GetFogOverride() ); // TODO: Get this from the actual fog-distance in the fogzone!

// Override fog color when in fog zone
color = Engine::GAPI->GetFogColor();

#ifndef BUILD_GOTHIC_1_08k
// Make it z-Fog
cb.HF_HeightFalloff = Toolbox::lerp( cb.HF_HeightFalloff, 0.000001f, Engine::GAPI->GetFogOverride() );
#endif

// Turn up density
cb.HF_GlobalDensity = Toolbox::lerp( cb.HF_GlobalDensity, cb.HF_GlobalDensity * 2, Engine::GAPI->GetFogOverride() );
cb.HF_GlobalDensity = Toolbox::lerp( cb.HF_GlobalDensity, cb.HF_GlobalDensity * fogDensityFactor, Engine::GAPI->GetFogOverride() );

#ifndef BUILD_GOTHIC_1_08k
// Use other fog-values for fog-zones
float distNear = WORLD_SECTION_SIZE * ((ffar - fnear) / ffar);
cb.HF_WeightZNear = Toolbox::lerp( cb.HF_WeightZNear, WORLD_SECTION_SIZE * 0.09f, Engine::GAPI->GetFogOverride() );
cb.HF_WeightZFar = Toolbox::lerp( cb.HF_WeightZFar, WORLD_SECTION_SIZE * 0.8, Engine::GAPI->GetFogOverride() );
#endif
}

//Engine::GAPI->GetRendererState().RendererSettings.FogColorMod;
Expand All @@ -94,7 +106,7 @@ XRESULT D3D11PFX_HeightFog::Render( RenderToTextureBuffer* fxbuffer ) {
XMStoreFloat3( &FogColorMod, XMVectorLerpV( color, XMLoadFloat3( &Engine::GAPI->GetRendererState().RendererSettings.RainFogColor ), XMVectorSet( std::min( 1.0f, rain * 2.0f ), std::min( 1.0f, rain * 2.0f ), std::min( 1.0f, rain * 2.0f ), 0 ) ) ); // Scale color faster here, so it looks better on light rain
cb.HF_FogColorMod = FogColorMod;
// Raining Density, only when not in fogzone
cb.HF_GlobalDensity = Toolbox::lerp( cb.HF_GlobalDensity, Engine::GAPI->GetRendererState().RendererSettings.RainFogDensity, rain * (1.0f - Engine::GAPI->GetFogOverride()) );
cb.HF_GlobalDensity = Toolbox::lerp( cb.HF_GlobalDensity, Engine::GAPI->GetRendererState().RendererSettings.RainFogDensity, rain * fogDensityFactorRain );


hfPS->GetConstantBuffer()[0]->UpdateBuffer( &cb );
Expand Down
6 changes: 6 additions & 0 deletions D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2720,6 +2720,12 @@ GInventory* GothicAPI::GetInventory() {
return Inventory.get();
}

/** Returns the far Z */
float GothicAPI::GetFarZ() {
zCSkyController_Outdoor* sc = oCGame::GetGame()->_zCSession_world->GetSkyControllerOutdoor();
return sc->GetFarZ();
}

/** Returns the fog-color */
FXMVECTOR GothicAPI::GetFogColor() {
zCSkyController_Outdoor* sc = oCGame::GetGame()->_zCSession_world->GetSkyControllerOutdoor();
Expand Down
3 changes: 3 additions & 0 deletions D3D11Engine/GothicAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,9 @@ class GothicAPI {
/** Returns the GSky-Object */
GSky* GetSky() const;

/** Returns the far Z */
float GetFarZ();

/** Returns the fog-color */
FXMVECTOR GetFogColor();

Expand Down
4 changes: 2 additions & 2 deletions D3D11Engine/GothicMemoryLocations1_08k.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ struct GothicMemoryLocations {
static const unsigned int Init = 0x005E6A00;*/

static const unsigned int GetUnderwaterFX = 0x5baaa0;
static const unsigned int Offset_OverrideColor = 0x558;
static const unsigned int Offset_OverrideFlag = 0x564;
static const unsigned int Offset_FarZ = 0x56C;
static const unsigned int Offset_Color = 0x580;

static const unsigned int SetCameraLocationHint = 0x005BC7D0;

Expand Down
2 changes: 2 additions & 0 deletions D3D11Engine/GothicMemoryLocations2_6_fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ struct GothicMemoryLocations {
static const unsigned int Offset_SkyLayerState1 = 0x124;
static const unsigned int Offset_OverrideColor = 0x558;
static const unsigned int Offset_OverrideFlag = 0x564;
static const unsigned int Offset_FarZ = 0x580;
static const unsigned int Offset_Color = 0x594;
static const unsigned int Interpolate = 0x005E8C20;
static const unsigned int Offset_InitDone = 0x7C;
static const unsigned int Init = 0x005E6A00;
Expand Down
11 changes: 10 additions & 1 deletion D3D11Engine/zCSkyController_Outdoor.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,22 @@ class zCSkyController_Outdoor : public zCSkyController {
#ifndef BUILD_GOTHIC_1_08k
return *reinterpret_cast<XMFLOAT3*>(THISPTR_OFFSET( GothicMemoryLocations::zCSkyController_Outdoor::Offset_OverrideColor ));
#else
return XMFLOAT3( 0, 0, 0 );
zColor color = *reinterpret_cast<zColor*>THISPTR_OFFSET( GothicMemoryLocations::zCSkyController_Outdoor::Offset_Color );
return XMFLOAT3( color.bgra.r / 255.0f, color.bgra.g / 255.0f, color.bgra.b / 255.0f );
#endif
}

bool GetOverrideFlag() {
#ifndef BUILD_GOTHIC_1_08k
return *reinterpret_cast<int*>(THISPTR_OFFSET( GothicMemoryLocations::zCSkyController_Outdoor::Offset_OverrideFlag )) != 0;
#else
return 1;
#endif
}

float GetFarZ() {
#if defined(BUILD_GOTHIC_1_08k) || defined(BUILD_GOTHIC_2_6_fix)
return *reinterpret_cast<float*>THISPTR_OFFSET( GothicMemoryLocations::zCSkyController_Outdoor::Offset_FarZ );
#else
return 0;
#endif
Expand Down
Loading