diff --git a/rsrc/shaders/hud_frag.glsl b/rsrc/shaders/hud_frag.glsl index b418de35..59c7a716 100644 --- a/rsrc/shaders/hud_frag.glsl +++ b/rsrc/shaders/hud_frag.glsl @@ -3,11 +3,11 @@ in vec4 fragmentColor; in vec3 fragmentNormal; +uniform float ambient = 0.0; uniform float lights_active = 1.0; out vec4 color; -float ambient = 0.7; vec3 light0 = vec3(-0.136808053, -0.282842726, 0.375877053); vec3 light1 = vec3(0.102606051, -0.102606043, -0.281907797); vec3 lightColor = vec3(1, 1, 1); diff --git a/src/game/CAvaraGame.cpp b/src/game/CAvaraGame.cpp index 4ab26542..a1e9cc25 100755 --- a/src/game/CAvaraGame.cpp +++ b/src/game/CAvaraGame.cpp @@ -612,7 +612,7 @@ void CAvaraGame::EndScript() { itsView->ambientLight = ReadFixedVar(iAmbient); itsView->ambientLightColor = ARGBColor::Parse(ReadStringVar(iAmbientColor)) .value_or(DEFAULT_LIGHT_COLOR); - AvaraGLSetAmbient(ToFloat(itsView->ambientLight), itsView->ambientLightColor); + AvaraGLSetAmbient(ToFloat(itsView->ambientLight), itsView->ambientLightColor, Shader::World); for (i = 0; i < 4; i++) { intensity = ReadFixedVar(iLightsTable + 4 * i); diff --git a/src/util/AvaraGL.cpp b/src/util/AvaraGL.cpp index 10ca02d3..d0ab5e5f 100644 --- a/src/util/AvaraGL.cpp +++ b/src/util/AvaraGL.cpp @@ -86,7 +86,7 @@ GLuint light2Loc, light2ColorLoc; GLuint light3Loc, light3ColorLoc; GLuint hudProgram; -GLuint hudViewLoc, hudProjLoc, hudMvLoc, hudLightsActiveLoc; +GLuint hudViewLoc, hudProjLoc, hudMvLoc, hudAmbientLoc, hudLightsActiveLoc; GLuint skyProgram; GLuint skyVertArray, skyBuffer; @@ -189,15 +189,20 @@ void AvaraGLSetLight(int light_index, float intensity, float elevation, float az } } -void AvaraGLSetAmbient(float ambient, ARGBColor color) { +void AvaraGLSetAmbient(float ambient, ARGBColor color, Shader shader) { if (!actuallyRender) return; float rgb[3]; color.ExportGLFloats(rgb, 3); - glUseProgram(gProgram); - glUniform1f(ambLoc, ambient); - glUniform3fv(ambColorLoc, 1, rgb); + if (shader == Shader::HUD) { + glUseProgram(hudProgram); + glUniform1f(hudAmbientLoc, ambient); + } else { + glUseProgram(gProgram); + glUniform1f(ambLoc, ambient); + glUniform3fv(ambColorLoc, 1, rgb); + } } void ActivateLights(float active, Shader shader) { @@ -217,7 +222,8 @@ void AvaraGLLightDefaults() { AvaraGLSetLight(1, 0.3f, 20.0f, 200.0f, DEFAULT_LIGHT_COLOR); AvaraGLSetLight(2, 0, 0, 0, DEFAULT_LIGHT_COLOR); AvaraGLSetLight(3, 0, 0, 0, DEFAULT_LIGHT_COLOR); - AvaraGLSetAmbient(0.4f, DEFAULT_LIGHT_COLOR); + AvaraGLSetAmbient(0.4f, DEFAULT_LIGHT_COLOR, Shader::World); + AvaraGLSetAmbient(0.7f, DEFAULT_LIGHT_COLOR, Shader::HUD); } void SetTransforms(CBSPPart *part, Shader shader) { @@ -292,6 +298,7 @@ void AvaraGLInitContext() { hudViewLoc = glGetUniformLocation(hudProgram, "view"); hudProjLoc = glGetUniformLocation(hudProgram, "proj"); hudMvLoc = glGetUniformLocation(hudProgram, "modelview"); + hudAmbientLoc = glGetUniformLocation(hudProgram, "ambient"); hudLightsActiveLoc = glGetUniformLocation(hudProgram, "lights_active"); glCheckErrors(); @@ -350,13 +357,11 @@ void AvaraGLDrawPolygons(CBSPPart* part, Shader shader) { float extra_amb = ToFloat(part->extraAmbient); float current_amb = ToFloat(part->currentView->ambientLight); - if (shader == Shader::World) { - if (part->privateAmbient != -1) { - AvaraGLSetAmbient(ToFloat(part->privateAmbient), part->currentView->ambientLightColor); - } - if (extra_amb > 0) { - AvaraGLSetAmbient(current_amb + extra_amb, part->currentView->ambientLightColor); - } + if (part->privateAmbient != -1) { + AvaraGLSetAmbient(ToFloat(part->privateAmbient), part->currentView->ambientLightColor, shader); + } + if (extra_amb > 0) { + AvaraGLSetAmbient(current_amb + extra_amb, part->currentView->ambientLightColor, shader); } if (part->ignoreDirectionalLights) { ActivateLights(0, shader); @@ -378,11 +383,9 @@ void AvaraGLDrawPolygons(CBSPPart* part, Shader shader) { glDisableVertexAttribArray(2); // restore previous lighting state - if (shader == Shader::World) { - if (part->privateAmbient != -1 || extra_amb > 0) { - AvaraGLSetAmbient(current_amb, part->currentView->ambientLightColor); - glCheckErrors(); - } + if (part->privateAmbient != -1 || extra_amb > 0) { + AvaraGLSetAmbient(current_amb, part->currentView->ambientLightColor, shader); + glCheckErrors(); } if (part->ignoreDirectionalLights) { ActivateLights(1, shader); diff --git a/src/util/AvaraGL.h b/src/util/AvaraGL.h index de1043dc..85225387 100644 --- a/src/util/AvaraGL.h +++ b/src/util/AvaraGL.h @@ -31,13 +31,13 @@ class CWorldShader; #define GLAD_DEBUG -enum struct Shader { World, HUD, Sky }; +enum struct Shader { World, HUD }; GLuint LoadShaders(std::optional vertex_file_path, std::optional fragment_file_path); void AvaraGLSetLight(int light, float intensity, float elevation, float azimuth, ARGBColor color); void AvaraGLSetDepthTest(bool doTest); -void AvaraGLSetAmbient(float ambient, ARGBColor color); +void AvaraGLSetAmbient(float ambient, ARGBColor color, Shader shader = Shader::World); void AvaraGLSetView(glm::mat4 view); void AvaraGLSetFOV(float fov); void AvaraGLUpdateProjectionMatrix();