diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index 3d513fc9e1..caeeaa0450 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -223,8 +223,9 @@ void FGLRenderer::UpdateCameraExposure() mBuffers->BindCurrentTexture(0, GL_LINEAR); mExposureExtractShader->Bind(); mExposureExtractShader->SceneTexture.Set(0); - mExposureExtractShader->Scale.Set(mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height); - mExposureExtractShader->Offset.Set(mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height); + mExposureExtractShader->Uniforms->Scale = { mSceneViewport.width / (float)mScreenViewport.width, mSceneViewport.height / (float)mScreenViewport.height }; + mExposureExtractShader->Uniforms->Offset = { mSceneViewport.left / (float)mScreenViewport.width, mSceneViewport.top / (float)mScreenViewport.height }; + mExposureExtractShader->Uniforms.Set(); RenderScreenQuad(); // Find the average value: @@ -257,10 +258,11 @@ void FGLRenderer::UpdateCameraExposure() mBuffers->ExposureLevels.Last().Texture.Bind(0); mExposureCombineShader->Bind(); mExposureCombineShader->ExposureTexture.Set(0); - mExposureCombineShader->ExposureBase.Set(gl_exposure_base); - mExposureCombineShader->ExposureMin.Set(gl_exposure_min); - mExposureCombineShader->ExposureScale.Set(gl_exposure_scale); - mExposureCombineShader->ExposureSpeed.Set(gl_exposure_speed); + mExposureCombineShader->Uniforms->ExposureBase = gl_exposure_base; + mExposureCombineShader->Uniforms->ExposureMin = gl_exposure_min; + mExposureCombineShader->Uniforms->ExposureScale = gl_exposure_scale; + mExposureCombineShader->Uniforms->ExposureSpeed = gl_exposure_speed; + mExposureCombineShader->Uniforms.Set(); RenderScreenQuad(); glViewport(mScreenViewport.left, mScreenViewport.top, mScreenViewport.width, mScreenViewport.height); diff --git a/src/gl/shaders/gl_tonemapshader.cpp b/src/gl/shaders/gl_tonemapshader.cpp index a5012833a4..d1254edb58 100644 --- a/src/gl/shaders/gl_tonemapshader.cpp +++ b/src/gl/shaders/gl_tonemapshader.cpp @@ -69,14 +69,15 @@ void FExposureExtractShader::Bind() { if (!mShader) { + FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()); + mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330); - mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureextract.fp", "", 330); + mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposureextract.fp", prolog, 330); mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/exposureextract"); mShader.SetAttribLocation(0, "PositionInProjection"); SceneTexture.Init(mShader, "SceneTexture"); - Scale.Init(mShader, "Scale"); - Offset.Init(mShader, "Offset"); + Uniforms.Init(mShader); } mShader.Bind(); } @@ -99,16 +100,15 @@ void FExposureCombineShader::Bind() { if (!mShader) { + FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc()); + mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330); - mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposurecombine.fp", "", 330); + mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/exposurecombine.fp", prolog, 330); mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/exposurecombine"); mShader.SetAttribLocation(0, "PositionInProjection"); ExposureTexture.Init(mShader, "ExposureTexture"); - ExposureBase.Init(mShader, "ExposureBase"); - ExposureMin.Init(mShader, "ExposureMin"); - ExposureScale.Init(mShader, "ExposureScale"); - ExposureSpeed.Init(mShader, "ExposureSpeed"); + Uniforms.Init(mShader); } mShader.Bind(); } \ No newline at end of file diff --git a/src/gl/shaders/gl_tonemapshader.h b/src/gl/shaders/gl_tonemapshader.h index b4cd102de6..8240320b11 100644 --- a/src/gl/shaders/gl_tonemapshader.h +++ b/src/gl/shaders/gl_tonemapshader.h @@ -37,8 +37,23 @@ public: void Bind(); FBufferedUniformSampler SceneTexture; - FBufferedUniform2f Scale; - FBufferedUniform2f Offset; + + struct UniformBlock + { + FVector2 Scale; + FVector2 Offset; + + static std::vector Desc() + { + return + { + { "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) }, + { "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) } + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShader; @@ -61,10 +76,27 @@ public: void Bind(); FBufferedUniformSampler ExposureTexture; - FBufferedUniform1f ExposureBase; - FBufferedUniform1f ExposureMin; - FBufferedUniform1f ExposureScale; - FBufferedUniform1f ExposureSpeed; + + struct UniformBlock + { + float ExposureBase; + float ExposureMin; + float ExposureScale; + float ExposureSpeed; + + static std::vector Desc() + { + return + { + { "ExposureBase", UniformType::Float, offsetof(UniformBlock, ExposureBase) }, + { "ExposureMin", UniformType::Float, offsetof(UniformBlock, ExposureMin) }, + { "ExposureScale", UniformType::Float, offsetof(UniformBlock, ExposureScale) }, + { "ExposureSpeed", UniformType::Float, offsetof(UniformBlock, ExposureSpeed) } + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShader; diff --git a/wadsrc/static/shaders/glsl/exposurecombine.fp b/wadsrc/static/shaders/glsl/exposurecombine.fp index f806f8f860..e4e7126bb6 100644 --- a/wadsrc/static/shaders/glsl/exposurecombine.fp +++ b/wadsrc/static/shaders/glsl/exposurecombine.fp @@ -3,10 +3,6 @@ in vec2 TexCoord; out vec4 FragColor; uniform sampler2D ExposureTexture; -uniform float ExposureBase; -uniform float ExposureMin; -uniform float ExposureScale; -uniform float ExposureSpeed; void main() { diff --git a/wadsrc/static/shaders/glsl/exposureextract.fp b/wadsrc/static/shaders/glsl/exposureextract.fp index f673bf0295..7a5b4f7a11 100644 --- a/wadsrc/static/shaders/glsl/exposureextract.fp +++ b/wadsrc/static/shaders/glsl/exposureextract.fp @@ -3,8 +3,6 @@ in vec2 TexCoord; out vec4 FragColor; uniform sampler2D SceneTexture; -uniform vec2 Scale; -uniform vec2 Offset; void main() {