Commit c52666f7 authored by MURRAY David's avatar MURRAY David

wip with filter

parent 0718231a
Pipeline #107656 skipped with stage
......@@ -6,6 +6,8 @@ uniform sampler2D display_buffer;
uniform sampler2D output_buffer;
uniform sampler2D alpha_buffer;
uniform sampler2D variance_buffer;
uniform sampler2D position_buffer;
uniform sampler2D normal_buffer;
uniform vec2 viewport;
uniform int visu_mode;
......@@ -16,8 +18,8 @@ uniform ivec2 picked_pos;
uniform int frame;
uniform int log_variance;
#define RADIANCE_RAW 0
#define RADIANCE_ADJUSTED 1
#define RADIANCE_ADJUSTED 0
#define RADIANCE_RAW 1
#define ALPHA 2
#define VARIANCE 3
......@@ -169,9 +171,10 @@ main(void)
vec3 var = texture(variance_buffer, screen_coord).rgb;
var = sqrt(var);
var /= rad;
var = vec3(length(var));
var /= length(rad);
ret_color.rgb = vec3(length(var)) * 0.1;
ret_color.rgb = var * 0.1;//vec3(length(var)) * 0.1;
// ret_color.rgb = getAvgVar(ivec2(gl_FragCoord.xy));
......
......@@ -9,10 +9,51 @@ using optix::Exception;
Texture::Texture():
_textureType(GL_TEXTURE_2D), _textureUnit(0), _textureID(0),
_textureType(GL_TEXTURE_2D), _textureID(0),
_textureFormat(GL_RGBA32F_ARB), _pixelFormat(GL_RGBA), _dataType(GL_FLOAT)
{
_textureUnit = nextFreeUnit++;
}
Texture::Texture(int width, int height, GLenum format, const char* name) :
Texture()
{
_uniformName = name;
switch (format)
{
case GL_RGBA32F_ARB:
{
_textureFormat = format;
_pixelFormat = GL_RGBA;
_dataType = GL_FLOAT;
break;
}
default:
{
_textureFormat = GL_RGBA32F_ARB;
_pixelFormat = GL_RGBA;
_dataType = GL_FLOAT;
break;
}
}
glGenTextures(1, &_textureID);
glBindTexture(_textureType, _textureID);
// Change these to GL_LINEAR for super- or sub-sampling
glTexParameteri(_textureType, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(_textureType, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// GL_CLAMP_TO_EDGE for linear filtering, not relevant for nearest.
glTexParameteri(_textureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(_textureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(_textureType, _textureID);
glTexImage2D(_textureType, 0, _textureFormat, width, height, 0, _pixelFormat, _dataType, nullptr);
GLuint clearColor[4] = { 0, 0, 0, 0 };
glClearTexImage(_textureID, 0, _pixelFormat, _dataType, &clearColor);
}
Texture::Texture(optix::Buffer buffer, const char* name):
......@@ -63,10 +104,7 @@ bool Texture::createTextureFromBuffer(optix::Buffer buffer, const char* name)
glTexParameteri(_textureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glBindTexture(_textureType, _textureID);
if (buffer_depth <= 1)
glTexImage2D(_textureType, 0, _textureFormat, width, height, 0, _pixelFormat, _dataType, imageData);
if (buffer_depth > 1)
glTexImage3D(_textureType, 0, _textureFormat, width, height, buffer_depth, 0, _pixelFormat, _dataType, imageData);
glTexImage2D(_textureType, 0, _textureFormat, width, height, 0, _pixelFormat, _dataType, imageData);
buffer->unmap();
......@@ -87,10 +125,7 @@ bool Texture::updateTextureFromBuffer(optix::Buffer buffer)
imageData = buffer->map(0, RT_BUFFER_MAP_READ);
glBindTexture(_textureType, _textureID);
if(buffer_depth <= 1)
glTexImage2D(_textureType, 0, _textureFormat, width, height, 0, _pixelFormat, _dataType, imageData);
if (buffer_depth > 1)
glTexImage3D(_textureType, 0, _textureFormat, width, height, buffer_depth, 0, _pixelFormat, _dataType, imageData);
glTexImage2D(_textureType, 0, _textureFormat, width, height, 0, _pixelFormat, _dataType, imageData);
buffer->unmap();
......
......@@ -24,6 +24,7 @@ class Texture
{
public:
Texture();
Texture(int width, int height, GLenum format = GL_RGBA32F_ARB, const char* name = "");
Texture(optix::Buffer buffer, const char* name);
......@@ -47,6 +48,7 @@ public:
GLenum getTextureFormat() const { return _textureFormat; }
GLenum getPixelFormat() const { return _pixelFormat; }
GLenum getDataType() const { return _dataType; }
const char* getName() const { return _uniformName; }
void setFromBufferFormat(RTformat buffer_format);
......
......@@ -45,7 +45,9 @@ void ImGUI::initializeUI(mrf::rendering::OptixRenderer* renderer)
createContext(_ui_width, _ui_height);
_textureList[TextureName::COLOR] = Texture(_renderer->getDisplayBuffer(), "display_buffer");
_textureList[TextureName::OUTPUT] = Texture(_renderer->getOutputBuffer(), "display_buffer");
_textureList[TextureName::OUTPUT] = Texture(_renderer->getOutputBuffer(), "output_buffer");
_textureList[TextureName::POSITION] = Texture(_renderer->getBuffer("position_buffer"), "position_buffer");
_textureList[TextureName::NORMAL] = Texture(_renderer->getBuffer("normal_buffer"), "normal_buffer");
}
void ImGUI::run()
......
......@@ -44,81 +44,56 @@ ImGUI_shader::ImGUI_shader(mrf::gui::fb::Loger::LEVEL const & logging_level) :
_save_all = false;
_config_done = 0;
//Config(start, balancing, reset, clamp, learning sample, learning iteration, total samples)
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 2048)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 64, 8, 2048));
_config_list.push_back(Config(0.5f, true, false, true, 64, 8, 2048));
_config_list.push_back(Config(0.5f, true, true, false, 64, 8, 2048));
_config_list.push_back(Config(0.5f, true, true, true, 64, 8, 2048));//10240*5 + 20480 * 5 + 40960 * 3
_config_list.push_back(Config(0.5f, true, true, true, 64, 8, 2048));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 2048)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 64, 16, 2048));
_config_list.push_back(Config(0.5f, true, false, true, 64, 16, 2048));
_config_list.push_back(Config(0.5f, true, true, false, 64, 16, 2048));
_config_list.push_back(Config(0.5f, true, true, true, 64, 16, 2048));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 2048)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 64, 32, 2048));
_config_list.push_back(Config(0.5f, true, false, true, 64, 32, 2048));
_config_list.push_back(Config(0.5f, true, true, false, 64, 32, 2048));
_config_list.push_back(Config(0.5f, true, true, true, 64, 32, 2048));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 2048)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 8, 2048));
_config_list.push_back(Config(0.5f, true, false, true, 128, 8, 2048));
_config_list.push_back(Config(0.5f, true, true, false, 128, 8, 2048));
_config_list.push_back(Config(0.5f, true, true, true, 128, 8, 2048));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 2048)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 16, 2048));
_config_list.push_back(Config(0.5f, true, false, true, 128, 16, 2048));
_config_list.push_back(Config(0.5f, true, true, false, 128, 16, 2048));
_config_list.push_back(Config(0.5f, true, true, true, 128, 16, 2048));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 4096)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 8, 4096));
_config_list.push_back(Config(0.5f, true, false, true, 128, 8, 4096));
_config_list.push_back(Config(0.5f, true, true, false, 128, 8, 4096));
_config_list.push_back(Config(0.5f, true, true, true, 128, 8, 4096));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 4096)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 16, 4096));
_config_list.push_back(Config(0.5f, true, false, true, 128, 16, 4096));
_config_list.push_back(Config(0.5f, true, true, false, 128, 16, 4096));
_config_list.push_back(Config(0.5f, true, true, true, 128, 16, 4096));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 4096)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 32, 4096));
_config_list.push_back(Config(0.5f, true, false, true, 128, 32, 4096));
_config_list.push_back(Config(0.5f, true, true, false, 128, 32, 4096));
_config_list.push_back(Config(0.5f, true, true, true, 128, 32, 4096));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 4096)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 256, 16, 4096));
_config_list.push_back(Config(0.5f, true, false, true, 256, 16, 4096));
_config_list.push_back(Config(0.5f, true, true, false, 256, 16, 4096));
_config_list.push_back(Config(0.5f, true, true, true, 256, 16, 4096));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 4096)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 512, 8, 4096));
_config_list.push_back(Config(0.5f, true, false, true, 512, 8, 4096));
_config_list.push_back(Config(0.5f, true, true, false, 512, 8, 4096));
_config_list.push_back(Config(0.5f, true, true, true, 512, 8, 4096));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 8192)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 256, 16, 8192));
_config_list.push_back(Config(0.5f, true, false, true, 256, 16, 8192));
_config_list.push_back(Config(0.5f, true, true, false, 256, 16, 8192));
_config_list.push_back(Config(0.5f, true, true, true, 256, 16, 8192));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 8192)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 512, 8, 8192));
_config_list.push_back(Config(0.5f, true, false, true, 512, 8, 8192));
_config_list.push_back(Config(0.5f, true, true, false, 512, 8, 8192));
_config_list.push_back(Config(0.5f, true, true, true, 512, 8, 8192));
_config_list.push_back(Config(0.5f, false, false, false, 1, 1, 8192)); //REF
_config_list.push_back(Config(0.5f, true, false, false, 128, 32, 8192));
_config_list.push_back(Config(0.5f, true, false, true, 128, 32, 8192));
_config_list.push_back(Config(0.5f, true, true, false, 128, 32, 8192));
_config_list.push_back(Config(0.5f, true, true, true, 128, 32, 8192));
//_config_list.push_back(Config(0.5f, true, false, false));
......@@ -137,7 +112,6 @@ void ImGUI_shader::initializeUI(mrf::rendering::OptixRenderer* renderer)
_shaderProg.loadFromFiles(pathToShaders + "simple.vert", pathToShaders + "simple.frag");
_textureList[TextureName::POSITION] = Texture(_renderer->getPositionBuffer(), "position_buffer");
_textureList[TextureName::ALPHA] = Texture(_renderer->getBuffer("alpha_buffer"), "alpha_buffer");
_textureList[TextureName::VARIANCE] = Texture(_renderer->getBuffer("variance_buffer"), "variance_buffer");
}
......@@ -246,7 +220,6 @@ bool ImGUI_shader::doRendering()
{
bool ret = GUI::doRendering();
//_textureList[TextureName::POSITION].updateTextureFromBuffer(_renderer->getPositionBuffer());
_textureList[TextureName::ALPHA].updateTextureFromBuffer(_renderer->getBuffer("alpha_buffer"));
_textureList[TextureName::VARIANCE].updateTextureFromBuffer(_renderer->getBuffer("variance_buffer"));
......@@ -332,6 +305,8 @@ void ImGUI_shader::render(Shader* prg, bool use_tex)
_textureList[TextureName::OUTPUT].activate(prg);
_textureList[TextureName::ALPHA].activate(prg);
_textureList[TextureName::VARIANCE].activate(prg);
_textureList[TextureName::POSITION].activate(prg);
_textureList[TextureName::NORMAL].activate(prg);
}
bindSSBO();
......@@ -347,6 +322,8 @@ void ImGUI_shader::render(Shader* prg, bool use_tex)
_textureList[TextureName::OUTPUT].deactivate();
_textureList[TextureName::ALPHA].deactivate();
_textureList[TextureName::VARIANCE].deactivate();
_textureList[TextureName::POSITION].deactivate();
_textureList[TextureName::NORMAL].deactivate();
}
prg->deactivate();
......
......@@ -46,10 +46,14 @@ void GUI::initializeUI(mrf::rendering::OptixRenderer* renderer)
_width = (_renderer->hasScene()) ? _renderer->renderWidth() : 0;;
_height = (_renderer->hasScene()) ? _renderer->renderHeight() : 0;
createContext(_width, _height);
_textureList[TextureName::COLOR] = Texture(_renderer->getDisplayBuffer(), "display_buffer");
_textureList[TextureName::OUTPUT] = Texture(_renderer->getOutputBuffer(), "output_buffer");
_textureList[TextureName::POSITION] = Texture(_renderer->getBuffer("position_buffer"), "position_buffer");
_textureList[TextureName::NORMAL] = Texture(_renderer->getBuffer("normal_buffer"), "normal_buffer");
}
void GUI::run()
......@@ -256,6 +260,8 @@ bool GUI::doRendering()
_textureList[TextureName::COLOR].updateTextureFromBuffer(_renderer->getDisplayBuffer());
_textureList[TextureName::OUTPUT].updateTextureFromBuffer(_renderer->getOutputBuffer());
_textureList[TextureName::POSITION].updateTextureFromBuffer(_renderer->getBuffer("position_buffer"));
_textureList[TextureName::NORMAL].updateTextureFromBuffer(_renderer->getBuffer("normal_buffer"));
return display_output_buffer_directly;
}
......
......@@ -109,6 +109,7 @@ protected:
COLOR,
OUTPUT,
POSITION,
NORMAL,
ALPHA,
VARIANCE,
FBO
......
......@@ -81,6 +81,7 @@ rtBuffer<Metrics, 2> metrics_buffer;
rtBuffer<float4, 2> alpha_buffer;
rtBuffer<float4, 2> variance_buffer;
rtBuffer<float4, 2> rad_sqr_buffer;
rtBuffer<float3, 2> normal_buffer;
rtDeclareVariable(int, alpha_samples,, );
rtDeclareVariable(int, alpha_passes,, );
rtDeclareVariable(float, start_alpha,, );
......@@ -103,6 +104,11 @@ float toRadiance(float3 rgb)
return (rgb.x*0.265f + 0.67f*rgb.y + 0.065f*rgb.z);
}
float length(uint2 x)
{
return sqrt(float(x.x * x.x + x.y*x.y));
}
float gaussian(float sigma, float x)
{
float sqrSigma = sigma*sigma;
......@@ -152,33 +158,50 @@ RT_PROGRAM void pathtrace_camera()
if (use_filtering == 1
&& (metrics_buffer[launch_index].nb_samples)%alpha_samples > 0
&& (metrics_buffer[launch_index].nb_samples)%alpha_samples < 5
&& (metrics_buffer[launch_index].nb_samples)%alpha_samples < 4
&& metrics_buffer[launch_index].nb_samples > alpha_samples)
// && alpha_buffer[launch_index].w >= 0.f)
{
float alpha = alpha_buffer[launch_index].z;
float L = toRadiance(make_float3(output_buffer[launch_index]));
float3 n = normal_buffer[launch_index];
float3 pos = normalize(position_buffer[launch_index]);
int x[4];
int x[3];
x[0] = launch_index.x == 0? 0 : launch_index.x-1;
x[1] = launch_index.x;
x[2] = min(launch_index.x+1, int(alpha_buffer.size().x-1));
x[3] = launch_index.x;
int y[4];
y[1] = launch_index.y == 0? 0 : launch_index.y-1;
y[0] = launch_index.y;
y[3] = min(launch_index.y+1, int(alpha_buffer.size().y-1));
y[2] = launch_index.y;
int y[3];
y[0] = launch_index.y == 0? 0 : launch_index.y-1;
y[1] = launch_index.y;
y[2] = min(launch_index.y+1, int(alpha_buffer.size().y-1));
uint2 indexes[8]=
{
make_uint2(x[0],y[0]),
make_uint2(x[0],y[1]),
make_uint2(x[0],y[2]),
make_uint2(x[1],y[0]),
make_uint2(x[1],y[2]),
make_uint2(x[2],y[0]),
make_uint2(x[2],y[1]),
make_uint2(x[2],y[2])
};
float sumNum = 0.f;
float sumDen = 0.f;
for (int i = 0; i <4 ; ++i)
{
float alphai = alpha_buffer[make_uint2(x[i], y[i])].z;
// float Li = toRadiance(make_float3(output_buffer[make_uint2(x[i], y[i])]));
sumNum += alphai * gaussian(4, 1) * gaussian(0.1f, alpha - alphai);// * max(Li - L, 0.f);
sumDen += gaussian(4, 1) * gaussian(0.1f, alpha - alphai);//max(Li - L, 0.f);
float alphai = alpha_buffer[indexes[i]].z;
float Li = toRadiance(make_float3(output_buffer[indexes[i]]));
float3 ni = normal_buffer[indexes[i]];
float3 posi = normalize(position_buffer[indexes[i]]);
float error = (1.f - dot(n, ni)) * length(pos - posi);
sumNum += alphai * gaussian(1, length(launch_index - indexes[i])) * gaussian(0.2f, error);
sumDen += gaussian(1, length(launch_index - indexes[i])) * gaussian(0.2f, error);
}
alpha = clamp(sumNum / sumDen, 0.1, 0.9);
......@@ -243,7 +266,7 @@ RT_PROGRAM void pathtrace_camera()
if(prd.depth == 0)
{
impactPos += prd.origin / samples_per_pixel;
impactPos = prd.origin / samples_per_pixel;
}
// Russian roulette termination
......@@ -420,9 +443,6 @@ RT_PROGRAM void pathtrace_camera()
//interactive rgb mode
#ifdef INTERACTIVE_MODE
// if(dot(impactPos, impactPos) == 0.0)
// impactPos = make_float3(launch_index.x, launch_index.y, -100.0);
if (frame_number > 1)
{
float a = 1.0f / (float)frame_number;
......
This diff is collapsed.
......@@ -105,6 +105,7 @@ OptixRenderer::OptixRenderer(mrf::gui::fb::Loger const & loger) :
_reset_iteration = false;
_use_sample_balancing = true;
_clamp_alpha = false;
_filtering_alpha = false;
#if RENDERER_INTERACTIVE
_exposition = 1.f;
......@@ -590,6 +591,13 @@ void OptixRenderer::createRenderContext(bool interactive_mode)
}
}
void OptixRenderer::createImageSamplerFromTexture(int glID, const char* name)
{
optix::TextureSampler tex = _context.get()->createTextureSamplerFromGLImage(glID, RT_TARGET_GL_TEXTURE_2D);
auto buffer = tex->getBuffer();
_context[name]->set(buffer);
}
void OptixRenderer::createRenderTarget()
{
#if RENDERER_INTERACTIVE
......@@ -600,6 +608,9 @@ void OptixRenderer::createRenderTarget()
_position_buffer = _context->createBuffer(RT_BUFFER_OUTPUT, RT_FORMAT_FLOAT3, _render_width, _render_height);
_context["position_buffer"]->set(_position_buffer);
_normal_buffer = _context->createBuffer(RT_BUFFER_OUTPUT, RT_FORMAT_FLOAT3, _render_width, _render_height);
_context["normal_buffer"]->set(_normal_buffer);
}
#endif
......
......@@ -152,6 +152,8 @@ class MRF_EXPORT OptixRenderer : public Renderer
float getStartAlpha() { return _start_alpha; }
optix::Buffer getBuffer(std::string bufferName);
void createImageSamplerFromTexture(int glID, const char* name);
void activatePathLog();
void deactivatePathLog();
......@@ -316,6 +318,7 @@ public:
int _alpha_passes;
float _start_alpha;
optix::Buffer _position_buffer;
optix::Buffer _normal_buffer;
#ifdef MRF_RENDERING_MODE_SPECTRAL
mrf::image::UniformSpectralImage _output_spectral_image;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment