Skip to content

Commit

Permalink
Fix a bug that smoke particles from Counter-Strike were culled by par…
Browse files Browse the repository at this point in the history
…ticleman.dll because Legacy OpenGL matrix was corrupted after gamma blending.
  • Loading branch information
hzqst committed Jan 15, 2024
1 parent 99685d3 commit 646cd42
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 9 deletions.
6 changes: 3 additions & 3 deletions Build/svencoop/renderer/shader/studio_shader.fsh
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ vec3 R_StudioCelShade(vec3 v_color, vec3 normalWS, vec3 lightdirWS, float specul

#endif

#endif
#endif //defined(STUDIO_NF_CELSHADE_HAIR)

return v_color.xyz * litOrShadowColor + rimLightColor + rimDarkColor + specularColor;
}
} //R_StudioCelShade

#endif
#endif //defined(STUDIO_NF_CELSHADE)

#if defined(STUDIO_NF_CELSHADE_FACE) && defined(STUDIO_DEBUG_ENABLED)

Expand Down
4 changes: 3 additions & 1 deletion Plugins/Renderer/exportfuncs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ void V_CalcRefdef(struct ref_params_s *pparams)
memcpy(&r_params, pparams, sizeof(struct ref_params_s));
}

#if 0
void HUD_DrawTransparentTriangles(void)
{
//gExportfuncs.HUD_DrawTransparentTriangles();
gExportfuncs.HUD_DrawTransparentTriangles();
}
#endif

int HUD_Redraw(float time, int intermission)
{
Expand Down
2 changes: 2 additions & 0 deletions Plugins/Renderer/gl_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,8 @@ void GL_UploadSubDataToVBODynamicDraw(GLuint VBO, size_t offset, size_t size, co

void GL_UploadDataToEBOStaticDraw(GLuint EBO, size_t size, const void* data)
{
//TODO: what if size == 0 ?

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
if (glBufferStorage)
{
Expand Down
28 changes: 25 additions & 3 deletions Plugins/Renderer/gl_rmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,8 +903,8 @@ void R_DrawTransEntities(int onlyClientDraw)

glColorMask(1, 1, 1, 1);

GL_BlitFrameBufferToFrameBufferColorOnly(&s_BackBufferFBO, &s_BackBufferFBO2);
R_BlendOITBuffer(&s_BackBufferFBO2, &s_BackBufferFBO);
GL_BlitFrameBufferToFrameBufferColorOnly(GL_GetCurrentSceneFBO(), &s_BackBufferFBO2);
R_BlendOITBuffer(&s_BackBufferFBO2, GL_GetCurrentSceneFBO());

glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT);
}
Expand Down Expand Up @@ -1375,6 +1375,7 @@ void GL_FreeFrameBuffers(void)
GL_FreeFBO(&s_FinalBufferFBO);
GL_FreeFBO(&s_BackBufferFBO);
GL_FreeFBO(&s_BackBufferFBO2);
GL_FreeFBO(&s_BackBufferFBO3);
GL_FreeFBO(&s_GBufferFBO);
for (int i = 0; i < DOWNSAMPLE_BUFFERS; ++i)
GL_FreeFBO(&s_DownSampleFBO[i]);
Expand Down Expand Up @@ -1404,6 +1405,7 @@ void GL_GenerateFrameBuffers(void)
GL_GenFrameBuffer(&s_FinalBufferFBO);
GL_FrameBufferColorTexture(&s_FinalBufferFBO, GL_RGBA8);
GL_FrameBufferDepthTexture(&s_FinalBufferFBO, GL_DEPTH24_STENCIL8);
glDrawBuffer(GL_COLOR_ATTACHMENT0);

if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
{
Expand Down Expand Up @@ -2081,6 +2083,7 @@ void R_RenderView_SvEngine(int viewIdx)
else
{
GL_BindFrameBuffer(&s_FinalBufferFBO);
GL_SetCurrentSceneFBO(NULL);
}

(*c_alias_polys) += r_studio_polys;
Expand Down Expand Up @@ -2835,6 +2838,22 @@ void R_AdjustScopeFOVForViewModel(float *fov)
}
}

void R_UseLegacyOpenGLMatrixForViewModel()
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(r_viewmodel_projection_matrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(r_world_matrix);
}

void R_UseLegacyOpenGLMatrixForWorld()
{
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(r_projection_matrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(r_world_matrix);
}

void R_UseProjMatrixForViewModel(void)
{
scene_ubo_t SceneUBO;
Expand Down Expand Up @@ -3436,11 +3455,14 @@ void R_EndRenderOpaque(void)

if (R_IsGammaBlendEnabled())
{
R_GammaCorrection(GL_GetCurrentSceneFBO(), &s_BackBufferFBO3);
GL_BlitFrameBufferToFrameBufferDepthStencil(GL_GetCurrentSceneFBO(), &s_BackBufferFBO3);
R_GammaCorrection(GL_GetCurrentSceneFBO(), &s_BackBufferFBO3);
GL_SetCurrentSceneFBO(&s_BackBufferFBO3);
r_draw_gammablend = true;
}

//For backward compatibility, some Mods may use Legacy OpenGL 1.x Matrix
R_UseLegacyOpenGLMatrixForWorld();
}

void ClientDLL_DrawNormalTriangles(void)
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Renderer/gl_shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ void R_SaveProgramStatesCaches(const char *filename, const std::vector<program_s

#define SHADER_DEFINE(name) name##_program_t name;

#define SHADER_UNIFORM(name, loc, locstring) name##.loc = glGetUniformLocationARB(name.program, locstring);
#define SHADER_ATTRIB(name, loc, locstring) name##.loc = glGetAttribLocationARB(name.program, locstring);
#define SHADER_UNIFORM(name, loc, locstring) name##.loc = glGetUniformLocation(name.program, locstring);
#define SHADER_ATTRIB(name, loc, locstring) name##.loc = glGetAttribLocation(name.program, locstring);
1 change: 1 addition & 0 deletions Plugins/Renderer/gl_sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ void R_UseLegacySpriteProgram(program_state_t state, legacysprite_program_t *pro
auto def = defs.str();

prog.program = R_CompileShaderFileEx("renderer\\shader\\legacysprite_shader.vsh", "renderer\\shader\\legacysprite_shader.fsh", def.c_str(), def.c_str(), NULL);

if (prog.program)
{

Expand Down

0 comments on commit 646cd42

Please sign in to comment.