mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-22 20:21:26 +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);
|
mBuffers->BindCurrentTexture(0, GL_LINEAR);
|
||||||
mLensShader->Bind();
|
mLensShader->Bind();
|
||||||
mLensShader->InputTexture.Set(0);
|
mLensShader->InputTexture.Set(0);
|
||||||
mLensShader->AspectRatio.Set(aspect);
|
mLensShader->Uniforms->AspectRatio = aspect;
|
||||||
mLensShader->Scale.Set(scale);
|
mLensShader->Uniforms->Scale = scale;
|
||||||
mLensShader->LensDistortionCoefficient.Set(k);
|
mLensShader->Uniforms->LensDistortionCoefficient = k;
|
||||||
mLensShader->CubicDistortionValue.Set(kcube);
|
mLensShader->Uniforms->CubicDistortionValue = kcube;
|
||||||
|
mLensShader->Uniforms.Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
mBuffers->NextTexture();
|
mBuffers->NextTexture();
|
||||||
|
|
||||||
|
|
|
@ -33,16 +33,15 @@ void FLensShader::Bind()
|
||||||
{
|
{
|
||||||
if (!mShader)
|
if (!mShader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
|
||||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
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.SetFragDataLocation(0, "FragColor");
|
||||||
mShader.Link("shaders/glsl/lensdistortion");
|
mShader.Link("shaders/glsl/lensdistortion");
|
||||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||||
InputTexture.Init(mShader, "InputTexture");
|
InputTexture.Init(mShader, "InputTexture");
|
||||||
AspectRatio.Init(mShader, "Aspect");
|
Uniforms.Init(mShader);
|
||||||
Scale.Init(mShader, "Scale");
|
|
||||||
LensDistortionCoefficient.Init(mShader, "k");
|
|
||||||
CubicDistortionValue.Init(mShader, "kcube");
|
|
||||||
}
|
}
|
||||||
mShader.Bind();
|
mShader.Bind();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,10 +9,30 @@ public:
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
FBufferedUniformSampler InputTexture;
|
FBufferedUniformSampler InputTexture;
|
||||||
FBufferedUniform1f AspectRatio;
|
|
||||||
FBufferedUniform1f Scale;
|
struct UniformBlock
|
||||||
FBufferedUniform4f LensDistortionCoefficient;
|
{
|
||||||
FBufferedUniform4f CubicDistortionValue;
|
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:
|
private:
|
||||||
FShaderProgram mShader;
|
FShaderProgram mShader;
|
||||||
|
|
|
@ -33,10 +33,6 @@ in vec2 TexCoord;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D InputTexture;
|
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()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue