Factorize (and fix) gaussian weight computation
This commit is contained in:
parent
d8b3cf9c8f
commit
df12714f49
@ -284,6 +284,27 @@ void PostProcessing::renderShadowedSunlight(const core::vector3df &direction, co
|
||||
DrawFullScreenEffect<FullScreenShader::ShadowedSunLightShader>(shadowSplit[1], shadowSplit[2], shadowSplit[3], shadowSplit[4], direction, col);
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<float> getGaussianWeight(float sigma, size_t count)
|
||||
{
|
||||
float g0, g1, g2, total;
|
||||
|
||||
std::vector<float> weights;
|
||||
g0 = 1.f / (sqrtf(2.f * 3.14f) * sigma);
|
||||
g1 = exp(-.5f / (sigma * sigma));
|
||||
g2 = g1 * g1;
|
||||
total = g0;
|
||||
for (unsigned i = 0; i < count; i++)
|
||||
{
|
||||
weights.push_back(g0);
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
total += 2 * g0;
|
||||
}
|
||||
for (float &weight : weights)
|
||||
weight /= total;
|
||||
return weights;
|
||||
}
|
||||
|
||||
void PostProcessing::renderGaussian3Blur(FrameBuffer &in_fbo, FrameBuffer &auxiliary)
|
||||
{
|
||||
@ -320,18 +341,7 @@ void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo, size_t layer,
|
||||
}
|
||||
else
|
||||
{
|
||||
float g0, g1, g2;
|
||||
|
||||
std::vector<float> weightsV;
|
||||
g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaV);
|
||||
g1 = exp(-.5f / (sigmaV * sigmaV));
|
||||
g2 = g1 * g1;
|
||||
for (unsigned i = 0; i < 7; i++)
|
||||
{
|
||||
weightsV.push_back(g0);
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
}
|
||||
const std::vector<float> &weightsV = getGaussianWeight(sigmaV, 7);
|
||||
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
glUseProgram(FullScreenShader::ComputeShadowBlurVShader::getInstance()->Program);
|
||||
FullScreenShader::ComputeShadowBlurVShader::getInstance()->SetTextureUnits(LayerTex);
|
||||
@ -340,17 +350,7 @@ void PostProcessing::renderGaussian6BlurLayer(FrameBuffer &in_fbo, size_t layer,
|
||||
FullScreenShader::ComputeShadowBlurVShader::getInstance()->setUniforms(core::vector2df(1.f / 1024.f, 1.f / 1024.f), weightsV);
|
||||
glDispatchCompute((int)1024 / 8 + 1, (int)1024 / 8 + 1, 1);
|
||||
|
||||
std::vector<float> weightsH;
|
||||
g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaH);
|
||||
g1 = exp(-.5f / (sigmaH * sigmaH));
|
||||
g2 = g1 * g1;
|
||||
for (unsigned i = 0; i < 7; i++)
|
||||
{
|
||||
weightsH.push_back(g0);
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
}
|
||||
|
||||
const std::vector<float> &weightsH = getGaussianWeight(sigmaH, 7);
|
||||
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
glUseProgram(FullScreenShader::ComputeShadowBlurHShader::getInstance()->Program);
|
||||
FullScreenShader::ComputeShadowBlurHShader::getInstance()->SetTextureUnits(irr_driver->getFBO(FBO_SCALAR_1024).getRTT()[0]);
|
||||
@ -382,19 +382,7 @@ void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxil
|
||||
}
|
||||
else
|
||||
{
|
||||
float g0, g1, g2;
|
||||
|
||||
std::vector<float> weightsV;
|
||||
g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaV);
|
||||
g1 = exp(-.5f / (sigmaV * sigmaV));
|
||||
g2 = g1 * g1;
|
||||
for (unsigned i = 0; i < 7; i++)
|
||||
{
|
||||
weightsV.push_back(g0);
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
}
|
||||
|
||||
const std::vector<float> &weightsV = getGaussianWeight(sigmaV, 7);
|
||||
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT);
|
||||
glUseProgram(FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->Program);
|
||||
FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->SetTextureUnits(in_fbo.getRTT()[0]);
|
||||
@ -403,17 +391,7 @@ void PostProcessing::renderGaussian6Blur(FrameBuffer &in_fbo, FrameBuffer &auxil
|
||||
FullScreenShader::ComputeGaussian6VBlurShader::getInstance()->setUniforms(core::vector2df(inv_width, inv_height), weightsV);
|
||||
glDispatchCompute((int)in_fbo.getWidth() / 8 + 1, (int)in_fbo.getHeight() / 8 + 1, 1);
|
||||
|
||||
std::vector<float> weightsH;
|
||||
g0 = 1.f / (sqrtf(2.f * 3.14f) * sigmaH);
|
||||
g1 = exp(-.5f / (sigmaH * sigmaH));
|
||||
g2 = g1 * g1;
|
||||
for (unsigned i = 0; i < 7; i++)
|
||||
{
|
||||
weightsH.push_back(g0);
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
}
|
||||
|
||||
const std::vector<float> &weightsH = getGaussianWeight(sigmaH, 7);
|
||||
glMemoryBarrier(GL_TEXTURE_FETCH_BARRIER_BIT | GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
|
||||
glUseProgram(FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->Program);
|
||||
FullScreenShader::ComputeGaussian6HBlurShader::getInstance()->SetTextureUnits(auxiliary.getRTT()[0]);
|
||||
|
Loading…
Reference in New Issue
Block a user