mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-23 04:22:34 +00:00
- change ssao pass to use an uniform block
This commit is contained in:
parent
29d2e77840
commit
763c5c9769
9 changed files with 283 additions and 113 deletions
|
@ -118,13 +118,14 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
mLinearDepthShader->Bind();
|
mLinearDepthShader->Bind();
|
||||||
mLinearDepthShader->DepthTexture.Set(0);
|
mLinearDepthShader->DepthTexture.Set(0);
|
||||||
mLinearDepthShader->ColorTexture.Set(1);
|
mLinearDepthShader->ColorTexture.Set(1);
|
||||||
if (gl_multisample > 1) mLinearDepthShader->SampleIndex.Set(0);
|
if (gl_multisample > 1) mLinearDepthShader->Uniforms->SampleIndex = 0;
|
||||||
mLinearDepthShader->LinearizeDepthA.Set(1.0f / GetZFar() - 1.0f / GetZNear());
|
mLinearDepthShader->Uniforms->LinearizeDepthA = 1.0f / GetZFar() - 1.0f / GetZNear();
|
||||||
mLinearDepthShader->LinearizeDepthB.Set(MAX(1.0f / GetZNear(), 1.e-8f));
|
mLinearDepthShader->Uniforms->LinearizeDepthB = MAX(1.0f / GetZNear(), 1.e-8f);
|
||||||
mLinearDepthShader->InverseDepthRangeA.Set(1.0f);
|
mLinearDepthShader->Uniforms->InverseDepthRangeA = 1.0f;
|
||||||
mLinearDepthShader->InverseDepthRangeB.Set(0.0f);
|
mLinearDepthShader->Uniforms->InverseDepthRangeB = 0.0f;
|
||||||
mLinearDepthShader->Scale.Set(sceneScaleX, sceneScaleY);
|
mLinearDepthShader->Uniforms->Scale = { sceneScaleX, sceneScaleY };
|
||||||
mLinearDepthShader->Offset.Set(sceneOffsetX, sceneOffsetY);
|
mLinearDepthShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY };
|
||||||
|
mLinearDepthShader->Uniforms.Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
||||||
// Apply ambient occlusion
|
// Apply ambient occlusion
|
||||||
|
@ -136,17 +137,18 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
mSSAOShader->DepthTexture.Set(0);
|
mSSAOShader->DepthTexture.Set(0);
|
||||||
mSSAOShader->RandomTexture.Set(1);
|
mSSAOShader->RandomTexture.Set(1);
|
||||||
mSSAOShader->NormalTexture.Set(2);
|
mSSAOShader->NormalTexture.Set(2);
|
||||||
if (gl_multisample > 1) mSSAOShader->SampleIndex.Set(0);
|
if (gl_multisample > 1) mSSAOShader->Uniforms->SampleIndex = 0;
|
||||||
mSSAOShader->UVToViewA.Set(2.0f * invFocalLenX, 2.0f * invFocalLenY);
|
mSSAOShader->Uniforms->UVToViewA = { 2.0f * invFocalLenX, 2.0f * invFocalLenY };
|
||||||
mSSAOShader->UVToViewB.Set(-invFocalLenX, -invFocalLenY);
|
mSSAOShader->Uniforms->UVToViewB = { -invFocalLenX, -invFocalLenY };
|
||||||
mSSAOShader->InvFullResolution.Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
mSSAOShader->Uniforms->InvFullResolution = { 1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight };
|
||||||
mSSAOShader->NDotVBias.Set(nDotVBias);
|
mSSAOShader->Uniforms->NDotVBias = nDotVBias;
|
||||||
mSSAOShader->NegInvR2.Set(-1.0f / r2);
|
mSSAOShader->Uniforms->NegInvR2 = -1.0f / r2;
|
||||||
mSSAOShader->RadiusToScreen.Set(aoRadius * 0.5 / tanHalfFovy * mBuffers->AmbientHeight);
|
mSSAOShader->Uniforms->RadiusToScreen = aoRadius * 0.5 / tanHalfFovy * mBuffers->AmbientHeight;
|
||||||
mSSAOShader->AOMultiplier.Set(1.0f / (1.0f - nDotVBias));
|
mSSAOShader->Uniforms->AOMultiplier = 1.0f / (1.0f - nDotVBias);
|
||||||
mSSAOShader->AOStrength.Set(aoStrength);
|
mSSAOShader->Uniforms->AOStrength = aoStrength;
|
||||||
mSSAOShader->Scale.Set(sceneScaleX, sceneScaleY);
|
mSSAOShader->Uniforms->Scale = { sceneScaleX, sceneScaleY };
|
||||||
mSSAOShader->Offset.Set(sceneOffsetX, sceneOffsetY);
|
mSSAOShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY };
|
||||||
|
mSSAOShader->Uniforms.Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
||||||
// Blur SSAO texture
|
// Blur SSAO texture
|
||||||
|
@ -155,16 +157,18 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
mBuffers->AmbientFB0.Bind();
|
mBuffers->AmbientFB0.Bind();
|
||||||
mBuffers->AmbientTexture1.Bind(0);
|
mBuffers->AmbientTexture1.Bind(0);
|
||||||
mDepthBlurShader->Bind(false);
|
mDepthBlurShader->Bind(false);
|
||||||
mDepthBlurShader->BlurSharpness[false].Set(blurSharpness);
|
mDepthBlurShader->Uniforms[false]->BlurSharpness = blurSharpness;
|
||||||
mDepthBlurShader->InvFullResolution[false].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
mDepthBlurShader->Uniforms[false]->InvFullResolution = { 1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight };
|
||||||
|
mDepthBlurShader->Uniforms[false].Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
||||||
mBuffers->AmbientFB1.Bind();
|
mBuffers->AmbientFB1.Bind();
|
||||||
mBuffers->AmbientTexture0.Bind(0);
|
mBuffers->AmbientTexture0.Bind(0);
|
||||||
mDepthBlurShader->Bind(true);
|
mDepthBlurShader->Bind(true);
|
||||||
mDepthBlurShader->BlurSharpness[true].Set(blurSharpness);
|
mDepthBlurShader->Uniforms[true]->BlurSharpness = blurSharpness;
|
||||||
mDepthBlurShader->InvFullResolution[true].Set(1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight);
|
mDepthBlurShader->Uniforms[true]->InvFullResolution = { 1.0f / mBuffers->AmbientWidth, 1.0f / mBuffers->AmbientHeight };
|
||||||
mDepthBlurShader->PowExponent[true].Set(gl_ssao_exponent);
|
mDepthBlurShader->Uniforms[true]->PowExponent = gl_ssao_exponent;
|
||||||
|
mDepthBlurShader->Uniforms[true].Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,9 +188,10 @@ void FGLRenderer::AmbientOccludeScene()
|
||||||
mSSAOCombineShader->Bind();
|
mSSAOCombineShader->Bind();
|
||||||
mSSAOCombineShader->AODepthTexture.Set(0);
|
mSSAOCombineShader->AODepthTexture.Set(0);
|
||||||
mSSAOCombineShader->SceneFogTexture.Set(1);
|
mSSAOCombineShader->SceneFogTexture.Set(1);
|
||||||
if (gl_multisample > 1) mSSAOCombineShader->SampleCount.Set(gl_multisample);
|
if (gl_multisample > 1) mSSAOCombineShader->Uniforms->SampleCount = gl_multisample;
|
||||||
mSSAOCombineShader->Scale.Set(sceneScaleX, sceneScaleY);
|
mSSAOCombineShader->Uniforms->Scale = { sceneScaleX, sceneScaleY };
|
||||||
mSSAOCombineShader->Offset.Set(sceneOffsetX, sceneOffsetY);
|
mSSAOCombineShader->Uniforms->Offset = { sceneOffsetX, sceneOffsetY };
|
||||||
|
mSSAOCombineShader->Uniforms.Set();
|
||||||
RenderScreenQuad();
|
RenderScreenQuad();
|
||||||
|
|
||||||
FGLDebug::PopGroup();
|
FGLDebug::PopGroup();
|
||||||
|
|
|
@ -33,21 +33,18 @@ void FLinearDepthShader::Bind()
|
||||||
|
|
||||||
if (!mShader)
|
if (!mShader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
if (multisample) prolog += "#define MULTISAMPLE\n";
|
||||||
|
|
||||||
mShader.reset(new FShaderProgram());
|
mShader.reset(new FShaderProgram());
|
||||||
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||||
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/lineardepth.fp", multisample ? "#define MULTISAMPLE\n" : "", 330);
|
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/lineardepth.fp", prolog, 330);
|
||||||
mShader->SetFragDataLocation(0, "FragColor");
|
mShader->SetFragDataLocation(0, "FragColor");
|
||||||
mShader->Link("shaders/glsl/lineardepth");
|
mShader->Link("shaders/glsl/lineardepth");
|
||||||
mShader->SetAttribLocation(0, "PositionInProjection");
|
mShader->SetAttribLocation(0, "PositionInProjection");
|
||||||
DepthTexture.Init(*mShader, "DepthTexture");
|
DepthTexture.Init(*mShader, "DepthTexture");
|
||||||
ColorTexture.Init(*mShader, "ColorTexture");
|
ColorTexture.Init(*mShader, "ColorTexture");
|
||||||
SampleIndex.Init(*mShader, "SampleIndex");
|
Uniforms.Init(*mShader);
|
||||||
LinearizeDepthA.Init(*mShader, "LinearizeDepthA");
|
|
||||||
LinearizeDepthB.Init(*mShader, "LinearizeDepthB");
|
|
||||||
InverseDepthRangeA.Init(*mShader, "InverseDepthRangeA");
|
|
||||||
InverseDepthRangeB.Init(*mShader, "InverseDepthRangeB");
|
|
||||||
Scale.Init(*mShader, "Scale");
|
|
||||||
Offset.Init(*mShader, "Offset");
|
|
||||||
mMultisample = multisample;
|
mMultisample = multisample;
|
||||||
}
|
}
|
||||||
mShader->Bind();
|
mShader->Bind();
|
||||||
|
@ -61,26 +58,19 @@ void FSSAOShader::Bind()
|
||||||
|
|
||||||
if (!mShader)
|
if (!mShader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
prolog += GetDefines(gl_ssao, multisample);
|
||||||
|
|
||||||
mShader.reset(new FShaderProgram());
|
mShader.reset(new FShaderProgram());
|
||||||
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||||
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", GetDefines(gl_ssao, multisample), 330);
|
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssao.fp", prolog, 330);
|
||||||
mShader->SetFragDataLocation(0, "FragColor");
|
mShader->SetFragDataLocation(0, "FragColor");
|
||||||
mShader->Link("shaders/glsl/ssao");
|
mShader->Link("shaders/glsl/ssao");
|
||||||
mShader->SetAttribLocation(0, "PositionInProjection");
|
mShader->SetAttribLocation(0, "PositionInProjection");
|
||||||
DepthTexture.Init(*mShader, "DepthTexture");
|
DepthTexture.Init(*mShader, "DepthTexture");
|
||||||
NormalTexture.Init(*mShader, "NormalTexture");
|
NormalTexture.Init(*mShader, "NormalTexture");
|
||||||
RandomTexture.Init(*mShader, "RandomTexture");
|
RandomTexture.Init(*mShader, "RandomTexture");
|
||||||
UVToViewA.Init(*mShader, "UVToViewA");
|
Uniforms.Init(*mShader);
|
||||||
UVToViewB.Init(*mShader, "UVToViewB");
|
|
||||||
InvFullResolution.Init(*mShader, "InvFullResolution");
|
|
||||||
NDotVBias.Init(*mShader, "NDotVBias");
|
|
||||||
NegInvR2.Init(*mShader, "NegInvR2");
|
|
||||||
RadiusToScreen.Init(*mShader, "RadiusToScreen");
|
|
||||||
AOMultiplier.Init(*mShader, "AOMultiplier");
|
|
||||||
AOStrength.Init(*mShader, "AOStrength");
|
|
||||||
Scale.Init(*mShader, "Scale");
|
|
||||||
Offset.Init(*mShader, "Offset");
|
|
||||||
SampleIndex.Init(*mShader, "SampleIndex");
|
|
||||||
mMultisample = multisample;
|
mMultisample = multisample;
|
||||||
}
|
}
|
||||||
mShader->Bind();
|
mShader->Bind();
|
||||||
|
@ -116,15 +106,19 @@ void FDepthBlurShader::Bind(bool vertical)
|
||||||
auto &shader = mShader[vertical];
|
auto &shader = mShader[vertical];
|
||||||
if (!shader)
|
if (!shader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms[vertical].CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
if (vertical)
|
||||||
|
prolog += "#define BLUR_VERTICAL\n";
|
||||||
|
else
|
||||||
|
prolog += "#define BLUR_HORIZONTAL\n";
|
||||||
|
|
||||||
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
shader.Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||||
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/depthblur.fp", vertical ? "#define BLUR_VERTICAL\n" : "#define BLUR_HORIZONTAL\n", 330);
|
shader.Compile(FShaderProgram::Fragment, "shaders/glsl/depthblur.fp", prolog, 330);
|
||||||
shader.SetFragDataLocation(0, "FragColor");
|
shader.SetFragDataLocation(0, "FragColor");
|
||||||
shader.Link("shaders/glsl/depthblur");
|
shader.Link("shaders/glsl/depthblur");
|
||||||
shader.SetAttribLocation(0, "PositionInProjection");
|
shader.SetAttribLocation(0, "PositionInProjection");
|
||||||
AODepthTexture[vertical].Init(shader, "AODepthTexture");
|
AODepthTexture[vertical].Init(shader, "AODepthTexture");
|
||||||
BlurSharpness[vertical].Init(shader, "BlurSharpness");
|
Uniforms[vertical].Init(shader);
|
||||||
InvFullResolution[vertical].Init(shader, "InvFullResolution");
|
|
||||||
PowExponent[vertical].Init(shader, "PowExponent");
|
|
||||||
}
|
}
|
||||||
shader.Bind();
|
shader.Bind();
|
||||||
}
|
}
|
||||||
|
@ -137,17 +131,19 @@ void FSSAOCombineShader::Bind()
|
||||||
|
|
||||||
if (!mShader)
|
if (!mShader)
|
||||||
{
|
{
|
||||||
|
FString prolog = Uniforms.CreateDeclaration("Uniforms", UniformBlock::Desc());
|
||||||
|
if (multisample)
|
||||||
|
prolog += "#define MULTISAMPLE\n";
|
||||||
|
|
||||||
mShader.reset(new FShaderProgram());
|
mShader.reset(new FShaderProgram());
|
||||||
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
mShader->Compile(FShaderProgram::Vertex, "shaders/glsl/screenquad.vp", "", 330);
|
||||||
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssaocombine.fp", multisample ? "#define MULTISAMPLE\n" : "", 330);
|
mShader->Compile(FShaderProgram::Fragment, "shaders/glsl/ssaocombine.fp", prolog, 330);
|
||||||
mShader->SetFragDataLocation(0, "FragColor");
|
mShader->SetFragDataLocation(0, "FragColor");
|
||||||
mShader->Link("shaders/glsl/ssaocombine");
|
mShader->Link("shaders/glsl/ssaocombine");
|
||||||
mShader->SetAttribLocation(0, "PositionInProjection");
|
mShader->SetAttribLocation(0, "PositionInProjection");
|
||||||
AODepthTexture.Init(*mShader, "AODepthTexture");
|
AODepthTexture.Init(*mShader, "AODepthTexture");
|
||||||
SceneFogTexture.Init(*mShader, "SceneFogTexture");
|
SceneFogTexture.Init(*mShader, "SceneFogTexture");
|
||||||
SampleCount.Init(*mShader, "SampleCount");
|
Uniforms.Init(*mShader);
|
||||||
Scale.Init(*mShader, "Scale");
|
|
||||||
Offset.Init(*mShader, "Offset");
|
|
||||||
mMultisample = multisample;
|
mMultisample = multisample;
|
||||||
}
|
}
|
||||||
mShader->Bind();
|
mShader->Bind();
|
||||||
|
|
|
@ -12,13 +12,37 @@ public:
|
||||||
|
|
||||||
FBufferedUniformSampler DepthTexture;
|
FBufferedUniformSampler DepthTexture;
|
||||||
FBufferedUniformSampler ColorTexture;
|
FBufferedUniformSampler ColorTexture;
|
||||||
FBufferedUniform1i SampleIndex;
|
|
||||||
FBufferedUniform1f LinearizeDepthA;
|
struct UniformBlock
|
||||||
FBufferedUniform1f LinearizeDepthB;
|
{
|
||||||
FBufferedUniform1f InverseDepthRangeA;
|
int SampleIndex;
|
||||||
FBufferedUniform1f InverseDepthRangeB;
|
float LinearizeDepthA;
|
||||||
FBufferedUniform2f Scale;
|
float LinearizeDepthB;
|
||||||
FBufferedUniform2f Offset;
|
float InverseDepthRangeA;
|
||||||
|
float InverseDepthRangeB;
|
||||||
|
float Padding0, Padding1, Padding2;
|
||||||
|
FVector2 Scale;
|
||||||
|
FVector2 Offset;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "SampleIndex", UniformType::Int, offsetof(UniformBlock, SampleIndex) },
|
||||||
|
{ "LinearizeDepthA", UniformType::Float, offsetof(UniformBlock, LinearizeDepthA) },
|
||||||
|
{ "LinearizeDepthB", UniformType::Float, offsetof(UniformBlock, LinearizeDepthB) },
|
||||||
|
{ "InverseDepthRangeA", UniformType::Float, offsetof(UniformBlock, InverseDepthRangeA) },
|
||||||
|
{ "InverseDepthRangeB", UniformType::Float, offsetof(UniformBlock, InverseDepthRangeB) },
|
||||||
|
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||||
|
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||||
|
{ "Padding2", UniformType::Float, offsetof(UniformBlock, Padding2) },
|
||||||
|
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||||
|
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<FShaderProgram> mShader;
|
std::unique_ptr<FShaderProgram> mShader;
|
||||||
|
@ -33,17 +57,44 @@ public:
|
||||||
FBufferedUniformSampler DepthTexture;
|
FBufferedUniformSampler DepthTexture;
|
||||||
FBufferedUniformSampler NormalTexture;
|
FBufferedUniformSampler NormalTexture;
|
||||||
FBufferedUniformSampler RandomTexture;
|
FBufferedUniformSampler RandomTexture;
|
||||||
FBufferedUniform2f UVToViewA;
|
|
||||||
FBufferedUniform2f UVToViewB;
|
struct UniformBlock
|
||||||
FBufferedUniform2f InvFullResolution;
|
{
|
||||||
FBufferedUniform1f NDotVBias;
|
FVector2 UVToViewA;
|
||||||
FBufferedUniform1f NegInvR2;
|
FVector2 UVToViewB;
|
||||||
FBufferedUniform1f RadiusToScreen;
|
FVector2 InvFullResolution;
|
||||||
FBufferedUniform1f AOMultiplier;
|
float NDotVBias;
|
||||||
FBufferedUniform1f AOStrength;
|
float NegInvR2;
|
||||||
FBufferedUniform2f Scale;
|
float RadiusToScreen;
|
||||||
FBufferedUniform2f Offset;
|
float AOMultiplier;
|
||||||
FBufferedUniform1i SampleIndex;
|
float AOStrength;
|
||||||
|
int SampleIndex;
|
||||||
|
float Padding0, Padding1;
|
||||||
|
FVector2 Scale;
|
||||||
|
FVector2 Offset;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "UVToViewA", UniformType::Vec2, offsetof(UniformBlock, UVToViewA) },
|
||||||
|
{ "UVToViewB", UniformType::Vec2, offsetof(UniformBlock, UVToViewB) },
|
||||||
|
{ "InvFullResolution", UniformType::Vec2, offsetof(UniformBlock, InvFullResolution) },
|
||||||
|
{ "NDotVBias", UniformType::Float, offsetof(UniformBlock, NDotVBias) },
|
||||||
|
{ "NegInvR2", UniformType::Float, offsetof(UniformBlock, NegInvR2) },
|
||||||
|
{ "RadiusToScreen", UniformType::Float, offsetof(UniformBlock, RadiusToScreen) },
|
||||||
|
{ "AOMultiplier", UniformType::Float, offsetof(UniformBlock, AOMultiplier) },
|
||||||
|
{ "AOStrength", UniformType::Float, offsetof(UniformBlock, AOStrength) },
|
||||||
|
{ "SampleIndex", UniformType::Int, offsetof(UniformBlock, SampleIndex) },
|
||||||
|
{ "Padding0", UniformType::Float, offsetof(UniformBlock, Padding0) },
|
||||||
|
{ "Padding1", UniformType::Float, offsetof(UniformBlock, Padding1) },
|
||||||
|
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||||
|
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum Quality
|
enum Quality
|
||||||
|
@ -68,9 +119,25 @@ public:
|
||||||
void Bind(bool vertical);
|
void Bind(bool vertical);
|
||||||
|
|
||||||
FBufferedUniformSampler AODepthTexture[2];
|
FBufferedUniformSampler AODepthTexture[2];
|
||||||
FBufferedUniform1f BlurSharpness[2];
|
|
||||||
FBufferedUniform2f InvFullResolution[2];
|
struct UniformBlock
|
||||||
FBufferedUniform1f PowExponent[2];
|
{
|
||||||
|
float BlurSharpness;
|
||||||
|
float PowExponent;
|
||||||
|
FVector2 InvFullResolution;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "BlurSharpness", UniformType::Float, offsetof(UniformBlock, BlurSharpness) },
|
||||||
|
{ "PowExponent", UniformType::Float, offsetof(UniformBlock, PowExponent) },
|
||||||
|
{ "InvFullResolution", UniformType::Vec2, offsetof(UniformBlock, InvFullResolution) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms[2];
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FShaderProgram mShader[2];
|
FShaderProgram mShader[2];
|
||||||
|
@ -83,9 +150,29 @@ public:
|
||||||
|
|
||||||
FBufferedUniformSampler AODepthTexture;
|
FBufferedUniformSampler AODepthTexture;
|
||||||
FBufferedUniformSampler SceneFogTexture;
|
FBufferedUniformSampler SceneFogTexture;
|
||||||
FBufferedUniform1i SampleCount;
|
|
||||||
FBufferedUniform2f Scale;
|
struct UniformBlock
|
||||||
FBufferedUniform2f Offset;
|
{
|
||||||
|
int SampleCount;
|
||||||
|
int Padding0, Padding1, Padding2;
|
||||||
|
FVector2 Scale;
|
||||||
|
FVector2 Offset;
|
||||||
|
|
||||||
|
static std::vector<UniformFieldDesc> Desc()
|
||||||
|
{
|
||||||
|
return
|
||||||
|
{
|
||||||
|
{ "SampleCount", UniformType::Int, offsetof(UniformBlock, SampleCount) },
|
||||||
|
{ "Padding0", UniformType::Int, offsetof(UniformBlock, Padding0) },
|
||||||
|
{ "Padding1", UniformType::Int, offsetof(UniformBlock, Padding1) },
|
||||||
|
{ "Padding2", UniformType::Int, offsetof(UniformBlock, Padding2) },
|
||||||
|
{ "Scale", UniformType::Vec2, offsetof(UniformBlock, Scale) },
|
||||||
|
{ "Offset", UniformType::Vec2, offsetof(UniformBlock, Offset) }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ShaderUniforms<UniformBlock> Uniforms;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<FShaderProgram> mShader;
|
std::unique_ptr<FShaderProgram> mShader;
|
||||||
|
|
|
@ -407,7 +407,8 @@ public:
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
LIGHTBUF_BINDINGPOINT = 1
|
LIGHTBUF_BINDINGPOINT = 1,
|
||||||
|
POSTPROCESS_BINDINGPOINT = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,8 +1,121 @@
|
||||||
#ifndef __GL_SHADERPROGRAM_H
|
|
||||||
#define __GL_SHADERPROGRAM_H
|
#pragma once
|
||||||
|
|
||||||
#include "gl_shader.h"
|
#include "gl_shader.h"
|
||||||
|
|
||||||
|
enum class UniformType
|
||||||
|
{
|
||||||
|
Int,
|
||||||
|
UInt,
|
||||||
|
Float,
|
||||||
|
Vec2,
|
||||||
|
Vec3,
|
||||||
|
Vec4,
|
||||||
|
IVec2,
|
||||||
|
IVec3,
|
||||||
|
IVec4,
|
||||||
|
UVec2,
|
||||||
|
UVec3,
|
||||||
|
UVec4,
|
||||||
|
};
|
||||||
|
|
||||||
|
class UniformFieldDesc
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UniformFieldDesc() { }
|
||||||
|
UniformFieldDesc(const char *name, UniformType type, std::size_t offset) : Name(name), Type(type), Offset(offset) { }
|
||||||
|
|
||||||
|
const char *Name;
|
||||||
|
UniformType Type;
|
||||||
|
std::size_t Offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class ShaderUniforms
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ShaderUniforms()
|
||||||
|
{
|
||||||
|
memset(&Values, 0, sizeof(Values));
|
||||||
|
}
|
||||||
|
|
||||||
|
~ShaderUniforms()
|
||||||
|
{
|
||||||
|
if (mBufferHandle)
|
||||||
|
glDeleteBuffers(1, &mBufferHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
FString CreateDeclaration(const char *name, const std::vector<UniformFieldDesc> &fields)
|
||||||
|
{
|
||||||
|
mName = name;
|
||||||
|
mFields = fields;
|
||||||
|
|
||||||
|
FString decl;
|
||||||
|
decl.Format("layout(std140) uniform %s\n{\n", name);
|
||||||
|
for (const auto &field : fields)
|
||||||
|
{
|
||||||
|
decl.AppendFormat("\t%s %s;\n", GetTypeStr(field.Type), field.Name);
|
||||||
|
}
|
||||||
|
decl += "};\n";
|
||||||
|
|
||||||
|
return decl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Init(GLuint hShader, int index = POSTPROCESS_BINDINGPOINT)
|
||||||
|
{
|
||||||
|
GLuint uniformBlockIndex = glGetUniformBlockIndex(hShader, mName);
|
||||||
|
if (uniformBlockIndex != GL_INVALID_INDEX)
|
||||||
|
{
|
||||||
|
glUniformBlockBinding(hShader, uniformBlockIndex, index);
|
||||||
|
glGenBuffers(1, (GLuint*)&mBufferHandle);
|
||||||
|
mIndex = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Set()
|
||||||
|
{
|
||||||
|
glBindBuffer(GL_UNIFORM_BUFFER, mBufferHandle);
|
||||||
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(T), &Values, GL_STREAM_DRAW);
|
||||||
|
|
||||||
|
glBindBufferBase(GL_UNIFORM_BUFFER, mIndex, mBufferHandle);
|
||||||
|
}
|
||||||
|
|
||||||
|
T *operator->() { return &Values; }
|
||||||
|
const T *operator->() const { return &Values; }
|
||||||
|
|
||||||
|
T Values;
|
||||||
|
|
||||||
|
private:
|
||||||
|
ShaderUniforms(const ShaderUniforms &) = delete;
|
||||||
|
ShaderUniforms &operator=(const ShaderUniforms &) = delete;
|
||||||
|
|
||||||
|
const char *GetTypeStr(UniformType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
case UniformType::Int: return "int";
|
||||||
|
case UniformType::UInt: return "uint";
|
||||||
|
case UniformType::Float: return "float";
|
||||||
|
case UniformType::Vec2: return "vec2";
|
||||||
|
case UniformType::Vec3: return "vec3";
|
||||||
|
case UniformType::Vec4: return "vec4";
|
||||||
|
case UniformType::IVec2: return "ivec2";
|
||||||
|
case UniformType::IVec3: return "ivec3";
|
||||||
|
case UniformType::IVec4: return "ivec4";
|
||||||
|
case UniformType::UVec2: return "uvec2";
|
||||||
|
case UniformType::UVec3: return "uvec3";
|
||||||
|
case UniformType::UVec4: return "uvec4";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *mName = nullptr;
|
||||||
|
int mIndex = -1;
|
||||||
|
GLuint mBufferHandle = 0;
|
||||||
|
std::vector<UniformFieldDesc> mFields;
|
||||||
|
std::vector<int> mUniformLocations;
|
||||||
|
};
|
||||||
|
|
||||||
class FShaderProgram
|
class FShaderProgram
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -39,5 +152,3 @@ private:
|
||||||
GLuint mProgram = 0;
|
GLuint mProgram = 0;
|
||||||
GLuint mShaders[NumShaderTypes];
|
GLuint mShaders[NumShaderTypes];
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
|
|
@ -3,9 +3,6 @@ in vec2 TexCoord;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform sampler2D AODepthTexture;
|
uniform sampler2D AODepthTexture;
|
||||||
uniform float BlurSharpness;
|
|
||||||
uniform vec2 InvFullResolution;
|
|
||||||
uniform float PowExponent;
|
|
||||||
|
|
||||||
#define KERNEL_RADIUS 3.0
|
#define KERNEL_RADIUS 3.0
|
||||||
|
|
||||||
|
|
|
@ -5,19 +5,11 @@ out vec4 FragColor;
|
||||||
#if defined(MULTISAMPLE)
|
#if defined(MULTISAMPLE)
|
||||||
uniform sampler2DMS DepthTexture;
|
uniform sampler2DMS DepthTexture;
|
||||||
uniform sampler2DMS ColorTexture;
|
uniform sampler2DMS ColorTexture;
|
||||||
uniform int SampleIndex;
|
|
||||||
#else
|
#else
|
||||||
uniform sampler2D DepthTexture;
|
uniform sampler2D DepthTexture;
|
||||||
uniform sampler2D ColorTexture;
|
uniform sampler2D ColorTexture;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform float LinearizeDepthA;
|
|
||||||
uniform float LinearizeDepthB;
|
|
||||||
uniform float InverseDepthRangeA;
|
|
||||||
uniform float InverseDepthRangeB;
|
|
||||||
uniform vec2 Scale;
|
|
||||||
uniform vec2 Offset;
|
|
||||||
|
|
||||||
float normalizeDepth(float depth)
|
float normalizeDepth(float depth)
|
||||||
{
|
{
|
||||||
float normalizedDepth = clamp(InverseDepthRangeA * depth + InverseDepthRangeB, 0.0, 1.0);
|
float normalizedDepth = clamp(InverseDepthRangeA * depth + InverseDepthRangeB, 0.0, 1.0);
|
||||||
|
|
|
@ -2,25 +2,10 @@
|
||||||
in vec2 TexCoord;
|
in vec2 TexCoord;
|
||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
uniform vec2 UVToViewA;
|
|
||||||
uniform vec2 UVToViewB;
|
|
||||||
uniform vec2 InvFullResolution;
|
|
||||||
|
|
||||||
uniform float NDotVBias;
|
|
||||||
uniform float NegInvR2;
|
|
||||||
uniform float RadiusToScreen;
|
|
||||||
uniform float AOMultiplier;
|
|
||||||
|
|
||||||
uniform float AOStrength;
|
|
||||||
|
|
||||||
uniform vec2 Scale;
|
|
||||||
uniform vec2 Offset;
|
|
||||||
|
|
||||||
uniform sampler2D DepthTexture;
|
uniform sampler2D DepthTexture;
|
||||||
|
|
||||||
#if defined(MULTISAMPLE)
|
#if defined(MULTISAMPLE)
|
||||||
uniform sampler2DMS NormalTexture;
|
uniform sampler2DMS NormalTexture;
|
||||||
uniform int SampleIndex;
|
|
||||||
#else
|
#else
|
||||||
uniform sampler2D NormalTexture;
|
uniform sampler2D NormalTexture;
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -6,14 +6,10 @@ uniform sampler2D AODepthTexture;
|
||||||
|
|
||||||
#if defined(MULTISAMPLE)
|
#if defined(MULTISAMPLE)
|
||||||
uniform sampler2DMS SceneFogTexture;
|
uniform sampler2DMS SceneFogTexture;
|
||||||
uniform int SampleCount;
|
|
||||||
#else
|
#else
|
||||||
uniform sampler2D SceneFogTexture;
|
uniform sampler2D SceneFogTexture;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uniform vec2 Scale;
|
|
||||||
uniform vec2 Offset;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec2 uv = Offset + TexCoord * Scale;
|
vec2 uv = Offset + TexCoord * Scale;
|
||||||
|
|
Loading…
Reference in a new issue