Implemented bilateral for compute path.
This commit is contained in:
parent
d8edf64caf
commit
3219e564d0
@ -1,20 +1,25 @@
|
||||
// From http://http.developer.nvidia.com/GPUGems3/gpugems3_ch40.html
|
||||
|
||||
uniform layout(size1x16) restrict readonly image2D source;
|
||||
uniform layout(size1x32) restrict readonly image2D depth;
|
||||
uniform layout(size1x16) volatile restrict writeonly image2D dest;
|
||||
uniform float sigma = 5.;
|
||||
|
||||
layout (local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
shared float local_src[8 + 2 * 8][8];
|
||||
shared float local_depth[8 + 2 * 8][8];
|
||||
|
||||
void main()
|
||||
{
|
||||
int x = int(gl_LocalInvocationID.x), y = int(gl_LocalInvocationID.y);
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
|
||||
local_src[x][y] = imageLoad(source, ivec2(uv) - ivec2(8, 0)).x;
|
||||
local_depth[x][y] = imageLoad(depth, ivec2(uv) - ivec2(8, 0)).x;
|
||||
local_src[x + 8][y] = imageLoad(source, ivec2(uv)).x;
|
||||
local_depth[x + 8][y] = imageLoad(depth, ivec2(uv)).x;
|
||||
local_src[x + 16][y] = imageLoad(source, ivec2(uv) + ivec2(8, 0)).x;
|
||||
local_depth[x + 16][y] = imageLoad(depth, ivec2(uv) + ivec2(8, 0)).x;
|
||||
|
||||
barrier();
|
||||
|
||||
@ -23,14 +28,20 @@ void main()
|
||||
g1 = exp(-0.5 / (sigma * sigma));
|
||||
g2 = g1 * g1;
|
||||
float sum = local_src[x + 8][y] * g0;
|
||||
float pixel_depth = local_depth[x + 8][y];
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
float tmp_weight, total_weight = g0;
|
||||
for (int j = 1; j < 8; j++) {
|
||||
sum += local_src[8 + x - j][y] * g0;
|
||||
sum += local_src[8 + x + j][y] * g0;
|
||||
tmp_weight = max(0.0, 1.0 - .001 * abs(local_depth[8 + x - j][y] - pixel_depth));
|
||||
total_weight += g0 * tmp_weight;
|
||||
sum += local_src[8 + x - j][y] * g0 * tmp_weight;
|
||||
tmp_weight = max(0.0, 1.0 - .001 * abs(local_depth[8 + x + j][y] - pixel_depth));
|
||||
total_weight += g0 * tmp_weight;
|
||||
sum += local_src[8 + x + j][y] * g0 * tmp_weight;
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
}
|
||||
imageStore(dest, ivec2(uv), vec4(sum));
|
||||
imageStore(dest, ivec2(uv), vec4(sum / total_weight));
|
||||
}
|
||||
|
@ -1,20 +1,25 @@
|
||||
// From http://http.developer.nvidia.com/GPUGems3/gpugems3_ch40.html
|
||||
|
||||
uniform layout(size1x16) restrict readonly image2D source;
|
||||
uniform layout(size1x32) restrict readonly image2D depth;
|
||||
uniform layout(size1x16) volatile restrict writeonly image2D dest;
|
||||
uniform float sigma = 5.;
|
||||
|
||||
layout (local_size_x = 8, local_size_y = 8) in;
|
||||
|
||||
shared float local_src[8][8 + 2 * 8];
|
||||
shared float local_depth[8][8 + 2 * 8];
|
||||
|
||||
void main()
|
||||
{
|
||||
int x = int(gl_LocalInvocationID.x), y = int(gl_LocalInvocationID.y);
|
||||
ivec2 uv = ivec2(gl_GlobalInvocationID.x, gl_GlobalInvocationID.y);
|
||||
local_src[x][y] = imageLoad(source, ivec2(uv) - ivec2(0, 8)).x;
|
||||
local_depth[x][y] = imageLoad(depth, ivec2(uv) - ivec2(0, 8)).x;
|
||||
local_src[x][y + 8] = imageLoad(source, ivec2(uv)).x;
|
||||
local_depth[x][y + 8] = imageLoad(depth, ivec2(uv)).x;
|
||||
local_src[x][y + 16] = imageLoad(source, ivec2(uv) + ivec2(0, 8)).x;
|
||||
local_depth[x][y + 16] = imageLoad(depth, ivec2(uv) + ivec2(0, 8)).x;
|
||||
|
||||
barrier();
|
||||
|
||||
@ -23,14 +28,21 @@ void main()
|
||||
g1 = exp(-0.5 / (sigma * sigma));
|
||||
g2 = g1 * g1;
|
||||
float sum = local_src[x][y + 8] * g0;
|
||||
float pixel_depth = local_depth[x][y + 8];
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
float tmp_weight, total_weight = g0;
|
||||
for (int j = 1; j < 8; j++) {
|
||||
sum += local_src[x][y + 8 + j] * g0;
|
||||
sum += local_src[x][y + 8 - j] * g0;
|
||||
tmp_weight = max(0.0, 1.0 - .001 * abs(local_depth[x][y + 8 + j] - pixel_depth));
|
||||
sum += local_src[x][y + 8 + j] * g0 * tmp_weight;
|
||||
total_weight += g0 * tmp_weight;
|
||||
tmp_weight = max(0.0, 1.0 - .001 * abs(local_depth[x][y + 8 - j] - pixel_depth));
|
||||
sum += local_src[x][y + 8 - j] * g0 * tmp_weight;
|
||||
total_weight += g0 * tmp_weight;
|
||||
g0 *= g1;
|
||||
g1 *= g2;
|
||||
|
||||
}
|
||||
imageStore(dest, ivec2(uv), vec4(sum));
|
||||
imageStore(dest, ivec2(uv), vec4(sum / total_weight));
|
||||
}
|
||||
|
@ -425,9 +425,11 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &a
|
||||
|
||||
glUseProgram(FullScreenShader::ComputeGaussian17TapHShader::Program);
|
||||
glBindImageTexture(0, in_fbo.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
|
||||
glBindImageTexture(1, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
|
||||
glBindImageTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
|
||||
glBindImageTexture(2, auxiliary.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_source, 0);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_dest, 1);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_depth, 1);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapHShader::uniform_dest, 2);
|
||||
glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
|
||||
}
|
||||
#endif
|
||||
@ -455,9 +457,11 @@ void PostProcessing::renderGaussian17TapBlur(FrameBuffer &in_fbo, FrameBuffer &a
|
||||
{
|
||||
glUseProgram(FullScreenShader::ComputeGaussian17TapVShader::Program);
|
||||
glBindImageTexture(0, auxiliary.getRTT()[0], 0, false, 0, GL_READ_ONLY, GL_R16F);
|
||||
glBindImageTexture(1, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
|
||||
glBindImageTexture(1, irr_driver->getFBO(FBO_LINEAR_DEPTH).getRTT()[0], 1, false, 0, GL_READ_ONLY, GL_R32F);
|
||||
glBindImageTexture(2, in_fbo.getRTT()[0], 0, false, 0, GL_WRITE_ONLY, GL_R16F);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_source, 0);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_dest, 1);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_depth, 1);
|
||||
glUniform1i(FullScreenShader::ComputeGaussian17TapVShader::uniform_dest, 2);
|
||||
glDispatchCompute(in_fbo.getWidth() / 8, in_fbo.getHeight() / 8, 1);
|
||||
}
|
||||
#endif
|
||||
|
@ -2509,13 +2509,15 @@ namespace FullScreenShader
|
||||
|
||||
GLuint ComputeGaussian17TapHShader::Program;
|
||||
GLuint ComputeGaussian17TapHShader::uniform_source;
|
||||
GLuint ComputeGaussian17TapHShader::uniform_depth;
|
||||
GLuint ComputeGaussian17TapHShader::uniform_dest;
|
||||
void ComputeGaussian17TapHShader::init()
|
||||
{
|
||||
#if WIN32
|
||||
Program = LoadProgram(
|
||||
GL_COMPUTE_SHADER, file_manager->getAsset("shaders/gaussian.comp").c_str());
|
||||
GL_COMPUTE_SHADER, file_manager->getAsset("shaders/bilateralH.comp").c_str());
|
||||
uniform_source = glGetUniformLocation(Program, "source");
|
||||
uniform_depth = glGetUniformLocation(Program, "depth");
|
||||
uniform_dest = glGetUniformLocation(Program, "dest");
|
||||
#endif
|
||||
}
|
||||
@ -2564,13 +2566,15 @@ namespace FullScreenShader
|
||||
|
||||
GLuint ComputeGaussian17TapVShader::Program;
|
||||
GLuint ComputeGaussian17TapVShader::uniform_source;
|
||||
GLuint ComputeGaussian17TapVShader::uniform_depth;
|
||||
GLuint ComputeGaussian17TapVShader::uniform_dest;
|
||||
void ComputeGaussian17TapVShader::init()
|
||||
{
|
||||
#if WIN32
|
||||
Program = LoadProgram(
|
||||
GL_COMPUTE_SHADER, file_manager->getAsset("shaders/gaussianv.comp").c_str());
|
||||
GL_COMPUTE_SHADER, file_manager->getAsset("shaders/bilateralV.comp").c_str());
|
||||
uniform_source = glGetUniformLocation(Program, "source");
|
||||
uniform_depth = glGetUniformLocation(Program, "depth");
|
||||
uniform_dest = glGetUniformLocation(Program, "dest");
|
||||
#endif
|
||||
}
|
||||
|
@ -657,7 +657,7 @@ class ComputeGaussian17TapHShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_source, uniform_dest;
|
||||
static GLuint uniform_source, uniform_depth, uniform_dest;
|
||||
|
||||
static void init();
|
||||
};
|
||||
@ -696,7 +696,7 @@ class ComputeGaussian17TapVShader
|
||||
{
|
||||
public:
|
||||
static GLuint Program;
|
||||
static GLuint uniform_source, uniform_dest;
|
||||
static GLuint uniform_source, uniform_depth, uniform_dest;
|
||||
|
||||
static void init();
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user