Fog fixes

This commit is contained in:
Mind Rapist
2026-02-16 16:47:52 +02:00
parent 2c73eb7bb0
commit 3e604d5f10
9 changed files with 124 additions and 22 deletions

View File

@@ -7,6 +7,19 @@
#include "PropertyLoader.h"
// MR-14: Fog update by Alaric
// Not the proper way to handle this but I'm lazy
#ifdef _DEBUG
#undef _DEBUG
#include <python/python.h>
#define _DEBUG
#else
#include <python/python.h>
#endif
#include "UserInterface/PythonSystem.h"
// MR-14: -- END OF -- Fog update by Alaric
//////////////////////////////////////////////////////////////////////////
// 기본 함수
//////////////////////////////////////////////////////////////////////////
@@ -251,12 +264,30 @@ void CMapManager::BeginEnvironment()
DWORD dwFogColor = mc_pcurEnvironmentData->FogColor;
STATEMANAGER.SetRenderState(D3DRS_FOGCOLOR, dwFogColor);
if (mc_pcurEnvironmentData->bDensityFog)
// MR-14: Fog update by Alaric
// DIFFERENCE WITH THE OFFICIAL VERSION:
/*
Currently the official does not use the buttons "Dense", "Middle", "Light" for fog density. Instead,
they use an On/Off boolean variable. To maintain the classic feel in the settings, we customized the
modern official functionality into the 3-way button controls.
To migrate to boolean (official-like), replace mc_pcurEnvironmentData->bDensityFog with m_isFogModeEnabled
and remove the const float fFogDensityLevel[3] and instead, multiple mc_pcurEnvironmentData->bFogLevel with
the official 0.000010f value for the fDensity.
To migrate with the official, other variables in this update must be adjusted as well.
*/
if (mc_pcurEnvironmentData->bDensityFog && mc_pcurEnvironmentData->bFogLevel != 0)
{
float fDensity = 0.00015f;
const float fFogDensityLevel[3] = { 0.000020f, 0.000010f, 0.000005f };
float fDensity = mc_pcurEnvironmentData->bFogLevel * fFogDensityLevel[CPythonSystem::Instance().GetFogLevel()];
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_EXP); // pixel fog
STATEMANAGER.SetRenderState(D3DRS_FOGDENSITY, *((DWORD *) &fDensity)); // vertex fog
}
// MR-14: -- END OF -- Fog update by Alaric
else
{
CSpeedTreeForestDirectX8& rkForest=CSpeedTreeForestDirectX8::Instance();
@@ -267,6 +298,7 @@ void CMapManager::BeginEnvironment()
float fFogNear=mc_pcurEnvironmentData->GetFogNearDistance();
float fFogFar=mc_pcurEnvironmentData->GetFogFarDistance();
STATEMANAGER.SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR); // vertex fox
STATEMANAGER.SetRenderState(D3DRS_RANGEFOGENABLE, TRUE); // vertex fox
STATEMANAGER.SetRenderState(D3DRS_FOGSTART, *((DWORD *) &fFogNear)); // USED BY D3DFOG_LINEAR

View File

@@ -89,13 +89,17 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
SelectIndexBuffer(0, &wPrimitiveCount, &ePrimitiveType);
DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE);
// MR-14: Fog update by Alaric
// DWORD dwFogEnable = STATEMANAGER.GetRenderState(D3DRS_FOGENABLE);
// MR-14: -- END OF -- Fog update by Alaric
std::vector<std::pair<float, long> >::iterator it = m_PatchVector.begin();
// NOTE: 맵툴에서는 view ~ fog near 사이의 지형을 fog disabled 상태로 그리는 작업을 하지 않음.
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
// MR-14: Fog update by Alaric
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
// MR-14: -- END OF -- Fog update by Alaric
for( ; it != near_it; ++it)
for(; it != near_it; ++it)
{
if (byCUrrentLODLevel == 0 && fLODLevel1Distance <= it->first)
{
@@ -109,6 +113,7 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
}
__HardwareTransformPatch_RenderPatchSplat(it->second, wPrimitiveCount, ePrimitiveType);
if (m_iRenderedSplatNum >= m_iSplatLimit)
break;
@@ -116,7 +121,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
DrawWireFrame(it->second, wPrimitiveCount, ePrimitiveType);
}
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
// MR-14: Fog update by Alaric
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
// MR-14: -- END OF -- Fog update by Alaric
if (m_iRenderedSplatNum < m_iSplatLimit)
{
@@ -143,7 +150,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
}
}
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
// MR-14: Fog update by Alaric
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, FALSE);
// MR-14: -- END OF -- Fog update by Alaric
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, FALSE);
STATEMANAGER.SetTexture(0, NULL);
@@ -195,7 +204,9 @@ void CMapOutdoor::__RenderTerrain_RenderHardwareTransformPatch()
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
STATEMANAGER.SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
// MR-14: Fog update by Alaric
// STATEMANAGER.SetRenderState(D3DRS_FOGENABLE, dwFogEnable);
// MR-14: -- END OF -- Fog update by Alaric
STATEMANAGER.SetRenderState(D3DRS_LIGHTING, TRUE);
std::sort(m_RenderedTextureNumVector.begin(),m_RenderedTextureNumVector.end());

View File

@@ -143,6 +143,9 @@ typedef struct SEnvironmentData
float GetFogFarDistance() const;
D3DXCOLOR FogColor;
// MR-14: Fog update by Alaric
BYTE bFogLevel;
// MR-14: -- END OF -- Fog update by Alaric
// Filtering
BOOL bFilteringEnable;

View File

@@ -27,8 +27,10 @@ void Environment_Init(SEnvironmentData& envData)
envData.Material.Specular = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);
envData.Material.Power = 0.0f;
envData.bFogEnable = FALSE;
envData.bDensityFog = FALSE;
// MR-14: Fog update by Alaric
envData.bFogEnable = TRUE;
envData.bDensityFog = TRUE;
// MR-14: -- END OF -- Fog update by Alaric
envData.m_fFogNearDistance = 25600.0f * 0.5f;
envData.m_fFogFarDistance = 25600.0f * 0.7f;
envData.FogColor = D3DXCOLOR(0.5f, 0.5f, 0.5f, 1.0f);
@@ -114,10 +116,13 @@ bool Environment_Load(SEnvironmentData& envData, const char* envFileName)
if (textLoader.SetChildNode("fog"))
{
textLoader.GetTokenBoolean("enable", &envData.bFogEnable);
textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog);
textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance);
textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance);
// MR-14: Fog update by Alaric
// textLoader.GetTokenBoolean("enable", &envData.bFogEnable);
// textLoader.GetTokenBoolean("isdensity", &envData.bDensityFog);
// textLoader.GetTokenFloat("neardistance", &envData.m_fFogNearDistance);
// textLoader.GetTokenFloat("fardistance", &envData.m_fFogFarDistance);
textLoader.GetTokenByte("foglevel", &envData.bFogLevel);
// MR-14: -- END OF -- Fog update by Alaric
textLoader.GetTokenColor("color", &envData.FogColor);
textLoader.SetParentNode();
}