Fog Parameters Updated

Hook timecycle to get fog start value.  This is then converted into a density value (based on known range) to produce a nicer fog cutoff value using EXP fog instead of linear table mode.
This commit is contained in:
Josh Pearson
2025-01-29 15:58:40 -07:00
parent 69f9bbcf7b
commit 282b639a4c

View File

@@ -174,6 +174,7 @@ static pvr_dr_state_t drState;
#include <kos/dbglog.h>
#if !defined(DC_TEXCONV) && !defined(DC_SIM)
#include "Timecycle.h"
#include <kos.h>
#define VIDEO_MODE_WIDTH vid_mode->width
@@ -305,6 +306,7 @@ void rw_mat_load_4x4(rw::Matrix* mtx) {
#define mat_identity(a)
#define pvr_fog_table_color(a,r,g,b)
#define pvr_fog_table_linear(s,e)
#define pvr_fog_table_exp(d)
#endif
#define mat_trans_single3_nomod(x_, y_, z_, x2, y2, z2) do { \
@@ -1098,6 +1100,7 @@ static bool doAlphaTest;
static uint8_t fogFuncPvr = PVR_FOG_DISABLE;
static uint32_t fogColor = 0;
static float fogStart = 0.0f;
static uint32 cullModePvr;
static inline unsigned pvrCullMode(uint32_t cullMode) {
@@ -1198,8 +1201,9 @@ setRenderState(int32 state, void *pvalue)
fogFuncPvr = value ? PVR_FOG_TABLE : PVR_FOG_DISABLE;
break;
case FOGCOLOR:
#if !defined(DC_TEXCONV)
// Set fog color when state changes
if(fogColor != value) {
if(fogColor != value || fogStart != CTimeCycle::GetFogStart()) {
fogColor = value;
RGBA c;
c.red = value;
@@ -1207,9 +1211,21 @@ setRenderState(int32 state, void *pvalue)
c.blue = value>>16;
c.alpha = value>>24;
pvr_fog_table_color(c.alpha / 255.0f, c.red / 255.0f, c.green / 255.0f, c.blue / 255.0f);
pvr_fog_table_linear(50.0f, 450.0f);
fogStart = CTimeCycle::GetFogStart();
//pvr_fog_table_linear(fogStart + 200.0f, fogStart + 450.0f);
// Fog ranges between -200 (Most Fog) and +100 (least fog) (these are loaded from TIMECYC.DAT)
// This formula will transform these values into a density between 0 and 0.02f
const float MAX_DENSITY = 0.02f;
const float FOG_RANGE = 300.0f;
const float FOG_OFFSET = 200.0f;
float density = ((FOG_RANGE - (fogStart + FOG_OFFSET)) / FOG_RANGE) * MAX_DENSITY;
pvr_fog_table_exp(density);
}
#endif
break;
// case CULLMODE:
// if(rwStateCache.cullmode != value){
// rwStateCache.cullmode = value;