Skip to content

Commit

Permalink
Fix underwater fog
Browse files Browse the repository at this point in the history
  • Loading branch information
pskelton committed Aug 1, 2024
1 parent 8b129f6 commit a0063c0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/Engine/Graphics/Outdoor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ bool OutdoorLocation::Initialize(std::string_view filename, int days_played,
::day_attrib = this->loc_time.day_attrib;
::day_fogrange_1 = this->loc_time.day_fogrange_1;
::day_fogrange_2 = this->loc_time.day_fogrange_2;
::day_fogrange_3 = pCamera3D->GetFarClip();
if (isMapUnderwater(engine->_currentLoadedMapId))
SetUnderwaterFog();

Expand Down Expand Up @@ -489,6 +490,8 @@ void OutdoorLocation::SetFog() {
::day_attrib &= ~MAP_WEATHER_FOGGY;
}

::day_fogrange_3 = pCamera3D->GetFarClip();

if (isMapUnderwater(map_id))
SetUnderwaterFog();
pOutdoor->loc_time.day_fogrange_1 = ::day_fogrange_1;
Expand Down Expand Up @@ -2275,7 +2278,8 @@ int GetCeilingHeight(int Party_X, signed int Party_Y, int Party_ZHeight, int *pF
//----- (00464851) --------------------------------------------------------
void SetUnderwaterFog() {
day_fogrange_1 = 50;
day_fogrange_2 = 5000;
day_fogrange_2 = 1000;
day_fogrange_3 = 15000;
}

//----- (00487DA9) --------------------------------------------------------
Expand Down Expand Up @@ -2538,7 +2542,9 @@ void loadAndPrepareODM(MapId mapid, bool bLoading, ODMRenderParams *a2) {
// returns 0xXXYYZZ fog color
Color GetLevelFogColor() {
if (engine->IsUnderwater()) {
return colorTable.OliveDrab;
Color sea = colorTable.Topaz; //OliveDrab;
// TODO(pskelton): 0.65 is desaturation factor - this will need moving/dropping when thats sorted
return Color(sea.r * 0.65f, sea.g * 0.65f , sea.b * 0.65f);
}

if (day_attrib & MAP_WEATHER_FOGGY) {
Expand Down
4 changes: 2 additions & 2 deletions src/Engine/Graphics/Renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ void OpenGLRenderer::DrawForcePerVerts() {
if (fpfogcol != Color()) {
fpfogstart = day_fogrange_1;
fpfogmiddle = day_fogrange_2;
fpfogend = pCamera3D->GetFarClip();
fpfogend = day_fogrange_3;
fpfogr = fpfogcol.r / 255.0f;
fpfogg = fpfogcol.g / 255.0f;
fpfogb = fpfogcol.b / 255.0f;
Expand Down Expand Up @@ -2386,7 +2386,7 @@ void OpenGLRenderer::SetFogParametersGL() {
if (fogcol != Color()) {
fogstart = day_fogrange_1;
fogmiddle = day_fogrange_2;
fogend = pCamera3D->GetFarClip();
fogend = day_fogrange_3;
fog.r = fogcol.r / 255.0f;
fog.g = fogcol.g / 255.0f;
fog.b = fogcol.b / 255.0f;
Expand Down
6 changes: 5 additions & 1 deletion src/Engine/mm7_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2439,9 +2439,13 @@ int bDialogueUI_InitializeActor_NPC_ID;
std::array<char, 777> byte_5E4C15;

int uDefaultTravelTime_ByFoot;

// TODO(pskelton): can we drop these fog globals?
MapWeatherFlags day_attrib;
int day_fogrange_1; // fog start dist
int day_fogrange_2; // fog end dist
int day_fogrange_2; // fog mid dist
int day_fogrange_3; // fog end dist

float fWalkSpeedMultiplier = 1.0f;
float fBackwardWalkSpeedMultiplier = 1.0f;
float fTurnSpeedMultiplier = 1.0f;
Expand Down
3 changes: 3 additions & 0 deletions src/Engine/mm7_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ extern int npcIdToDismissAfterDialogue;
extern int bDialogueUI_InitializeActor_NPC_ID;

extern int uDefaultTravelTime_ByFoot;

extern MapWeatherFlags day_attrib;
extern int day_fogrange_1;
extern int day_fogrange_2;
extern int day_fogrange_3;

extern float fWalkSpeedMultiplier;
extern float fBackwardWalkSpeedMultiplier;
extern float fTurnSpeedMultiplier;
Expand Down

0 comments on commit a0063c0

Please sign in to comment.