rodecomp/Source/Render/DX7/RendererFogDX7.cpp
ragnarok-clanker d4568519de Maintenance: [forced, user-approved] R7b+R7c (resubmit of returned 10244, rebased on 947ce989): remove the invented FogConfiguration,
Batch #10247 by ragnarok-clanker: forced by an admin (3 lower score(s), 26 changed function(s)); checked with 330 compiled unit(s), including every includer of Source/Render/DX7/RendererFogDX7.h, Source/Render/DX9/DeviceOwnerDX9.h, Source/Render/DX9/RenderSystemDX9.h, Source/Render/DX9/RendererDX9.h, Source/Render/DX9/RendererDX9Operations.h, Source/Render/DX9/RendererFogDX9.h, Source/Render/DX9/RendererPresentation.h, Source/Render/DeviceContext/DCSurface.h, Source/Render/Projection/RendererViewport.h, Source/Render/RenderAdapter.h, Source/Render/SpriteGeometry.h, Source/Render/TextureQuad.h, Source/Render/FogConfiguration.h.
Deletes: Source/Render/FogConfiguration.h
2026-11-03 12:07:29 +00:00

126 lines
4 KiB
C++

#include "Client/Application/ErrorDialog.h"
#include "Render/TextureQuad.h"
#include "Render/DX7/RendererFogDX7.h"
#include <bit>
#include <cmath>
namespace {
// OFFSET: 0x00556E50
// FUNCTION: fn_02039
float Sine(float angle) {
return static_cast<float>(std::sin(static_cast<double>(angle)));
}
// OFFSET: 0x00556E40
// FUNCTION: fn_02038
float Cosine(float angle) {
return static_cast<float>(std::cos(static_cast<double>(angle)));
}
}
// OFFSET: 0x00556E60
// FUNCTION: fn_02040
float SquareRoot(float value) {
return std::sqrt(value);
}
// OFFSET: 0x00548C30
// FUNCTION: fn_01863
HRESULT PerspectiveMatrixDX7(D3DMATRIX& matrix, float fov, float aspect, float nearPlane, float farPlane) {
const float difference = farPlane - nearPlane;
constexpr float epsilon = 0.01f;
if (epsilon > std::fabs(difference)) {
return E_INVALIDARG;
}
const float half = fov * 0.5f;
if (epsilon > std::fabs(Sine(half))) {
return E_INVALIDARG;
}
const float cosineX = Cosine(half);
const float sineX = Sine(half);
const float scaleX = static_cast<float>((static_cast<double>(cosineX) / sineX) * aspect);
const float cosineY = Cosine(half);
const float sineY = Sine(half);
const float scaleY = static_cast<float>(static_cast<double>(cosineY) / sineY);
const float depth = farPlane / difference;
matrix._12 = matrix._13 = matrix._14 = 0;
matrix._21 = matrix._23 = matrix._24 = 0;
matrix._31 = matrix._32 = 0;
matrix._41 = matrix._42 = matrix._44 = 0;
matrix._34 = 1;
matrix._33 = depth;
const float translation = -depth * nearPlane;
matrix._11 = scaleX;
matrix._22 = scaleY;
matrix._43 = translation;
return S_OK;
}
// OFFSET: 0x0055CF10
// FUNCTION: fn_02094
void RendererFogDX7::Set(int value, IDirect3DDevice7* device, const D3DDEVICEDESC7& caps) {
this->supported = (caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0;
this->enabled = value;
device->SetRenderState(D3DRENDERSTATE_FOGENABLE, value);
this->dirty = 1;
g_fogRange = 1;
g_fogVertexMode = D3DFOG_LINEAR;
}
// OFFSET: 0x0055A500
// FUNCTION: fn_02080
void RendererFogDX7::Apply(
IDirect3DDevice7* device, const D3DDEVICEDESC7& caps, float aspect, CRenderSystemBase* renderSystem
) {
if (!this->dirty) {
return;
}
if (this->enabled) {
const float start = g_depthStart * 1490.0f + 10.0f;
const float end = g_depthEnd * 1490.0f + 10.0f;
const bool vertexFog = (caps.dpcTriCaps.dwRasterCaps & D3DPRASTERCAPS_FOGVERTEX) != 0;
D3DMATRIX identity{};
identity._11 = identity._22 = identity._33 = identity._44 = 1;
D3DMATRIX projection;
PerspectiveMatrixDX7(projection, 0.26179934f, aspect, 10.0f, 1500.0f);
device->SetTransform(D3DTRANSFORMSTATE_WORLD, &identity);
device->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &projection);
device->SetTransform(D3DTRANSFORMSTATE_VIEW, &identity);
device->SetRenderState(D3DRENDERSTATE_FOGCOLOR, g_worldOverlayColor);
if (g_fogVertexMode == D3DFOG_LINEAR) {
if (vertexFog) {
device->SetRenderState(D3DRENDERSTATE_FOGSTART, std::bit_cast<unsigned>(start));
device->SetRenderState(D3DRENDERSTATE_FOGEND, std::bit_cast<unsigned>(end));
device->SetRenderState(D3DRENDERSTATE_FOGDENSITY, std::bit_cast<unsigned>(g_fogDensity));
device->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE);
device->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, g_fogVertexMode);
} else {
device->SetRenderState(D3DRENDERSTATE_FOGENABLE, 0);
}
} else {
if (vertexFog) {
device->SetRenderState(D3DRENDERSTATE_FOGTABLEMODE, D3DFOG_NONE);
device->SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE, g_fogVertexMode);
} else {
ShowErrorDialog(renderSystem, "Your graphic accelerator does not support fog effect.", 0);
}
device->SetRenderState(D3DRENDERSTATE_FOGDENSITY, std::bit_cast<unsigned>(g_fogDensity));
}
if (vertexFog && g_fogRange) {
device->SetRenderState(D3DRENDERSTATE_RANGEFOGENABLE, 1);
}
}
this->dirty = 0;
}