- 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],
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->MapRange.Set(m);
mColormapShader->Uniforms->MapStart = { scm->ColorizeStart[0], scm->ColorizeStart[1], scm->ColorizeStart[2], 0.f };
mColormapShader->Uniforms->MapRange = m;
mColormapShader->Uniforms.Set();
RenderScreenQuad();
mBuffers->NextTexture();

View File

@ -34,13 +34,14 @@ void FColormapShader::Bind()
auto &shader = mShader;
if (!shader)
{
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
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.Link("shaders/glsl/colormap");
shader.SetAttribLocation(0, "PositionInProjection");
MapStart.Init(shader, "uFixedColormapStart");
MapRange.Init(shader, "uFixedColormapRange");
Uniforms.Init(shader);
}
shader.Bind();
}

View File

@ -9,8 +9,23 @@ public:
void Bind();
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:

View File

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