NX/VITA: Proper fog implementation

This commit is contained in:
cypress 2023-09-02 22:01:12 -04:00
parent a8375fce89
commit e6827d3140
6 changed files with 45 additions and 53 deletions

View file

@ -552,7 +552,8 @@ void CL_RelinkEntities (void)
up_offset = up_offset/1000; up_offset = up_offset/1000;
forward_offset = forward_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 (start, forward_offset, v_forward ,smokeorg);
VectorMA (smokeorg, up_offset, v_up ,smokeorg); VectorMA (smokeorg, up_offset, v_up ,smokeorg);

View file

@ -299,11 +299,8 @@ float *Fog_GetColor (void)
for (i=0;i<3;i++) for (i=0;i<3;i++)
c[i] = (float)(Q_rint(c[i] * 255)) / 255.0f; 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++) for (i = 0; i < 3; i++)
c[i] /= 64.0; c[i] /= 64.0;
#endif // VITA
return c; return c;
} }

View file

@ -759,7 +759,9 @@ void R_DrawEntitiesOnList (qboolean alphapass) //johnfitz -- added parameter
{ {
case mod_sprite: case mod_sprite:
{ {
Fog_DisableGFog();
R_DrawSpriteModel (currententity); R_DrawSpriteModel (currententity);
Fog_EnableGFog();
break; break;
} }
case mod_alias: case mod_alias:
@ -1166,9 +1168,9 @@ R_RenderScene
void R_RenderScene (void) void R_RenderScene (void)
{ {
R_SetupScene (); //johnfitz -- this does everything that should be done once per call to RenderScene R_SetupScene (); //johnfitz -- this does everything that should be done once per call to RenderScene
#ifndef VITA
Fog_EnableGFog (); //johnfitz Fog_EnableGFog (); //johnfitz
#endif
Sky_DrawSky (); //johnfitz Sky_DrawSky (); //johnfitz
R_DrawWorld (); R_DrawWorld ();
@ -1185,12 +1187,12 @@ void R_RenderScene (void)
R_RenderDlights (); //triangle fan dlights -- johnfitz -- moved after water R_RenderDlights (); //triangle fan dlights -- johnfitz -- moved after water
Fog_DisableGFog (); //johnfitz
R_DrawParticles (); R_DrawParticles ();
QMB_DrawParticles(); QMB_DrawParticles();
#ifndef VITA
Fog_DisableGFog (); //johnfitz
#endif
R_DrawViewModel (); //johnfitz -- moved here from R_RenderView R_DrawViewModel (); //johnfitz -- moved here from R_RenderView
R_DrawView2Model (); R_DrawView2Model ();

View file

@ -1026,7 +1026,7 @@ void Sky_DrawSky (void)
glDepthMask(1); glDepthMask(1);
glDepthFunc(GL_LEQUAL); glDepthFunc(GL_LEQUAL);
} }
#ifndef VITA
Fog_EnableGFog (); Fog_EnableGFog ();
#endif
} }

View file

