From e6827d3140f9b4d68f649634212a29fc718632ca Mon Sep 17 00:00:00 2001 From: cypress Date: Sat, 2 Sep 2023 22:01:12 -0400 Subject: [PATCH] NX/VITA: Proper fog implementation --- source/cl_main.c | 3 ++- source/gl_fog.c | 3 --- source/gl_rmain.c | 12 +++++++----- source/gl_sky.c | 4 ++-- source/r_alias.c | 38 +++++++++++++++++--------------------- source/r_world.c | 38 +++++++++++++++++--------------------- 6 files changed, 45 insertions(+), 53 deletions(-) diff --git a/source/cl_main.c b/source/cl_main.c index 16082e8..1cc8f9c 100644 --- a/source/cl_main.c +++ b/source/cl_main.c @@ -552,7 +552,8 @@ void CL_RelinkEntities (void) up_offset = up_offset/1000; forward_offset = forward_offset/1000; - up_offset -= (36 - cl.viewheight); + up_offset -= (34 - cl.viewheight); + right_offset -= 4; VectorMA (start, forward_offset, v_forward ,smokeorg); VectorMA (smokeorg, up_offset, v_up ,smokeorg); diff --git a/source/gl_fog.c b/source/gl_fog.c index 9c3c370..71cc681 100644 --- a/source/gl_fog.c +++ b/source/gl_fog.c @@ -299,11 +299,8 @@ float *Fog_GetColor (void) for (i=0;i<3;i++) c[i] = (float)(Q_rint(c[i] * 255)) / 255.0f; - // Dumb descrepancy with NX/VITA gl wrappings. -#ifndef VITA for (i = 0; i < 3; i++) c[i] /= 64.0; -#endif // VITA return c; } diff --git a/source/gl_rmain.c b/source/gl_rmain.c index 8a56b52..4b6d46d 100644 --- a/source/gl_rmain.c +++ b/source/gl_rmain.c @@ -759,7 +759,9 @@ void R_DrawEntitiesOnList (qboolean alphapass) //johnfitz -- added parameter { case mod_sprite: { + Fog_DisableGFog(); R_DrawSpriteModel (currententity); + Fog_EnableGFog(); break; } case mod_alias: @@ -1166,9 +1168,9 @@ R_RenderScene void R_RenderScene (void) { R_SetupScene (); //johnfitz -- this does everything that should be done once per call to RenderScene -#ifndef VITA + Fog_EnableGFog (); //johnfitz -#endif + Sky_DrawSky (); //johnfitz R_DrawWorld (); @@ -1185,12 +1187,12 @@ void R_RenderScene (void) R_RenderDlights (); //triangle fan dlights -- johnfitz -- moved after water + Fog_DisableGFog (); //johnfitz + R_DrawParticles (); QMB_DrawParticles(); -#ifndef VITA - Fog_DisableGFog (); //johnfitz -#endif + R_DrawViewModel (); //johnfitz -- moved here from R_RenderView R_DrawView2Model (); diff --git a/source/gl_sky.c b/source/gl_sky.c index 1cf43f6..8d0a3f8 100644 --- a/source/gl_sky.c +++ b/source/gl_sky.c @@ -1026,7 +1026,7 @@ void Sky_DrawSky (void) glDepthMask(1); glDepthFunc(GL_LEQUAL); } -#ifndef VITA + Fog_EnableGFog (); -#endif + } diff --git a/source/r_alias.c b/source/r_alias.c index d078565..441d183 100644 --- a/source/r_alias.c +++ b/source/r_alias.c @@ -28,6 +28,10 @@ extern cvar_t r_drawflat, gl_overbright_models, gl_fullbrights, r_lerpmodels, r_ extern cvar_t scr_fov_viewmodel; //sB porting seperate viewmodel FOV extern cvar_t scr_fov; +extern float fog_red; +extern float fog_green; +extern float fog_blue; + #include "mathlib.h" //up to 16 color translated skins @@ -88,6 +92,9 @@ static GLuint useAlphaTestLoc; static GLuint aliasgrayscale_enableLoc; #ifdef VITA static GLuint fogDensityLoc; +static GLuint fogRedLoc; +static GLuint fogGreenLoc; +static GLuint fogBlueLoc; #endif #define pose1VertexAttrIndex 0 @@ -180,6 +187,9 @@ void GLAlias_CreateShaders (void) "uniform int UseAlphaTest;\n" "uniform int gs_mod;\n" "uniform float fog_density;\n" + "uniform float fog_red;\n" + "uniform float fog_green;\n" + "uniform float fog_blue;\n" "\n" "float4 main(\n" " float4 coords : WPOS,\n" @@ -198,7 +208,7 @@ void GLAlias_CreateShaders (void) " float FogFragCoord = coords.z / coords.w;\n" " float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n" " fog = clamp(fog, 0.0, 1.0);\n" - " result = lerp(float4(0.3, 0.3, 0.3, 1.0), result, fog);\n" + " result = lerp(float4(fog_red, fog_green, fog_blue, 1.0), result, fog);\n" " result.a = gl_Color.a;\n" // FIXME: This will make almost transparent things cut holes though heavy fog " if (gs_mod) {\n" " float value = clamp((result.r * 0.33) + (result.g * 0.55) + (result.b * 0.11), 0.0, 1.0);\n" @@ -301,6 +311,9 @@ void GLAlias_CreateShaders (void) aliasgrayscale_enableLoc = GL_GetUniformLocation (&r_alias_program, "gs_mod"); #ifdef VITA fogDensityLoc = GL_GetUniformLocation(&r_alias_program, "fog_density"); + fogRedLoc = GL_GetUniformLocation(&r_alias_program, "fog_red"); + fogGreenLoc = GL_GetUniformLocation(&r_alias_program, "fog_green"); + fogBlueLoc = GL_GetUniformLocation(&r_alias_program, "fog_blue"); #endif } } @@ -363,6 +376,9 @@ void GL_DrawAliasFrame_GLSL (aliashdr_t *paliashdr, lerpdata_t lerpdata, gltextu GL_Uniform1iFunc (useAlphaTestLoc, (currententity->model->flags & MF_HOLEY) ? 1 : 0); #ifdef VITA GL_Uniform1fFunc (fogDensityLoc, Fog_GetDensity() / 64.0f); + GL_Uniform1fFunc (fogRedLoc, fog_red / 64.0f); + GL_Uniform1fFunc (fogGreenLoc, fog_green / 64.0f); + GL_Uniform1fFunc (fogBlueLoc, fog_blue / 64.0f); #endif // naievil -- experimental grayscale mod GL_Uniform1fFunc (aliasgrayscale_enableLoc, /*sv_player->v.renderGrayscale*/0); @@ -1191,13 +1207,9 @@ void R_DrawAliasModel (entity_t *e) glBlendFunc (GL_ONE, GL_ONE); glDepthMask(GL_FALSE); glColor3f(entalpha,entalpha,entalpha); -#ifndef VITA Fog_StartAdditive (); -#endif GL_DrawAliasFrame (paliashdr, lerpdata); -#ifndef VITA Fog_StopAdditive (); -#endif glDepthMask(GL_TRUE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); @@ -1258,13 +1270,9 @@ void R_DrawAliasModel (entity_t *e) glDepthMask(GL_FALSE); shading = false; glColor3f(entalpha,entalpha,entalpha); -#ifndef VITA Fog_StartAdditive (); -#endif GL_DrawAliasFrame (paliashdr, lerpdata); -#ifndef VITA Fog_StopAdditive (); -#endif glDepthMask(GL_TRUE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); @@ -1281,13 +1289,9 @@ void R_DrawAliasModel (entity_t *e) glEnable(GL_BLEND); glBlendFunc (GL_ONE, GL_ONE); glDepthMask(GL_FALSE); -#ifndef VITA Fog_StartAdditive (); -#endif GL_DrawAliasFrame (paliashdr, lerpdata); -#ifndef VITA Fog_StopAdditive (); -#endif glDepthMask(GL_TRUE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1302,13 +1306,9 @@ void R_DrawAliasModel (entity_t *e) glDepthMask(GL_FALSE); shading = false; glColor3f(entalpha,entalpha,entalpha); -#ifndef VITA Fog_StartAdditive (); -#endif GL_DrawAliasFrame (paliashdr, lerpdata); -#ifndef VITA Fog_StopAdditive (); -#endif glDepthMask(GL_TRUE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); @@ -1347,13 +1347,9 @@ void R_DrawAliasModel (entity_t *e) glDepthMask(GL_FALSE); shading = false; glColor3f(entalpha,entalpha,entalpha); -#ifndef VITA Fog_StartAdditive (); -#endif GL_DrawAliasFrame (paliashdr, lerpdata); -#ifndef VITA Fog_StopAdditive (); -#endif glDepthMask(GL_TRUE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); diff --git a/source/r_world.c b/source/r_world.c index 9517616..aa57876 100644 --- a/source/r_world.c +++ b/source/r_world.c @@ -28,6 +28,10 @@ extern cvar_t gl_fullbrights, r_drawflat, gl_overbright, r_oldwater, r_oldskylea extern glpoly_t *lightmap_polys[MAX_LIGHTMAPS]; +extern float fog_red; +extern float fog_green; +extern float fog_blue; + byte *SV_FatPVS (vec3_t org, qmodel_t *worldmodel); int vis_changed; //if true, force pvs to be refreshed @@ -818,6 +822,9 @@ static GLuint alphaLoc; static GLuint grayscale_enableLoc; #ifdef VITA static GLuint fogDensityLoc; +static GLuint fogRedLoc; +static GLuint fogGreenLoc; +static GLuint fogBlueLoc; #endif #define vertAttrIndex 0 @@ -863,6 +870,9 @@ void GLWorld_CreateShaders (void) "uniform float Alpha;\n" "uniform int gs_mod;\n" "uniform float fog_density;\n" + "uniform float fog_red;\n" + "uniform float fog_green;\n" + "uniform float fog_blue;\n" "\n" "float4 main(\n" " float4 coords : WPOS,\n" @@ -881,7 +891,7 @@ void GLWorld_CreateShaders (void) " float FogFragCoord = coords.z / coords.w;\n" " float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n" " fog = clamp(fog, 0.0, 1.0);\n" - " result = lerp(float4(0.3, 0.3, 0.3, 1.0), result, fog);\n" + " result = lerp(float4(fog_red, fog_green, fog_blue, 1.0), result, fog);\n" " result.a = Alpha;\n" // FIXME: This will make almost transparent things cut holes though heavy fog " if (gs_mod) {\n" " float value = clamp((result.r * 0.33) + (result.g * 0.55) + (result.b * 0.11), 0.0, 1.0);\n" @@ -968,6 +978,9 @@ void GLWorld_CreateShaders (void) grayscale_enableLoc = GL_GetUniformLocation (&r_world_program, "gs_mod"); #ifdef VITA fogDensityLoc = GL_GetUniformLocation(&r_world_program, "fog_density"); + fogRedLoc = GL_GetUniformLocation(&r_world_program, "fog_red"); + fogGreenLoc = GL_GetUniformLocation(&r_world_program, "fog_green"); + fogBlueLoc = GL_GetUniformLocation(&r_world_program, "fog_blue"); #endif } } @@ -1027,6 +1040,9 @@ void R_DrawTextureChains_GLSL (qmodel_t *model, entity_t *ent, texchain_t chain) GL_Uniform1fFunc (alphaLoc, entalpha); #ifdef VITA GL_Uniform1fFunc (fogDensityLoc, Fog_GetDensity() / 64.0f); + GL_Uniform1fFunc (fogRedLoc, fog_red / 64.0f); + GL_Uniform1fFunc (fogGreenLoc, fog_green / 64.0f); + GL_Uniform1fFunc (fogBlueLoc, fog_blue / 64.0f); #endif // naievil -- experimental grayscale shader @@ -1197,21 +1213,14 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain) //to make fog work with multipass lightmapping, need to do one pass //with no fog, one modulate pass with black fog, and one additive //pass with black geometry and normal fog -#ifndef VITA Fog_DisableGFog (); -#endif R_DrawTextureChains_TextureOnly (model, ent, chain); -#ifndef VITA Fog_EnableGFog (); -#endif glDepthMask (GL_FALSE); glEnable (GL_BLEND); glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); //2x modulate -#ifndef VITA Fog_StartAdditive (); -#endif R_DrawLightmapChains (); -#ifndef VITA Fog_StopAdditive (); if (Fog_GetDensity() > 0) { @@ -1222,7 +1231,6 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain) glColor3f(1,1,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } -#endif glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_BLEND); glDepthMask (GL_TRUE); @@ -1247,21 +1255,14 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain) //to make fog work with multipass lightmapping, need to do one pass //with no fog, one modulate pass with black fog, and one additive //pass with black geometry and normal fog -#ifndef VITA Fog_DisableGFog (); -#endif R_DrawTextureChains_TextureOnly (model, ent, chain); -#ifndef VITA Fog_EnableGFog (); -#endif glDepthMask (GL_FALSE); glEnable (GL_BLEND); glBlendFunc(GL_ZERO, GL_SRC_COLOR); //modulate -#ifndef VITA Fog_StartAdditive (); -#endif R_DrawLightmapChains (); -#ifndef VITA Fog_StopAdditive (); if (Fog_GetDensity() > 0) { @@ -1272,7 +1273,6 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain) glColor3f(1,1,1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); } -#endif glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable (GL_BLEND); glDepthMask (GL_TRUE); @@ -1289,13 +1289,9 @@ fullbrights: glBlendFunc (GL_ONE, GL_ONE); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glColor3f (entalpha, entalpha, entalpha); -#ifndef VITA Fog_StartAdditive (); -#endif R_DrawTextureChains_Glow (model, ent, chain); -#ifndef VITA Fog_StopAdditive (); -#endif glColor3f (1, 1, 1); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);