mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 14:51:51 +00:00
- uniform buffers for the present and shadowmap shaders
This commit is contained in:
parent
6fcc79d72a
commit
48f753061a
15 changed files with 87 additions and 71 deletions
|
@ -52,7 +52,8 @@ void FShadowMap::Update()
|
||||||
GLRenderer->mBuffers->BindShadowMapFB();
|
GLRenderer->mBuffers->BindShadowMapFB();
|
||||||
|
|
||||||
GLRenderer->mShadowMapShader->Bind();
|
GLRenderer->mShadowMapShader->Bind();
|
||||||
GLRenderer->mShadowMapShader->ShadowmapQuality.Set(gl_shadowmap_quality);
|
GLRenderer->mShadowMapShader->Uniforms->ShadowmapQuality = gl_shadowmap_quality;
|
||||||
|
GLRenderer->mShadowMapShader->Uniforms.Set();
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, mLightList);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, mLightList);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, mNodesBuffer);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, mNodesBuffer);
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mLinesBuffer);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, mLinesBuffer);
|
||||||
|
|
|
@ -735,20 +735,21 @@ void FGLRenderer::DrawPresentTexture(const IntRect &box, bool applyGamma)
|
||||||
mPresentShader->InputTexture.Set(0);
|
mPresentShader->InputTexture.Set(0);
|
||||||
if (!applyGamma || framebuffer->IsHWGammaActive())
|
if (!applyGamma || framebuffer->IsHWGammaActive())
|
||||||
{
|
{
|
||||||
mPresentShader->InvGamma.Set(1.0f);
|
mPresentShader->Uniforms->InvGamma = 1.0f;
|
||||||
mPresentShader->Contrast.Set(1.0f);
|
mPresentShader->Uniforms->Contrast = 1.0f;
|
||||||
mPresentShader->Brightness.Set(0.0f);
|
mPresentShader->Uniforms->Brightness = 0.0f;
|
||||||
mPresentShader->Saturation.Set(1.0f);
|
mPresentShader->Uniforms->Saturation = 1.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mPresentShader->InvGamma.Set(1.0f / clamp<float>(Gamma, 0.1f, 4.f));
|
mPresentShader->Uniforms->InvGamma = 1.0f / clamp<float>(Gamma, 0.1f, 4.f);
|
||||||
mPresentShader->Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
|
mPresentShader->Uniforms->Contrast = clamp<float>(vid_contrast, 0.1f, 3.f);
|
||||||
mPresentShader->Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
|
mPresentShader->Uniforms->Brightness = clamp<float>(vid_brightness, -0.8f, 0.8f);
|
||||||
mPresentShader->Saturation.Set(clamp<float>(vid_saturation, -15.0f, 15.f));
|
mPresentShader->Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.f);
|
||||||
mPresentShader->GrayFormula.Set(static_cast<int>(gl_satformula));
|
mPresentShader->Uniforms->GrayFormula = static_cast<int>(gl_satformula);
|
||||||
}
|
}
|
||||||
mPresentShader->Scale.Set(screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight());
|
mPresentShader->Uniforms->Scale = { screen->mScreenViewport.width / (float)mBuffers->GetWidth(), screen->mScreenViewport.height / (float)mBuffers->GetHeight() };
|
||||||
|
mPresentShader->Uniforms.Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ void FPresentStereoShaderBase::Init(const char * vtx_shader_name, const char * p
|
||||||
FPresentShaderBase::Init(vtx_shader_name, program_name);
|
FPresentShaderBase::Init(vtx_shader_name, program_name);
|
||||||
LeftEyeTexture.Init(mShader, "LeftEyeTexture");
|
LeftEyeTexture.Init(mShader, "LeftEyeTexture");
|
||||||
RightEyeTexture.Init(mShader, "RightEyeTexture");
|
RightEyeTexture.Init(mShader, "RightEyeTexture");
|
||||||
WindowPositionParity.Init(mShader, "WindowPositionParity");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FPresent3DCheckerShader::Bind()
|
void FPresent3DCheckerShader::Bind()
|
||||||
|
|
|
@ -36,7 +36,6 @@ class FPresentStereoShaderBase : public FPresentShaderBase
|
||||||
public:
|
public:
|
||||||
FBufferedUniformSampler LeftEyeTexture;
|
FBufferedUniformSampler LeftEyeTexture;
|
||||||
FBufferedUniformSampler RightEyeTexture;
|
FBufferedUniformSampler RightEyeTexture;
|
||||||
FBufferedUniform1i WindowPositionParity;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void Init(const char * vtx_shader_name, const char * program_name) override;
|
void Init(const char * vtx_shader_name, const char * program_name) override;
|
||||||
|
|
|
@ -31,18 +31,15 @@
|
||||||
|
|
||||||
void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program_name)
|
void FPresentShaderBase::Init(const char * vtx_shader_name, const char * program_name)
|
||||||
{
|
{
|
||||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", "", 330);
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
mShader.Compile(FShaderProgram::Fragment, vtx_shader_name, "", 330);
|
|
||||||
|
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquadscale.vp", prolog, 330);
|
||||||
|
mShader.Compile(FShaderProgram::Fragment, vtx_shader_name, prolog, 330);
|
||||||
mShader.SetFragDataLocation(0, "FragColor");
|
mShader.SetFragDataLocation(0, "FragColor");
|
||||||
mShader.Link(program_name);
|
mShader.Link(program_name);
|
||||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||||
mShader.SetAttribLocation(1, "UV");
|
mShader.SetAttribLocation(1, "UV");
|
||||||
InvGamma.Init(mShader, "InvGamma");
|
Uniforms.Init(mShader);
|
||||||
Contrast.Init(mShader, "Contrast");
|
|
||||||
Brightness.Init(mShader, "Brightness");
|
|
||||||
Saturation.Init(mShader, "Saturation");
|
|
||||||
GrayFormula.Init(mShader, "GrayFormula");
|
|
||||||
Scale.Init(mShader, "UVScale");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FPresentShader::Bind()
|
void FPresentShader::Bind()
|
||||||
|
|
|
@ -9,12 +9,32 @@ public:
|
||||||
virtual ~FPresentShaderBase() {}
|
virtual ~FPresentShaderBase() {}
|
||||||
virtual void Bind() = 0;
|
virtual void Bind() = 0;
|
||||||
|
|
||||||
FBufferedUniform1f InvGamma;
|
struct UniformBlock
|
||||||
FBufferedUniform1f Contrast;
|
{
|
||||||
FBufferedUniform1f Brightness;
|
float InvGamma;
|
||||||
FBufferedUniform1f Saturation;
|
float Contrast;
|
||||||
FBufferedUniform1i GrayFormula;
|
float Brightness;
|
||||||
FBufferedUniform2f Scale;
|
float Saturation;
|
||||||
|
int GrayFormula;
|
||||||
|
int WindowPositionParity; // top-of-window might not be top-of-screen
|
||||||
|
FVector2 Scale;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "InvGamma", UniformType::Float, offsetof(UniformBlock, InvGamma) },
|
||||||
|
{ "Contrast", UniformType::Float, offsetof(UniformBlock, Contrast) },
|
||||||
|
{ "Brightness", UniformType::Float, offsetof(UniformBlock, Brightness) },
|
||||||
|
{ "Saturation", UniformType::Float, offsetof(UniformBlock, Saturation) },
|
||||||
|
{ "GrayFormula", UniformType::Int, offsetof(UniformBlock, GrayFormula) },
|
||||||
|
{ "WindowPositionParity", UniformType::Int, offsetof(UniformBlock, WindowPositionParity) },
|
||||||
|
{ "UVScale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void Init(const char * vtx_shader_name, const char * program_name);
|
virtual void Init(const char * vtx_shader_name, const char * program_name);
|
||||||
|
|
|
@ -28,12 +28,14 @@ void FShadowMapShader::Bind()
|
||||||
{
|
{
|
||||||
if (!mShader)
|
if (!mShader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
|
||||||
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430);
|
mShader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 430);
|
||||||
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", "", 430);
|
mShader.Compile(FShaderProgram::Fragment, "shaders/glsl/shadowmap.fp", prolog, 430);
|
||||||
mShader.SetFragDataLocation(0, "FragColor");
|
mShader.SetFragDataLocation(0, "FragColor");
|
||||||
mShader.Link("shaders/glsl/shadowmap");
|
mShader.Link("shaders/glsl/shadowmap");
|
||||||
mShader.SetAttribLocation(0, "PositionInProjection");
|
mShader.SetAttribLocation(0, "PositionInProjection");
|
||||||
ShadowmapQuality.Init(mShader, "ShadowmapQuality");
|
Uniforms.Init(mShader);
|
||||||
}
|
}
|
||||||
mShader.Bind();
|
mShader.Bind();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,24 @@ class FShadowMapShader
|
||||||
public:
|
public:
|
||||||
void Bind();
|
void Bind();
|
||||||
|
|
||||||
FBufferedUniform1f ShadowmapQuality;
|
struct UniformBlock
|
||||||
|
{
|
||||||
|
float ShadowmapQuality;
|
||||||
|
float Padding0, Padding1, Padding2;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "ShadowmapQuality", UniformType::Float, offsetof(UniformBlock, ShadowmapQuality) },
|
||||||
|
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||||
|
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||||
|
{ "Padding2", UniformType::Float, offsetof(UniformBlock, Padding2) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FShaderProgram mShader;
|
FShaderProgram mShader;
|
||||||
|
|
|
@ -101,22 +101,24 @@ static void prepareInterleavedPresent(FPresentStereoShaderBase& shader)
|
||||||
|
|
||||||
if ( GLRenderer->framebuffer->IsHWGammaActive() )
|
if ( GLRenderer->framebuffer->IsHWGammaActive() )
|
||||||
{
|
{
|
||||||
shader.InvGamma.Set(1.0f);
|
shader.Uniforms->InvGamma = 1.0f;
|
||||||
shader.Contrast.Set(1.0f);
|
shader.Uniforms->Contrast = 1.0f;
|
||||||
shader.Brightness.Set(0.0f);
|
shader.Uniforms->Brightness = 0.0f;
|
||||||
shader.Saturation.Set(1.0f);
|
shader.Uniforms->Saturation = 1.0f;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shader.InvGamma.Set(1.0f / clamp<float>(Gamma, 0.1f, 4.f));
|
shader.Uniforms->InvGamma = 1.0f / clamp<float>(Gamma, 0.1f, 4.f);
|
||||||
shader.Contrast.Set(clamp<float>(vid_contrast, 0.1f, 3.f));
|
shader.Uniforms->Contrast = clamp<float>(vid_contrast, 0.1f, 3.f);
|
||||||
shader.Brightness.Set(clamp<float>(vid_brightness, -0.8f, 0.8f));
|
shader.Uniforms->Brightness = clamp<float>(vid_brightness, -0.8f, 0.8f);
|
||||||
shader.Saturation.Set(clamp<float>(vid_saturation, -15.0f, 15.0f));
|
shader.Uniforms->Saturation = clamp<float>(vid_saturation, -15.0f, 15.0f);
|
||||||
shader.GrayFormula.Set(static_cast<int>(gl_satformula));
|
shader.Uniforms->GrayFormula = static_cast<int>(gl_satformula);
|
||||||
}
|
}
|
||||||
shader.Scale.Set(
|
shader.Uniforms->Scale = {
|
||||||
screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(),
|
screen->mScreenViewport.width / (float)GLRenderer->mBuffers->GetWidth(),
|
||||||
screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight());
|
screen->mScreenViewport.height / (float)GLRenderer->mBuffers->GetHeight()
|
||||||
|
};
|
||||||
|
shader.Uniforms.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
// fixme: I don't know how to get absolute window position on Mac and Linux
|
// fixme: I don't know how to get absolute window position on Mac and Linux
|
||||||
|
@ -147,13 +149,13 @@ void CheckerInterleaved3D::Present() const
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
GLRenderer->mPresent3dCheckerShader->WindowPositionParity.Set(
|
GLRenderer->mPresent3dCheckerShader->Uniforms->WindowPositionParity =
|
||||||
(windowVOffset
|
(windowVOffset
|
||||||
+ windowHOffset
|
+ windowHOffset
|
||||||
+ screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom
|
+ screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom
|
||||||
) % 2 // because we want the top pixel offset, but gl_FragCoord.y is the bottom pixel offset
|
) % 2; // because we want the top pixel offset, but gl_FragCoord.y is the bottom pixel offset
|
||||||
);
|
|
||||||
|
|
||||||
|
GLRenderer->mPresent3dCheckerShader->Uniforms.Set();
|
||||||
GLRenderer->RenderScreenQuad();
|
GLRenderer->RenderScreenQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +192,8 @@ void ColumnInterleaved3D::Present() const
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
GLRenderer->mPresent3dColumnShader->WindowPositionParity.Set(windowHOffset);
|
GLRenderer->mPresent3dColumnShader->Uniforms->WindowPositionParity = windowHOffset;
|
||||||
|
GLRenderer->mPresent3dColumnShader->Uniforms.Set();
|
||||||
|
|
||||||
GLRenderer->RenderScreenQuad();
|
GLRenderer->RenderScreenQuad();
|
||||||
}
|
}
|
||||||
|
@ -212,12 +215,12 @@ void RowInterleaved3D::Present() const
|
||||||
}
|
}
|
||||||
#endif // _WIN32
|
#endif // _WIN32
|
||||||
|
|
||||||
GLRenderer->mPresent3dRowShader->WindowPositionParity.Set(
|
GLRenderer->mPresent3dRowShader->Uniforms->WindowPositionParity =
|
||||||
(windowVOffset
|
(windowVOffset
|
||||||
+ screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom
|
+ screen->mOutputLetterbox.height + 1 // +1 because of origin at bottom
|
||||||
) % 2
|
) % 2;
|
||||||
);
|
|
||||||
|
|
||||||
|
GLRenderer->mPresent3dColumnShader->Uniforms.Set();
|
||||||
GLRenderer->RenderScreenQuad();
|
GLRenderer->RenderScreenQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,11 +3,6 @@ in vec2 TexCoord;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D InputTexture;
|
uniform sampler2D InputTexture;
|
||||||
uniform float InvGamma;
|
|
||||||
uniform float Contrast;
|
|
||||||
uniform float Brightness;
|
|
||||||
uniform float Saturation;
|
|
||||||
uniform int GrayFormula;
|
|
||||||
|
|
||||||
vec4 ApplyGamma(vec4 c)
|
vec4 ApplyGamma(vec4 c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,6 @@ out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D LeftEyeTexture;
|
uniform sampler2D LeftEyeTexture;
|
||||||
uniform sampler2D RightEyeTexture;
|
uniform sampler2D RightEyeTexture;
|
||||||
uniform float InvGamma;
|
|
||||||
uniform float Contrast;
|
|
||||||
uniform float Brightness;
|
|
||||||
uniform int WindowPositionParity; // top-of-window might not be top-of-screen
|
|
||||||
|
|
||||||
vec4 ApplyGamma(vec4 c)
|
vec4 ApplyGamma(vec4 c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,6 @@ out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D LeftEyeTexture;
|
uniform sampler2D LeftEyeTexture;
|
||||||
uniform sampler2D RightEyeTexture;
|
uniform sampler2D RightEyeTexture;
|
||||||
uniform float InvGamma;
|
|
||||||
uniform float Contrast;
|
|
||||||
uniform float Brightness;
|
|
||||||
uniform int WindowPositionParity; // top-of-window might not be top-of-screen
|
|
||||||
|
|
||||||
vec4 ApplyGamma(vec4 c)
|
vec4 ApplyGamma(vec4 c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,10 +4,6 @@ out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D LeftEyeTexture;
|
uniform sampler2D LeftEyeTexture;
|
||||||
uniform sampler2D RightEyeTexture;
|
uniform sampler2D RightEyeTexture;
|
||||||
uniform float InvGamma;
|
|
||||||
uniform float Contrast;
|
|
||||||
uniform float Brightness;
|
|
||||||
uniform int WindowPositionParity; // top-of-window might not be top-of-screen
|
|
||||||
|
|
||||||
vec4 ApplyGamma(vec4 c)
|
vec4 ApplyGamma(vec4 c)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
in vec4 PositionInProjection;
|
in vec4 PositionInProjection;
|
||||||
in vec2 UV;
|
in vec2 UV;
|
||||||
uniform vec2 UVScale;
|
|
||||||
out vec2 TexCoord;
|
out vec2 TexCoord;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
|
|
|
@ -2,11 +2,6 @@
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
// This constant must match the same constant in gl_shadowmap.h
|
|
||||||
// #define ShadowmapQuality 1024
|
|
||||||
//#define ShadowmapQuality 128
|
|
||||||
uniform float ShadowmapQuality;
|
|
||||||
|
|
||||||
struct GPUNode
|
struct GPUNode
|
||||||
{
|
{
|
||||||
vec2 aabb_min;
|
vec2 aabb_min;
|
||||||
|
|
Loading…
Reference in a new issue