diff --git a/src/gl/renderer/gl_postprocess.cpp b/src/gl/renderer/gl_postprocess.cpp index ce7e1ac617..a57b80b596 100644 --- a/src/gl/renderer/gl_postprocess.cpp +++ b/src/gl/renderer/gl_postprocess.cpp @@ -582,10 +582,11 @@ void FGLRenderer::LensDistortScene() mBuffers->BindCurrentTexture(0, GL_LINEAR); mLensShader->Bind(); mLensShader->InputTexture.Set(0); - mLensShader->AspectRatio.Set(aspect); - mLensShader->Scale.Set(scale); - mLensShader->LensDistortionCoefficient.Set(k); - mLensShader->CubicDistortionValue.Set(kcube); + mLensShader->Uniforms->AspectRatio = aspect; + mLensShader->Uniforms->Scale = scale; + mLensShader->Uniforms->LensDistortionCoefficient = k; + mLensShader->Uniforms->CubicDistortionValue = kcube; + mLensShader->Uniforms.Set(); RenderScreenQuad(); mBuffers->NextTexture(); diff --git a/src/gl/shaders/gl_lensshader.cpp b/src/gl/shaders/gl_lensshader.cpp index 96ec217a34..13945e8eba 100644 --- a/src/gl/shaders/gl_lensshader.cpp +++ b/src/gl/shaders/gl_lensshader.cpp @@ -33,16 +33,15 @@ void FLensShader::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/lensdistortion.fp", "", 330); + mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/lensdistortion.fp", prolog, 330); mShader.SetFragDataLocation(0, "FragColor"); mShader.Link("shaders/glsl/lensdistortion"); mShader.SetAttribLocation(0, "PositionInProjection"); InputTexture.Init(mShader, "InputTexture"); - AspectRatio.Init(mShader, "Aspect"); - Scale.Init(mShader, "Scale"); - LensDistortionCoefficient.Init(mShader, "k"); - CubicDistortionValue.Init(mShader, "kcube"); + Uniforms.Init(mShader); } mShader.Bind(); } diff --git a/src/gl/shaders/gl_lensshader.h b/src/gl/shaders/gl_lensshader.h index 7e9ef63926..ace6054cbd 100644 --- a/src/gl/shaders/gl_lensshader.h +++ b/src/gl/shaders/gl_lensshader.h @@ -9,10 +9,30 @@ public: void Bind(); FBufferedUniformSampler InputTexture; - FBufferedUniform1f AspectRatio; - FBufferedUniform1f Scale; - FBufferedUniform4f LensDistortionCoefficient; - FBufferedUniform4f CubicDistortionValue; + + struct UniformBlock + { + float AspectRatio; + float Scale; + float Padding0, Padding1; + FVector4 LensDistortionCoefficient; + FVector4 CubicDistortionValue; + + static std::vector Desc() + { + return + { + { "Aspect", UniformType::Float, offsetof(UniformBlock, AspectRatio) }, + { "Scale", UniformType::Float, offsetof(UniformBlock, Scale) }, + { "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) }, + { "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) }, + { "k", UniformType::Vec4, offsetof(UniformBlock, LensDistortionCoefficient) }, + { "kcube", UniformType::Vec4, offsetof(UniformBlock, CubicDistortionValue) } + }; + } + }; + + ShaderUniforms Uniforms; private: FShaderProgram mShader; diff --git a/wadsrc/static/shaders/glsl/lensdistortion.fp b/wadsrc/static/shaders/glsl/lensdistortion.fp index 7facf5a80b..d3cc5c7cad 100644 --- a/wadsrc/static/shaders/glsl/lensdistortion.fp +++ b/wadsrc/static/shaders/glsl/lensdistortion.fp @@ -33,10 +33,6 @@ in vec2 TexCoord; out vec4 FragColor; uniform sampler2D InputTexture; -uniform float Aspect; // image width/height -uniform float Scale; // 1/max(f) -uniform vec4 k; // lens distortion coefficient -uniform vec4 kcube; // cubic distortion value void main() {