mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 12:11:25 +00:00
- Uniform buffers for lens shader
This commit is contained in:
parent
763c5c9769
commit
d22fb24e28
4 changed files with 33 additions and 17 deletions
|
@ -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();
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<UniformFieldDesc> 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<UniformBlock> Uniforms;
|
||||
|
||||
private:
|
||||
FShaderProgram mShader;
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue