Skip to content

Commit

Permalink
1.Fix a bug that fog was unexpectedly activated by SCCameraFix.dll
Browse files Browse the repository at this point in the history
2.Fix a bug that sky fog was not correctly handled when r_light_dynamic set to 1.
  • Loading branch information
hzqst committed Mar 19, 2024
1 parent 5accd00 commit 1bb3eaf
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Build/svencoop/renderer/shader/dfinal_shader.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ void main()

vec4 finalColor = diffuseColor * lightmapColor;

#if !defined(SKY_FOG_ENABLED) && defined(TEXTURE_VIEW_AVAILABLE)
#if !defined(SKY_FOG_ENABLED)

uint stencilValue = texture(stencilTex, texCoord).r;

if((stencilValue & STENCIL_MASK_HAS_FOG) != 0)
if((stencilValue & STENCIL_MASK_HAS_FOG) == 0)
out_FragColor = finalColor;
else
out_FragColor = CalcFogWithDistance(finalColor, worldnormColor.z);
Expand Down
4 changes: 4 additions & 0 deletions Plugins/Renderer/gl_hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ void R_FillAddress(void)
gPrivateFuncs.triapi_RenderMode = gEngfuncs.pTriAPI->RenderMode;
gPrivateFuncs.triapi_GetMatrix = gEngfuncs.pTriAPI->GetMatrix;
gPrivateFuncs.triapi_BoxInPVS = gEngfuncs.pTriAPI->BoxInPVS;
gPrivateFuncs.triapi_Fog = gEngfuncs.pTriAPI->Fog;
//gPrivateFuncs.triapi_Color4f = gEngfuncs.pTriAPI->Color4f;

bHasOfficialFBOSupport = false;
Expand Down Expand Up @@ -7652,6 +7653,7 @@ static hook_t *g_phook_Mod_LoadSpriteModel = NULL;
static hook_t *g_phook_Mod_UnloadSpriteTextures = NULL;
static hook_t *g_phook_triapi_RenderMode = NULL;
static hook_t *g_phook_triapi_BoxInPVS = NULL;
static hook_t *g_phook_triapi_Fog = NULL;
static hook_t* g_phook_triapi_GetMatrix = NULL;
//static hook_t *g_phook_triapi_Color4f = NULL;
static hook_t *g_phook_Draw_MiptexTexture = NULL;
Expand Down Expand Up @@ -7696,6 +7698,7 @@ void R_UninstallHooksForEngineDLL(void)
Uninstall_Hook(Mod_UnloadSpriteTextures);
Uninstall_Hook(triapi_RenderMode);
Uninstall_Hook(triapi_BoxInPVS);
//Uninstall_Hook(triapi_Fog);
Uninstall_Hook(triapi_GetMatrix);
Uninstall_Hook(Draw_MiptexTexture);
Uninstall_Hook(BuildGammaTable);
Expand Down Expand Up @@ -7743,6 +7746,7 @@ void R_InstallHooks(void)
Install_InlineHook(Mod_UnloadSpriteTextures);
Install_InlineHook(triapi_RenderMode);
Install_InlineHook(triapi_BoxInPVS);
//Install_InlineHook(triapi_Fog);
Install_InlineHook(triapi_GetMatrix);
Install_InlineHook(Draw_MiptexTexture);
Install_InlineHook(BuildGammaTable);
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ void GL_EnableMultitexture(void);
void triapi_RenderMode(int mode);
int triapi_BoxInPVS(float* mins, float* maxs);
void triapi_GetMatrix(const int pname, float* matrix);
void triapi_Fog(float* flFogColor, float flStart, float flEnd, BOOL bOn);
//void triapi_Color4f(float x, float y, float z, float w);
void GL_UnloadTextureByIdentifier(const char* identifier, bool notify_callback);
void GL_UnloadTextures(void);
Expand Down
5 changes: 5 additions & 0 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,11 @@ int triapi_BoxInPVS(float* mins, float* maxs)
return R_PVSNode(r_worldmodel->nodes, mins, maxs) != NULL;
}

void triapi_Fog(float* flFogColor, float flStart, float flEnd, BOOL bOn)
{
gPrivateFuncs.triapi_Fog(flFogColor, flStart, flEnd, bOn);
}

void triapi_RenderMode(int mode)
{
gPrivateFuncs.triapi_RenderMode(mode);
Expand Down
1 change: 1 addition & 0 deletions Plugins/Renderer/privatehook.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ typedef struct
void(*triapi_RenderMode)(int mode);
void(*triapi_GetMatrix) (const int pname, float* matrix);
int (*triapi_BoxInPVS)(float* mins, float* maxs);
void (*triapi_Fog)(float* flFogColor, float flStart, float flEnd, BOOL bOn);
//void(*triapi_Color4f) (float r, float g, float b, float a);
enginesurface_Texture* (*staticGetTextureById)(int id);
void(__fastcall* enginesurface_drawSetTextureRGBA)(void* pthis, int, int textureId, const char* data, int wide, int tall, qboolean hardwareFilter, qboolean hasAlphaChannel);
Expand Down
3 changes: 3 additions & 0 deletions Plugins/SCCameraFix/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,11 +979,14 @@ void V_CalcRefdef(struct ref_params_s* pparams)
#endif
gExportfuncs.V_CalcRefdef(pparams);

#if 0
vec3_t fogColor;
fogColor[0] = g_iFogColor_SCClient[0] / 255.0f;
fogColor[1] = g_iFogColor_SCClient[1] / 255.0f;
fogColor[2] = g_iFogColor_SCClient[2] / 255.0f;
gEngfuncs.pTriAPI->Fog(fogColor, (*g_iStartDist_SCClient), (*g_iEndDist_SCClient), true);
#endif

}

void HUD_Init(void)
Expand Down
2 changes: 1 addition & 1 deletion Plugins/SCCameraFix/plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void IPluginsV4::LoadClient(cl_exportfuncs_t *pExportFunc)

pExportFunc->CAM_Think = CAM_Think;
pExportFunc->HUD_Init = HUD_Init;
pExportFunc->V_CalcRefdef = V_CalcRefdef;
//pExportFunc->V_CalcRefdef = V_CalcRefdef;

Client_FillAddress();
Client_InstallHooks();
Expand Down

0 comments on commit 1bb3eaf

Please sign in to comment.