mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-27 06:35:39 +00:00
VideoSoftware: Improve fog range adjustment by using less magic and more comments.
This commit is contained in:
parent
3ab4e35582
commit
0994a5828d
@ -686,8 +686,9 @@ union FogRangeKElement
|
|||||||
u32 LO : 12;
|
u32 LO : 12;
|
||||||
u32 regid : 8;
|
u32 regid : 8;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: Which scaling coefficient should we use here? This is just a guess!
|
// TODO: Which scaling coefficient should we use here? This is just a guess!
|
||||||
float GetValue(int i) { return (i ? HI : LO) / 32.f; }
|
float GetValue(int i) { return (i ? HI : LO) / 256.f; }
|
||||||
u32 HEX;
|
u32 HEX;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -697,7 +698,7 @@ struct FogRangeParams
|
|||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
u32 Center : 10;
|
u32 Center : 10; // viewport center + 342
|
||||||
u32 Enabled : 1;
|
u32 Enabled : 1;
|
||||||
u32 unused : 13;
|
u32 unused : 13;
|
||||||
u32 regid : 8;
|
u32 regid : 8;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "Tev.h"
|
#include "Tev.h"
|
||||||
#include "EfbInterface.h"
|
#include "EfbInterface.h"
|
||||||
#include "TextureSampler.h"
|
#include "TextureSampler.h"
|
||||||
|
#include "XFMemLoader.h"
|
||||||
#include "SWPixelEngine.h"
|
#include "SWPixelEngine.h"
|
||||||
#include "SWStatistics.h"
|
#include "SWStatistics.h"
|
||||||
#include "SWVideoConfig.h"
|
#include "SWVideoConfig.h"
|
||||||
@ -750,12 +751,19 @@ void Tev::Draw()
|
|||||||
|
|
||||||
if(bpmem.fogRange.Base.Enabled)
|
if(bpmem.fogRange.Base.Enabled)
|
||||||
{
|
{
|
||||||
// TODO: Check if this is correct (especially the magic values)
|
// TODO: This is untested and should definitely be checked against real hw.
|
||||||
float offset = Position[0] - bpmem.fogRange.Base.Center + 324.f;
|
// - No idea if offset is really normalized against the viewport width or against the projection matrix or yet something else
|
||||||
int index = 9 - std::abs(Position[0] - bpmem.fogRange.Base.Center + 324) / (162/5);
|
// - scaling of the "k" coefficient isn't clear either.
|
||||||
float k = bpmem.fogRange.K[index/2].GetValue(index%2);
|
|
||||||
float x_adjust = sqrt(offset*offset/162.f/162.f + k*k)/k;
|
// First, calculate the offset from the viewport center (normalized to 0..1)
|
||||||
ze *= x_adjust;
|
float offset = (Position[0] - (bpmem.fogRange.Base.Center - 342)) / (float)swxfregs.viewport.wd;
|
||||||
|
// Based on that, choose the index such that points which are far away from the z-axis use the 10th "k" value and such that central points use the first value.
|
||||||
|
int index = 9 - std::abs(offset) * 9.f;
|
||||||
|
index = (index < 0) ? 0 : (index > 9) ? 9 : 0; // TODO: Shouldn't be necessary!
|
||||||
|
// Look up coefficient... Seems like multiplying by 4 makes Fortune Street work properly (fog is too strong without the factor)
|
||||||
|
float k = bpmem.fogRange.K[index/2].GetValue(index%2) * 4.f;
|
||||||
|
float x_adjust = sqrt(offset*offset + k*k)/k;
|
||||||
|
ze *= x_adjust; // NOTE: This is basically dividing by a cosine (hidden behind GXInitFogAdjTable): 1/cos = c/b = sqrt(a^2+b^2)/b
|
||||||
}
|
}
|
||||||
|
|
||||||
ze -= bpmem.fog.c_proj_fsel.GetC();
|
ze -= bpmem.fog.c_proj_fsel.GetC();
|
||||||
|
@ -88,13 +88,13 @@ void TransformPosition(const InputVertexData *src, OutputVertexData *dst)
|
|||||||
const float* mat = (const float*)&swxfregs.posMatrices[src->posMtx * 4];
|
const float* mat = (const float*)&swxfregs.posMatrices[src->posMtx * 4];
|
||||||
MultiplyVec3Mat34(src->position, mat, dst->mvPosition);
|
MultiplyVec3Mat34(src->position, mat, dst->mvPosition);
|
||||||
|
|
||||||
if (swxfregs.projection[6] == 0)
|
if (swxfregs.projection.type == GX_PERSPECTIVE)
|
||||||
{
|
{
|
||||||
MultipleVec3Perspective(dst->mvPosition, swxfregs.projection, dst->projectedPosition);
|
MultipleVec3Perspective(dst->mvPosition, swxfregs.projection.rawProjection, dst->projectedPosition);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
MultipleVec3Ortho(dst->mvPosition, swxfregs.projection, dst->projectedPosition);
|
MultipleVec3Ortho(dst->mvPosition, swxfregs.projection.rawProjection, dst->projectedPosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,9 @@ struct Light
|
|||||||
#define LIGHTATTN_NONE 2
|
#define LIGHTATTN_NONE 2
|
||||||
#define LIGHTATTN_DIR 3
|
#define LIGHTATTN_DIR 3
|
||||||
|
|
||||||
|
#define GX_PERSPECTIVE 0
|
||||||
|
#define GX_ORTHOGRAPHIC 1
|
||||||
|
|
||||||
union LitChannel
|
union LitChannel
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
@ -160,6 +163,12 @@ struct Viewport
|
|||||||
float farZ;
|
float farZ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Projection
|
||||||
|
{
|
||||||
|
float rawProjection[6];
|
||||||
|
u32 type; // only GX_PERSPECTIVE or GX_ORTHOGRAPHIC are allowed
|
||||||
|
};
|
||||||
|
|
||||||
union TexMtxInfo
|
union TexMtxInfo
|
||||||
{
|
{
|
||||||
struct
|
struct
|
||||||
@ -218,7 +227,7 @@ struct XFRegisters
|
|||||||
TXFMatrixIndexA MatrixIndexA; // 0x1018
|
TXFMatrixIndexA MatrixIndexA; // 0x1018
|
||||||
TXFMatrixIndexB MatrixIndexB; // 0x1019
|
TXFMatrixIndexB MatrixIndexB; // 0x1019
|
||||||
Viewport viewport; // 0x101a - 0x101f
|
Viewport viewport; // 0x101a - 0x101f
|
||||||
float projection[7]; // 0x1020 - 0x1026
|
Projection projection; // 0x1020 - 0x1026
|
||||||
u32 unk8[24]; // 0x1027 - 0x103e
|
u32 unk8[24]; // 0x1027 - 0x103e
|
||||||
u32 numTexGens; // 0x103f
|
u32 numTexGens; // 0x103f
|
||||||
TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047
|
TexMtxInfo texMtxInfo[8]; // 0x1040 - 0x1047
|
||||||
|
Loading…
x
Reference in New Issue
Block a user