- Uniform buffer for colormap shader

This commit is contained in:
Magnus Norddahl 2018-06-11 21:03:55 +02:00
parent d22fb24e28
commit 2bde741a7e
4 changed files with 24 additions and 9 deletions

View file

@ -529,8 +529,9 @@ void FGLRenderer::ColormapScene(int fixedcm)
float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0], float m[] = { scm->ColorizeEnd[0] - scm->ColorizeStart[0],
scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f }; scm->ColorizeEnd[1] - scm->ColorizeStart[1], scm->ColorizeEnd[2] - scm->ColorizeStart[2], 0.f };
mColormapShader->MapStart.Set(scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f); mColormapShader->Uniforms->MapStart = { scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f };
mColormapShader->MapRange.Set(m); mColormapShader->Uniforms->MapRange = m;
mColormapShader->Uniforms.Set();
RenderScreenQuad(); RenderScreenQuad();
mBuffers->NextTexture(); mBuffers->NextTexture();

View file

@ -34,13 +34,14 @@ void FColormapShader::Bind()
auto &shader = mShader; auto &shader = mShader;
if (!shader) if (!shader)
{ {
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330); shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/colormap.fp", "", 330); shader.Compile(FShaderProgram::Fragment, "shaders/glsl/colormap.fp", prolog, 330);
shader.SetFragDataLocation(0, "FragColor"); shader.SetFragDataLocation(0, "FragColor");
shader.Link("shaders/glsl/colormap"); shader.Link("shaders/glsl/colormap");
shader.SetAttribLocation(0, "PositionInProjection"); shader.SetAttribLocation(0, "PositionInProjection");
MapStart.Init(shader, "uFixedColormapStart"); Uniforms.Init(shader);
MapRange.Init(shader, "uFixedColormapRange");
} }
shader.Bind(); shader.Bind();
} }

View file

@ -9,8 +9,23 @@ public:
void Bind(); void Bind();
FBufferedUniformSampler SceneTexture; FBufferedUniformSampler SceneTexture;
FUniform4f MapStart;
FUniform4f MapRange; struct UniformBlock
{
FVector4 MapStart;
FVector4 MapRange;
static std::vector<UniformFieldDesc> Desc()
{
return
{
{ "uFixedColormapStart", UniformType::Vec4, offsetof(UniformBlock, MapStart) },
{ "uFixedColormapRange", UniformType::Vec4, offsetof(UniformBlock, MapRange) },
};
}
};
ShaderUniforms<UniformBlock> Uniforms;
private: private:

View file

@ -3,8 +3,6 @@ in vec2 TexCoord;
out vec4 FragColor; out vec4 FragColor;
uniform sampler2D tex; uniform sampler2D tex;
uniform vec4 uFixedColormapStart;
uniform vec4 uFixedColormapRange;
void main() void main()
{ {