@ -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_viewmodel; //sB porting seperate viewmodel FOV
extern cvar_t scr_fov; extern cvar_t scr_fov;
extern float fog_red;
extern float fog_green;
extern float fog_blue;
#include "mathlib.h" #include "mathlib.h"
//up to 16 color translated skins //up to 16 color translated skins
@ -88,6 +92,9 @@ static GLuint useAlphaTestLoc;
static GLuint aliasgrayscale_enableLoc; static GLuint aliasgrayscale_enableLoc;
#ifdef VITA #ifdef VITA
static GLuint fogDensityLoc; static GLuint fogDensityLoc;
static GLuint fogRedLoc;
static GLuint fogGreenLoc;
static GLuint fogBlueLoc;
#endif #endif
#define pose1VertexAttrIndex 0 #define pose1VertexAttrIndex 0
@ -180,6 +187,9 @@ void GLAlias_CreateShaders (void)
"uniform int UseAlphaTest;\n" "uniform int UseAlphaTest;\n"
"uniform int gs_mod;\n" "uniform int gs_mod;\n"
"uniform float fog_density;\n" "uniform float fog_density;\n"
"uniform float fog_red;\n"
"uniform float fog_green;\n"
"uniform float fog_blue;\n"
"\n" "\n"
"float4 main(\n" "float4 main(\n"
" float4 coords : WPOS,\n" " float4 coords : WPOS,\n"
@ -198,7 +208,7 @@ void GLAlias_CreateShaders (void)
" float FogFragCoord = coords.z / coords.w;\n" " float FogFragCoord = coords.z / coords.w;\n"
" float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n" " float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n"
" fog = clamp(fog, 0.0, 1.0);\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 " result.a = gl_Color.a;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
" if (gs_mod) {\n" " if (gs_mod) {\n"
" float value = clamp((result.r * 0.33) + (result.g * 0.55) + (result.b * 0.11), 0.0, 1.0);\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"); aliasgrayscale_enableLoc = GL_GetUniformLocation (&r_alias_program, "gs_mod");
#ifdef VITA #ifdef VITA
fogDensityLoc = GL_GetUniformLocation(&r_alias_program, "fog_density"); 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 #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); GL_Uniform1iFunc (useAlphaTestLoc, (currententity->model->flags & MF_HOLEY) ? 1 : 0);
#ifdef VITA #ifdef VITA
GL_Uniform1fFunc (fogDensityLoc, Fog_GetDensity() / 64.0f); 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 #endif
// naievil -- experimental grayscale mod // naievil -- experimental grayscale mod
GL_Uniform1fFunc (aliasgrayscale_enableLoc, /*sv_player->v.renderGrayscale*/0); GL_Uniform1fFunc (aliasgrayscale_enableLoc, /*sv_player->v.renderGrayscale*/0);
@ -1191,13 +1207,9 @@ void R_DrawAliasModel (entity_t *e)
glBlendFunc (GL_ONE, GL_ONE); glBlendFunc (GL_ONE, GL_ONE);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
glColor3f(entalpha,entalpha,entalpha); glColor3f(entalpha,entalpha,entalpha);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
GL_DrawAliasFrame (paliashdr, lerpdata); GL_DrawAliasFrame (paliashdr, lerpdata);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -1258,13 +1270,9 @@ void R_DrawAliasModel (entity_t *e)
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
shading = false; shading = false;
glColor3f(entalpha,entalpha,entalpha); glColor3f(entalpha,entalpha,entalpha);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
GL_DrawAliasFrame (paliashdr, lerpdata); GL_DrawAliasFrame (paliashdr, lerpdata);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -1281,13 +1289,9 @@ void R_DrawAliasModel (entity_t *e)
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc (GL_ONE, GL_ONE); glBlendFunc (GL_ONE, GL_ONE);
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
GL_DrawAliasFrame (paliashdr, lerpdata); GL_DrawAliasFrame (paliashdr, lerpdata);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -1302,13 +1306,9 @@ void R_DrawAliasModel (entity_t *e)
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
shading = false; shading = false;
glColor3f(entalpha,entalpha,entalpha); glColor3f(entalpha,entalpha,entalpha);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
GL_DrawAliasFrame (paliashdr, lerpdata); GL_DrawAliasFrame (paliashdr, lerpdata);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -1347,13 +1347,9 @@ void R_DrawAliasModel (entity_t *e)
glDepthMask(GL_FALSE); glDepthMask(GL_FALSE);
shading = false; shading = false;
glColor3f(entalpha,entalpha,entalpha); glColor3f(entalpha,entalpha,entalpha);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
GL_DrawAliasFrame (paliashdr, lerpdata); GL_DrawAliasFrame (paliashdr, lerpdata);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glDepthMask(GL_TRUE); glDepthMask(GL_TRUE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND); glDisable(GL_BLEND);

View file

@ -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 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); byte *SV_FatPVS (vec3_t org, qmodel_t *worldmodel);
int vis_changed; //if true, force pvs to be refreshed int vis_changed; //if true, force pvs to be refreshed
@ -818,6 +822,9 @@ static GLuint alphaLoc;
static GLuint grayscale_enableLoc; static GLuint grayscale_enableLoc;
#ifdef VITA #ifdef VITA
static GLuint fogDensityLoc; static GLuint fogDensityLoc;
static GLuint fogRedLoc;
static GLuint fogGreenLoc;
static GLuint fogBlueLoc;
#endif #endif
#define vertAttrIndex 0 #define vertAttrIndex 0
@ -863,6 +870,9 @@ void GLWorld_CreateShaders (void)
"uniform float Alpha;\n" "uniform float Alpha;\n"
"uniform int gs_mod;\n" "uniform int gs_mod;\n"
"uniform float fog_density;\n" "uniform float fog_density;\n"
"uniform float fog_red;\n"
"uniform float fog_green;\n"
"uniform float fog_blue;\n"
"\n" "\n"
"float4 main(\n" "float4 main(\n"
" float4 coords : WPOS,\n" " float4 coords : WPOS,\n"
@ -881,7 +891,7 @@ void GLWorld_CreateShaders (void)
" float FogFragCoord = coords.z / coords.w;\n" " float FogFragCoord = coords.z / coords.w;\n"
" float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n" " float fog = exp(-fog_density * fog_density * FogFragCoord * FogFragCoord);\n"
" fog = clamp(fog, 0.0, 1.0);\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 " result.a = Alpha;\n" // FIXME: This will make almost transparent things cut holes though heavy fog
" if (gs_mod) {\n" " if (gs_mod) {\n"
" float value = clamp((result.r * 0.33) + (result.g * 0.55) + (result.b * 0.11), 0.0, 1.0);\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"); grayscale_enableLoc = GL_GetUniformLocation (&r_world_program, "gs_mod");
#ifdef VITA #ifdef VITA
fogDensityLoc = GL_GetUniformLocation(&r_world_program, "fog_density"); 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 #endif
} }
} }
@ -1027,6 +1040,9 @@ void R_DrawTextureChains_GLSL (qmodel_t *model, entity_t *ent, texchain_t chain)
GL_Uniform1fFunc (alphaLoc, entalpha); GL_Uniform1fFunc (alphaLoc, entalpha);
#ifdef VITA #ifdef VITA
GL_Uniform1fFunc (fogDensityLoc, Fog_GetDensity() / 64.0f); 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 #endif
// naievil -- experimental grayscale shader // 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 //to make fog work with multipass lightmapping, need to do one pass
//with no fog, one modulate pass with black fog, and one additive //with no fog, one modulate pass with black fog, and one additive
//pass with black geometry and normal fog //pass with black geometry and normal fog
#ifndef VITA
Fog_DisableGFog (); Fog_DisableGFog ();
#endif
R_DrawTextureChains_TextureOnly (model, ent, chain); R_DrawTextureChains_TextureOnly (model, ent, chain);
#ifndef VITA
Fog_EnableGFog (); Fog_EnableGFog ();
#endif
glDepthMask (GL_FALSE); glDepthMask (GL_FALSE);
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); //2x modulate glBlendFunc (GL_DST_COLOR, GL_SRC_COLOR); //2x modulate
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
R_DrawLightmapChains (); R_DrawLightmapChains ();
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
if (Fog_GetDensity() > 0) if (Fog_GetDensity() > 0)
{ {
@ -1222,7 +1231,6 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain)
glColor3f(1,1,1); glColor3f(1,1,1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} }
#endif
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_BLEND); glDisable (GL_BLEND);
glDepthMask (GL_TRUE); 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 //to make fog work with multipass lightmapping, need to do one pass
//with no fog, one modulate pass with black fog, and one additive //with no fog, one modulate pass with black fog, and one additive
//pass with black geometry and normal fog //pass with black geometry and normal fog
#ifndef VITA
Fog_DisableGFog (); Fog_DisableGFog ();
#endif
R_DrawTextureChains_TextureOnly (model, ent, chain); R_DrawTextureChains_TextureOnly (model, ent, chain);
#ifndef VITA
Fog_EnableGFog (); Fog_EnableGFog ();
#endif
glDepthMask (GL_FALSE); glDepthMask (GL_FALSE);
glEnable (GL_BLEND); glEnable (GL_BLEND);
glBlendFunc(GL_ZERO, GL_SRC_COLOR); //modulate glBlendFunc(GL_ZERO, GL_SRC_COLOR); //modulate
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
R_DrawLightmapChains (); R_DrawLightmapChains ();
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
if (Fog_GetDensity() > 0) if (Fog_GetDensity() > 0)
{ {
@ -1272,7 +1273,6 @@ void R_DrawTextureChains (qmodel_t *model, entity_t *ent, texchain_t chain)
glColor3f(1,1,1); glColor3f(1,1,1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
} }
#endif
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable (GL_BLEND); glDisable (GL_BLEND);
glDepthMask (GL_TRUE); glDepthMask (GL_TRUE);
@ -1289,13 +1289,9 @@ fullbrights:
glBlendFunc (GL_ONE, GL_ONE); glBlendFunc (GL_ONE, GL_ONE);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glColor3f (entalpha, entalpha, entalpha); glColor3f (entalpha, entalpha, entalpha);
#ifndef VITA
Fog_StartAdditive (); Fog_StartAdditive ();
#endif
R_DrawTextureChains_Glow (model, ent, chain); R_DrawTextureChains_Glow (model, ent, chain);
#ifndef VITA
Fog_StopAdditive (); Fog_StopAdditive ();
#endif
glColor3f (1, 1, 1); glColor3f (1, 1, 1);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);