Commit 46b3a06f authored by Florian Oetke's avatar Florian Oetke
Browse files

renderer extensions and smaller bug-fixes

parent 37c0f29b
Pipeline #2347 passed with stage
in 4 minutes and 28 seconds
......@@ -37,6 +37,13 @@ void main() {
const vec2 uv_01 = vertex_out.tex_coords + vec2(-1, 1) / tex_size;
const ivec2[] center_offsets = ivec2[4](ivec2(0,0), ivec2(1,0), ivec2(1,1), ivec2(0,1));
ivec2 iuv = ivec2(tex_size*vertex_out.tex_coords);
if(iuv.x<=1 || iuv.y<=1 || iuv.x>=tex_size.x-2 || iuv.y>=tex_size.y-2) {
out_depth = texelFetch(depth_sampler, ivec2(vertex_out.tex_coords * tex_size), 0);
out_mat_data = texelFetch(mat_data_sampler, ivec2(vertex_out.tex_coords * tex_size), 0);
return;
}
// sample depth and calculate score based on their difference to the center depth value
vec4 depth_00 = textureGather(depth_sampler, uv_00, 0);
vec4 depth_10 = textureGather(depth_sampler, uv_10, 0);
......
......@@ -19,6 +19,11 @@ void main() {
vec2 hws_step = 1.0 / hws_size;
ivec2 hws_uv = ivec2(hws_size * vertex_out.tex_coords.xy);
if(hws_uv.x<=1 || hws_uv.y<=1 || hws_uv.x>=hws_size.x-2 || hws_uv.y>=hws_size.y-2) {
out_weight = vec4(0,0,0,1);
return;
}
float weights[9];
vec4 w = textureGather(success_sampler, vertex_out.tex_coords.xy-hws_step, 0);
weights[0] = w[0];
......@@ -38,5 +43,5 @@ void main() {
weight.r = mix(weight.r, median_float(weights), 0.2);
out_weight = vec4(weight.r * (weight.g+1), 0, 0, 1);
out_weight = vec4(min(100, weight.r * (weight.g+1)), 0, 0, 1);
}
......@@ -87,7 +87,7 @@ vec3 gi_sample(int lod, int base_mip) {
ivec2 uv = ivec2(vertex_out.tex_coords * texture_size);
// clamp area to reduce artefacts around borders
if(uv.y >= texture_size.y-1 || uv.x >= texture_size.x-1)
if(uv.x<=0 || uv.y<=0 || uv.y >= texture_size.y-1 || uv.x >= texture_size.x-1)
return vec3(0, 0, 0);
// fetch the depth/normal of the target pixel and reconstruct its view-space position
......@@ -101,9 +101,9 @@ vec3 gi_sample(int lod, int base_mip) {
float angle = random(vec4(vertex_out.tex_coords, lod, global_uniforms.time.w)).r * 2*PI;
float outer_radius = R;
float inner_radius = LAST_SAMPLE==0 ? outer_radius / 2.0 - 4.0 : 0.0;
float angle_step = PI * 2.0 / pow((sqrt(5.0) + 1.0) / 2.0, 2.0);
float outer_radius = R+2.0;
float inner_radius = LAST_SAMPLE==0 ? outer_radius / 2.0 : 2.0;
float angle_step = 2.39996;// PI * 2.0 / pow((sqrt(5.0) + 1.0) / 2.0, 2.0);
float normal_dir = 0.5*PI;
float normal_weight = abs(N.z);
......@@ -114,7 +114,7 @@ vec3 gi_sample(int lod, int base_mip) {
for(int i=0; i<SAMPLES; i++) {
float r = max(
4.0,
2.0,
mix(inner_radius, outer_radius, sqrt(float(i) / float(SAMPLES))));
float a = i * angle_step + angle;
......@@ -196,7 +196,7 @@ vec3 calc_illumination_from(int lod, vec2 tex_size, ivec2 src_uv, vec2 shaded_uv
// if the material is an emitter (mat_data.b=0), flip the normal if that would result in a higher
// itensity (approximates light emitted from the backside by assuming rotation invariance)
NdotL_src = mix(max(clamp(dot(-N, dir), 0.0, 1.0), NdotL_src), NdotL_src, step(0.0001, mat_data.b));
NdotL_src = mix(NdotL_src, max(clamp(dot(-N, dir), 0.0, 1.0), NdotL_src), step(0.999999, mat_data.b));
// calculate the size of the differential area
float cos_alpha = Pn.z;
......
......@@ -77,6 +77,12 @@ void main() {
// read diffuse color, modulate with modulo if equal to min/max of neighborhood => noise
ivec2 result_sampler_size = textureSize(result_sampler, 0).xy;
ivec2 uv = ivec2(result_sampler_size * vertex_out.tex_coords);
if(uv.x<=1 || uv.y<=1 || uv.x>=result_sampler_size.x-2 || uv.y>=result_sampler_size.y-2) {
out_color = vec4(texelFetch(result_sampler, uv, 0).rgb, 1);
return;
}
vec3 colors[9] = vec3[](
texelFetchOffset(result_sampler, uv, 0, ivec2(-1,-1)).rgb,
texelFetchOffset(result_sampler, uv, 0, ivec2(-1, 0)).rgb,
......@@ -89,19 +95,6 @@ void main() {
texelFetchOffset(result_sampler, uv, 0, ivec2( 1, 1)).rgb
);
// clamp texture coordinates
float w = result_sampler_size.x;
float h = result_sampler_size.y;
colors[0] = uv.x>0 && uv.y>0 ? colors[0] : colors[4];
colors[1] = uv.x>0 ? colors[1] : colors[4];
colors[2] = uv.y>0 ? colors[2] : colors[4];
colors[3] = uv.y<h ? colors[3] : colors[4];
colors[5] = uv.x<w && uv.y>0 ? colors[5] : colors[4];
colors[6] = uv.x>0 && uv.y<h ? colors[6] : colors[4];
colors[7] = uv.x<w ? colors[7] : colors[4];
colors[8] = uv.x<w && uv.y<h ? colors[8] : colors[4];
float min_c = pixel_intensity(colors[0]);
float max_c = min_c;
......
......@@ -29,6 +29,13 @@ layout (constant_id = 0) const int NO_PREV_RESULT = 0;
#include "upsample.glsl"
void main() {
vec2 tex_size = textureSize(depth_sampler, 0);
ivec2 iuv = ivec2(tex_size*vertex_out.tex_coords);
if(iuv.x<=1 || iuv.y<=1 || iuv.x>=tex_size.x-2 || iuv.y>=tex_size.y-2) {
out_color = vec4(0,0,0, NO_PREV_RESULT);
return;
}
out_color = vec4(upsampled_result(depth_sampler, mat_data_sampler,
prev_depth_sampler, prev_mat_data_sampler,
prev_level_result_sampler, vertex_out.tex_coords), NO_PREV_RESULT);
......
......@@ -19,12 +19,19 @@ layout(push_constant) uniform Push_constants {
} pcs;
void main() {
ivec2 result_sampler_size = textureSize(prev_level_sampler, 0).xy;
ivec2 uv = ivec2(result_sampler_size * vertex_out.tex_coords);
if(uv.x<=0 || uv.y<=0 || uv.x>=result_sampler_size.x-1 || uv.y>=result_sampler_size.y-1) {
out_weight = vec4(0, 0,0,1);
return;
}
vec4 weights = textureGather(prev_level_sampler, vertex_out.tex_coords.xy, 0);
float min_weight = min(weights[0], min(weights[1], min(weights[2], weights[3])));
float avg_weight = dot(vec4(1.0), weights) / 4;
float mip = pcs.prev_projection[0][3];
float weight = mix(min_weight, avg_weight, clamp(mip,0,1));
float weight = mix(min_weight, avg_weight, clamp(mip/2,0,1));
out_weight = vec4(weight, 0,0,1);
}
......@@ -48,14 +48,15 @@ void main() {
roughness = mix(0.01, 0.99, roughness*roughness);
float emmissive_power = texture(mat_data2_sampler, tex_coords).r;
float emissive_power = texture(mat_data2_sampler, tex_coords).r;
float emissive_only = step(0.1, emissive_power);
albedo.rgb *= mix(vec3(1), model_uniforms.material_properties.rgb, step(0.1, emmissive_power));
albedo.rgb *= mix(vec3(1), model_uniforms.material_properties.rgb, emissive_only);
depth_out = vec4(-view_pos.z / global_uniforms.proj_planes.y, 0,0,1);
albedo_mat_id = vec4(albedo.rgb, 1.0);
mat_data_out = vec4(encode_normal(N), 1, 0);
color_out = vec4(albedo.rgb * emmissive_power * model_uniforms.material_properties.a, 1.0);
mat_data_out = vec4(encode_normal(N), mix(roughness, 1, emissive_only), metallic);
color_out = vec4(albedo.rgb * emissive_power * model_uniforms.material_properties.a, 1.0);
color_diffuse_out = color_out;
}
......
......@@ -19,7 +19,7 @@ layout(set=1, binding = 3) buffer PrevData {
};
layout(push_constant) uniform Push_constants {
// min/max log display luminance
// min/max log display luminance; La, Sigma override
vec4 parameters;
} pcs;
......@@ -90,63 +90,64 @@ void main() {
// adaption
if(local_id==0) {
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 = 0.08; // neural adaption time
float n = total;
uint median = 0;
if(n>0) {
float median_idx = (n+1)*0.8;
float sum = 0;
for(uint i=0; i<HISTOGRAM_SLOTS; i++) {
sum += local_histogram[i];
if(sum >= median_idx) {
median = i;
break;
if(pcs.parameters.w>=0) {
sigma = pcs.parameters.w;
} else {
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 = 0.08; // neural adaption time
float La=0;
if(pcs.parameters.z>=0) {
La = pcs.parameters.z;
} else {
float n = total;
uint median = 0;
if(n>0) {
float median_idx = (n+1)*0.8;
float sum = 0;
for(uint i=0; i<HISTOGRAM_SLOTS; i++) {
sum += local_histogram[i];
if(sum >= median_idx) {
median = i;
break;
}
}
}
}
}
float La = exp(index_to_log_lum(clamp(int(median), 0, HISTOGRAM_SLOTS-1)));
La = clamp(La, 1, 4e3);
//La /= 140.0/5.0;
//La = clamp(La, 0.001, 15);
// correction faktor based on observations in various lighting conditions.
// for some reason the original equation is too dark in bright but correct in dark environments
//float La_scale = 100.8225 - 99.99274*exp(-0.4800563*La);
//La /= max(1, La_scale);
float pLa = 1e1 / (1e1 + La);
float p = pLa + (p0-pLa) * exp(-t/(t0_pigment*pLa));
float L = La + (L0-La)*exp(-t/t0_neural);
La = exp(index_to_log_lum(clamp(int(median), 0, HISTOGRAM_SLOTS-1)));
La = clamp(La, 1, 4e3);
}
float sigma_b = 1.0 / p;
float pLa = 1e1 / (1e1 + La);
float p = pLa + (p0-pLa) * exp(-t/(t0_pigment*pLa));
float L = La + (L0-La)*exp(-t/t0_neural);
float sigma_b = 1.0 / p;
// rods
float sigma_n = pow(10, (2.311*pow(L,0.3604))
/(pow(L, 0.3604) + pow(0.008061,0.3604)) -2.749);
float sigma_c = pow(10, (1.735*pow(L,0.9524))
/(pow(L, 0.9524) + pow(1.277,0.9524)) +0.005684);
/*
// cones
float sigma_n = pow(10, (2.027*pow(L,0.6406))
/(pow(L, 0.6406) + pow(5.859,0.6406)) +0.01711);
float sigma_c = pow(10, (1.929*pow(L,0.8471))
/(pow(L, 0.8471) + pow(1048.0,0.8471)) +0.01820);
*/
sigma = sigma_b * sigma_n * sigma_c;
sigma = clamp(sigma, 1, 4e3);
// rods
float sigma_n = pow(10, (2.311*pow(L,0.3604))
/(pow(L, 0.3604) + pow(0.008061,0.3604)) -2.749);
float sigma_c = pow(10, (1.735*pow(L,0.9524))
/(pow(L, 0.9524) + pow(1.277,0.9524)) +0.005684);
//sigma = La;
/*
// cones
float sigma_n = pow(10, (2.027*pow(L,0.6406))
/(pow(L, 0.6406) + pow(5.859,0.6406)) +0.01711);
float sigma_c = pow(10, (1.929*pow(L,0.8471))
/(pow(L, 0.8471) + pow(1048.0,0.8471)) +0.01820);
*/
sigma = sigma_b * sigma_n * sigma_c;
sigma = clamp(sigma, 1, 4e3);
histogram[HISTOGRAM_SLOTS] = floatBitsToUint(L);
histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(p);
histogram[HISTOGRAM_SLOTS] = floatBitsToUint(L);
histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(p);
}
}
// constant calculated with doc/tonemapping/calc_delta_r.cpp
......@@ -249,11 +250,6 @@ void main() {
for(uint i=local_id; i<HISTOGRAM_SLOTS; i+=local_size) {
histogram[i] = local_histogram[i];
}
if(local_id==0) {
//histogram[HISTOGRAM_SLOTS] = floatBitsToUint(1.0-display_range_factor);
//histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(0);
}
memoryBarrierShared();
barrier();
......
......@@ -17,6 +17,11 @@ 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;
layout(push_constant) uniform Push_constants {
// r:desaturation weight
vec4 parameters;
} pcs;
float calc_histogram_index_fp(float luminance) {
luminance = (luminance-HISTOGRAM_MIN) / (HISTOGRAM_MAX-HISTOGRAM_MIN);
......@@ -37,7 +42,7 @@ void main() {
// scotopic simulation
float scotopic_lum = min(lum, max_mesoptic);
float alpha = clamp((scotopic_lum - min_mesoptic) / (max_mesoptic-min_mesoptic), 0.0, 1.0);
cie_color = mix(cie_white * scotopic_lum, cie_color, alpha);
cie_color = mix(mix(cie_white * scotopic_lum, cie_color, alpha), cie_color, pcs.parameters.x);
// histogram adjustment / tone mapping
float idx = calc_histogram_index_fp(log(lum));
......
......@@ -41,10 +41,10 @@ float calc_upsampled_weights(sampler2D highres_depth_sampler, sampler2D highres_
uv_01 = tex_coords + vec2(-1, 1) / tex_size;
// initialize the per-pixel weights with gaussian weights
weight_00 = vec4(0.125794409230998, 0.132980760133811, 0.125794409230998, 0.118996412547595);
weight_10 = vec4(0.125794409230998, 0.106482668507451, 0.100728288549083, 0.118996412547595);
weight_11 = vec4(0.100728288549083, 0.085264655436308, 0.100728288549083, 0.118996412547595);
weight_01 = vec4(0.100728288549083, 0.106482668507451, 0.125794409230998, 0.118996412547595);
weight_00 = vec4(1,2,1,1)/20.0;//vec4(0.125794409230998, 0.132980760133811, 0.125794409230998, 0.118996412547595);
weight_10 = vec4(2,1,1,1)/20.0;//vec4(0.125794409230998, 0.106482668507451, 0.100728288549083, 0.118996412547595);
weight_11 = vec4(1,1,1,2)/20.0;//vec4(0.100728288549083, 0.085264655436308, 0.100728288549083, 0.118996412547595);
weight_01 = vec4(1,1,2,1)/20.0;//vec4(0.100728288549083, 0.106482668507451, 0.125794409230998, 0.118996412547595);
// calculate the maximum depth deviation based on the distance, to reduce bluring
// near the camera where it's most noticable
......
......@@ -260,7 +260,10 @@ namespace mirrage::graphic {
if(debug) {
_enabled_layers = check_layers({"VK_LAYER_LUNARG_standard_validation"});
_enabled_layers = check_layers({"VK_LAYER_LUNARG_standard_validation",
"VK_LAYER_LUNARG_parameter_validation",
"VK_LAYER_LUNARG_core_validation",
"VK_LAYER_GOOGLE_threading"});
required_extensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
}
......
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