Commit f9d43f02 authored by Florian Oetke's avatar Florian Oetke
Browse files

tweaked bloom, tone mapping and general cleanup

parent 16d96a12
......@@ -68,8 +68,8 @@ frag_shader:luminance = shader/bin/luminance.frag.spv
vert_shader:luminance_adapt = shader/bin/fullscreen.vert.spv
frag_shader:luminance_adapt = shader/bin/luminance_adapt.frag.spv
vert_shader:bloom_filter = shader/bin/fullscreen.vert.spv
frag_shader:bloom_filter = shader/bin/bloom_filter.frag.spv
vert_shader:bloom_apply = shader/bin/fullscreen.vert.spv
frag_shader:bloom_apply = shader/bin/bloom_apply.frag.spv
vert_shader:bloom_blur = shader/bin/bloom_blur.vert.spv
frag_shader:bloom_blur = shader/bin/bloom_blur.frag.spv
......@@ -77,8 +77,5 @@ frag_shader:bloom_blur = shader/bin/bloom_blur.frag.spv
comp_shader:tone_mapping_adjust = shader/bin/tone_mapping_adjust.comp.spv
comp_shader:tone_mapping_histogram = shader/bin/tone_mapping_histogram.comp.spv
vert_shader:tone_mapping_veil = shader/bin/fullscreen.vert.spv
frag_shader:tone_mapping_veil = shader/bin/tone_mapping_veil.frag.spv
vert_shader:tone_mapping_apply = shader/bin/fullscreen.vert.spv
frag_shader:tone_mapping_apply = shader/bin/tone_mapping_apply.frag.spv
......@@ -156,7 +156,9 @@ vec3 dither(vec3 color) {
}
void main() {
//out_color = vec4(tone_mapping(texture(color_sampler, vertex_out.tex_coords).rgb), 1.0);
//out_color = vec4(dither(tone_mapping(resolve_fxaa().rgb)), 1.0);
out_color = vec4(dither(resolve_fxaa().rgb), 1.0);
vec3 color = resolve_fxaa();
if(pcs.options.z>0)
color *= pcs.options.z;
out_color = vec4(dither(color), 1.0);
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "normal_encoding.glsl"
#include "color_conversion.glsl"
layout(location = 0) in Vertex_data {
vec2 tex_coords;
} vertex_out;
layout(location = 0) out vec4 out_color;
layout(set=1, binding = 0) uniform sampler2D bloom_sampler;
layout(push_constant) uniform Settings {
vec4 options;
} pcs;
void main() {
out_color = vec4(textureLod(bloom_sampler, vertex_out.tex_coords, pcs.options.x).rgb, 1);
out_color *= 0.04;
}
......@@ -44,12 +44,7 @@ void main() {
result += read(vertex_out.uv_r3, 0.010381362401148057);
if(COMBINE>0) {
int end = int(round(pcs.options.y));
for(int i=0; i<end; i++) {
result += textureLod(downsampled_color_sampler, vertex_out.uv_center, i).rgb;
}
result /= end+1;
result += textureLod(downsampled_color_sampler, vertex_out.uv_center, 0).rgb;
}
color_out = vec4(result, 1.0);
......
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "normal_encoding.glsl"
#include "color_conversion.glsl"
layout(location = 0) in Vertex_data {
vec2 tex_coords;
} vertex_out;
layout(location = 0) out vec4 out_color;
layout(set=1, binding = 0) uniform sampler2D color_sampler;
layout(set=1, binding = 1) uniform sampler2D avg_log_luminance_sampler;
layout(push_constant) uniform Settings {
vec4 options;
} pcs;
vec3 expose(vec3 color, float threshold) {
float avg_luminance = max(exp(texture(avg_log_luminance_sampler, vec2(0.5, 0.5)).r), 0.0001);
float key = 1.03f - (2.0f / (2 + log(avg_luminance + 1)/log(10)));
float exposure = clamp(key/avg_luminance, 0.1, 6.0) + 0.5;
if(pcs.options.z>0) {
exposure = pcs.options.z;
}
exposure = log2(exposure);
exposure -= threshold;
return color * exp2(exposure);
}
void main() {
float lower_bound = max(exp(texelFetch(avg_log_luminance_sampler, ivec2(0, 0), 0).r), 0.0001);
float upper_bound = max(exp(texelFetch(avg_log_luminance_sampler, ivec2(1, 0), 0).r), 0.0001);
vec3 color = texture(color_sampler, vertex_out.tex_coords).rgb;
float lum = rgb2cie(color*10).y;
//color *= smoothstep(lower_bound, upper_bound, lum)*0.95+0.05;
color *= 0.087 * 10.0;
out_color = vec4(color, 1.0);
}
......@@ -9,17 +9,15 @@ layout (constant_id = 3) const float HISTOGRAM_MAX = 10;
layout (local_size_x = 128, local_size_y = 1, local_size_z = 1 ) in;
layout(set=1, binding = 1) buffer Data {
uint histogram[HISTOGRAM_SLOTS + 4];
uint histogram[HISTOGRAM_SLOTS + 2];
};
layout (set=1, binding = 2, r16f) uniform image2D adjustment_factor;
layout(set=1, binding = 3) buffer PrevData {
uint prev_histogram[HISTOGRAM_SLOTS + 4];
uint prev_histogram[HISTOGRAM_SLOTS + 2];
};
layout (set=1, binding = 5, r16f) uniform image2D avg_log_lum_buffer;
layout(push_constant) uniform Push_constants {
// min/max log display luminance
vec4 parameters;
......@@ -92,11 +90,11 @@ void main() {
// adaption
if(local_id==0) {
float L0 = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS+2]);
float p0 = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS+3]);
float L0 = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS]);
float p0 = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS+1]);
float t = global_uniforms.time.z;
float t0_pigment = 100; // pigment bleaching/regeneration time
float t0_neural = 2.08; // neural adaption time
float t0_neural = 1.08; // neural adaption time
float pigment_regen_speed = 0.01;
float n = total;
......@@ -143,42 +141,8 @@ void main() {
*/
sigma = sigma_b * sigma_n * sigma_c;
histogram[HISTOGRAM_SLOTS+2] = floatBitsToUint(L);
histogram[HISTOGRAM_SLOTS+3] = floatBitsToUint(p);
float sum = 0;
int top = 0;
int top_lower = 0;
for(int i=HISTOGRAM_SLOTS-1; i>0; i--) {
sum += histogram[i];
if(sum < total*0.02) {
top = i;
} else if(sum < total*0.2) {
top_lower = i;
} else {
break;
}
}
float avg_lum = exp(index_to_log_lum(clamp(int(top), 0, HISTOGRAM_SLOTS-1)));
float lower_lum = exp(index_to_log_lum(clamp(int(top_lower), 0, HISTOGRAM_SLOTS-1)));
float prev_avg_lum = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS+1]);
float prev_lower_lum = uintBitsToFloat(prev_histogram[HISTOGRAM_SLOTS]);
lower_lum = lower_lum + (prev_lower_lum-lower_lum)*exp(-t/t0_neural);
avg_lum = avg_lum + (prev_avg_lum-avg_lum)*exp(-t/t0_neural);
histogram[HISTOGRAM_SLOTS] = floatBitsToUint(lower_lum);
histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(avg_lum);
float upper_bound = log(avg_lum);
float lower_bound = log(avg_lum - (avg_lum-lower_lum));
imageStore(avg_log_lum_buffer, ivec2(0,0), vec4(lower_bound));
imageStore(avg_log_lum_buffer, ivec2(0,1), vec4(lower_bound));
imageStore(avg_log_lum_buffer, ivec2(1,0), vec4(upper_bound));
imageStore(avg_log_lum_buffer, ivec2(1,1), vec4(upper_bound));
histogram[HISTOGRAM_SLOTS] = floatBitsToUint(L);
histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(p);
}
// constant calculated with doc/tonemapping/calc_delta_r.cpp
......
......@@ -12,21 +12,12 @@ layout(location = 0) out vec4 out_color;
layout(set=1, binding = 0) uniform sampler2D color_sampler;
layout(set=1, binding = 1) uniform sampler2D histogram_adjustment_sampler;
layout(set=1, binding = 2) uniform sampler2D veil_sampler;
layout (constant_id = 0) const float HISTOGRAM_MIN = 0;
layout (constant_id = 1) const float HISTOGRAM_MAX = 0;
layout (constant_id = 2) const int HISTOGRAM_SLOTS = 256;
/*
float tm_luminance(vec3 c) {
vec3 cie_color = rgb2cie(c);
return cie_color.y * (1.33*(1+(cie_color.y+cie_color.z)/cie_color.x)-1.68);
// vec3 f = vec3(0.2126,0.7152,0.0722);
// return max(dot(c, f), 0.0);
}
*/
float calc_histogram_index_fp(float luminance) {
luminance = (luminance-HISTOGRAM_MIN) / (HISTOGRAM_MAX-HISTOGRAM_MIN);
return clamp(luminance, 0, 1);
......@@ -41,9 +32,6 @@ void main() {
vec3 color = textureLod(color_sampler, vertex_out.tex_coords, 0).rgb;
color *= 10;
vec3 veil = textureLod(veil_sampler, vertex_out.tex_coords, 0).rgb;
color = 0.913*color + veil;
vec3 cie_color = rgb2cie(color);
float lum = cie_color.y;
......
......@@ -10,7 +10,6 @@ layout (constant_id = 3) const float HISTOGRAM_MAX = 10;
layout (local_size_x_id = 1, local_size_y_id = 1, local_size_z = 1 ) in;
layout (set=1, binding = 0, rgba16f) uniform readonly image2D input_image;
layout (set=1, binding = 4, rgba16f) uniform readonly image2D veil_image;
layout(set=1, binding = 1) buffer Data
{
......@@ -52,8 +51,6 @@ void main() {
for(uint x=gl_GlobalInvocationID.x; x<data_size.x; x+=stride.x) {
for(uint y=gl_GlobalInvocationID.y; y<data_size.y; y+=stride.y) {
vec3 color = imageLoad(input_image, ivec2(x,y)).rgb;
vec3 veil = imageLoad(veil_image, ivec2(x,y)).rgb;
color = 0.913*color + veil;
float lum = log(tm_luminance(color*10));
atomicAdd(local_histogram[calc_histogram_index(lum)], 1);
}
......
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "color_conversion.glsl"
layout(location = 0) in Vertex_data {
vec2 tex_coords;
} vertex_out;
layout(location = 0) out vec4 out_color;
layout(set=1, binding = 0) uniform sampler2D color_sampler;
void main() {
ivec2 input_size = textureSize(color_sampler, 0);
int cx = int(vertex_out.tex_coords.x*input_size.x);
int cy = int(vertex_out.tex_coords.y*input_size.y);
float weights = 0.0f;
vec3 sum = vec3(0);
/*
for(int y = max(0,cy-input_size.y/10); y<min(input_size.y, cy+input_size.y/10); y++) {
for(int x = max(0,cx-input_size.x/10); x<min(input_size.x, cx+input_size.x/10); x++) {
if(x!=cx || y!=cy) {
float dx = x-cx;
float dy = y-cy;
float angle = sqrt(dx*dx + dy*dy) * 0.01745329251;
float weight = abs(cos(angle) / (angle*angle));
weights += weight;
sum += weight * texelFetch(color_sampler, ivec2(x,y), 0).rgb;
}
}
}
*/
out_color = weights>0.000001 ? vec4(0.087 * sum/weights, 1.0) : vec4(0,0,0,1);
}
......@@ -480,6 +480,10 @@ namespace mirrage {
nk_checkbox_label(ctx, "Bloom", &bool_nk_wrapper);
renderer_settings.bloom = bool_nk_wrapper == 1;
bool_nk_wrapper = renderer_settings.tonemapping ? 1 : 0;
nk_checkbox_label(ctx, "Tonemapping", &bool_nk_wrapper);
renderer_settings.tonemapping = bool_nk_wrapper == 1;
nk_layout_row_dynamic(ctx, 20, 2);
......@@ -617,8 +621,8 @@ namespace mirrage {
auto tone_mapping_pass = _meta_system.renderer().find_pass<renderer::Tone_mapping_pass>();
if(tone_mapping_pass) {
auto&& histogram = tone_mapping_pass->last_histogram();
auto histogram_sum = std::accumulate(begin(histogram), end(histogram) - 4, 0.0);
auto max_histogram = std::max_element(begin(histogram), end(histogram) - 4);
auto histogram_sum = std::accumulate(begin(histogram), end(histogram) - 2, 0.0);
auto max_histogram = std::max_element(begin(histogram), end(histogram) - 2);
auto ctx = _gui.ctx();
if(nk_begin_titled(
......@@ -630,7 +634,7 @@ namespace mirrage {
nk_layout_row_dynamic(ctx, 400, 1);
nk_chart_begin(
ctx, NK_CHART_COLUMN, static_cast<int>(histogram.size() - 4), 0, *max_histogram);
ctx, NK_CHART_COLUMN, static_cast<int>(histogram.size() - 2), 0, *max_histogram);
for(auto i : util::range(histogram.size() - 1)) {
auto state = nk_chart_push(ctx, histogram[i]);
if(state & NK_CHART_HOVERING) {
......@@ -641,11 +645,11 @@ namespace mirrage {
nk_layout_row_dynamic(ctx, 25, 2);
nk_label(ctx, "Luminance", NK_TEXT_CENTERED);
auto log_lum_range = std::log2(_meta_system.renderer().gbuffer().max_luminance)
- std::log2(_meta_system.renderer().gbuffer().min_luminance);
auto log_lum_range = std::log(_meta_system.renderer().gbuffer().max_luminance)
- std::log(_meta_system.renderer().gbuffer().min_luminance);
auto log_lum =
static_cast<double>(_last_selected_histogram) / (histogram.size() - 1) * log_lum_range
+ std::log2(_meta_system.renderer().gbuffer().min_luminance);
+ std::log(_meta_system.renderer().gbuffer().min_luminance);
auto lum = std::exp(log_lum);
nk_label(ctx, to_fixed_str(lum, 5).c_str(), NK_TEXT_CENTERED);
......@@ -655,12 +659,10 @@ namespace mirrage {
nk_label(ctx, "La", NK_TEXT_CENTERED);
nk_label(ctx, (to_fixed_str(histogram[histogram.size() - 2], 4)).c_str(), NK_TEXT_CENTERED);
nk_label(ctx, "range", NK_TEXT_CENTERED);
nk_label(ctx, "p(La)", NK_TEXT_CENTERED);
nk_label(ctx,
(to_fixed_str(1.f - histogram[histogram.size() - 4], 4)).c_str(),
(to_fixed_str(1.f - histogram[histogram.size() - 1], 4)).c_str(),
NK_TEXT_CENTERED);
nk_label(ctx, "offset", NK_TEXT_CENTERED);
nk_label(ctx, (to_fixed_str(histogram[histogram.size() - 3], 4)).c_str(), NK_TEXT_CENTERED);
nk_label(ctx, "Trimmings", NK_TEXT_CENTERED);
nk_label(ctx,
......@@ -670,16 +672,6 @@ namespace mirrage {
NK_TEXT_CENTERED);
auto renderer_settings = _meta_system.renderer().settings();
auto bool_nk_wrapper = 0;
bool_nk_wrapper = renderer_settings.histogram_adjustment ? 1 : 0;
nk_checkbox_label(ctx, "Histogram Adjustment", &bool_nk_wrapper);
renderer_settings.histogram_adjustment = bool_nk_wrapper == 1;
bool_nk_wrapper = renderer_settings.histogram_trim ? 1 : 0;
nk_checkbox_label(ctx, "Histogram Trim", &bool_nk_wrapper);
renderer_settings.histogram_trim = bool_nk_wrapper == 1;
nk_property_float(ctx,
"Min Display Lum.",
......
......@@ -30,19 +30,19 @@ namespace mirrage::renderer {
int shadowmap_resolution = 2048;
int shadow_quality = 99; // 0 = lowest
bool gi = true;
bool gi_highres = true;
int gi_diffuse_mip_level = 1;
int gi_min_mip_level = 0;
int gi_samples = 64;
int gi_lowres_samples = 512;
bool gi_jitter_samples = false;
int gi_low_quality_mip_levels = 0;
float exposure_override = 0.f;
bool histogram_adjustment = true;
bool histogram_trim = true;
float min_display_luminance = 2.f;
float max_display_luminance = 150.0f;
bool gi = true;
bool gi_highres = true;
int gi_diffuse_mip_level = 1;
int gi_min_mip_level = 0;
int gi_samples = 64;
int gi_lowres_samples = 512;
bool gi_jitter_samples = false;
int gi_low_quality_mip_levels = 0;
bool tonemapping = true;
float exposure_override = 0.f;
float min_display_luminance = 2.f;
float max_display_luminance = 150.0f;
bool ssao = true;
bool bloom = true;
......
......@@ -32,9 +32,6 @@ namespace mirrage::renderer {
util::maybe<graphic::Texture_2D_array&> voxels;
util::maybe<graphic::Texture_2D&> avg_log_luminance;
util::maybe<graphic::Render_target_2D&> bloom;
float min_luminance = 1e-4f;
float max_luminance = 1e6f;
};
......
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