Commit 5daec22f authored by Florian Oetke's avatar Florian Oetke
Browse files

point lights and refactored lighting/tone-mapping to use physically correct values [fixes #26]

parent d65f2840
......@@ -6,6 +6,9 @@ frag_shader:blit = shader/bin/blit.frag.spv
vert_shader:light_directional = shader/bin/fullscreen.vert.spv
frag_shader:light_directional = shader/bin/light_directional.frag.spv
vert_shader:light_point = shader/bin/light_point.vert.spv
frag_shader:light_point = shader/bin/light_point.frag.spv
vert_shader:shadow_model = shader/bin/shadow_model.vert.spv
vert_shader:shadow_model_animated = shader/bin/shadow_model_animated.vert.spv
vert_shader:shadow_model_animated_dqs = shader/bin/shadow_model_animated_dqs.vert.spv
......
......@@ -44,7 +44,7 @@ void main() {
result += read(vertex_out.uv_r3, 0.010381362401148057);
if(COMBINE>0) {
result += textureLod(downsampled_color_sampler, vertex_out.uv_center, 0).rgb;
result = result/2 + textureLod(downsampled_color_sampler, vertex_out.uv_center, 0).rgb/2;
}
color_out = vec4(result, 1.0);
......
......@@ -34,7 +34,7 @@ vec3 calculate_gi(vec2 uv, vec3 radiance, vec3 specular,
vec3 diff = albedo * radiance*(1.0 - F0*brdf.x) / PI;
vec3 spec = specular.rgb * (F0*brdf.x + brdf.y);
return max(diff + spec, vec3(0,0,0))*1000.0;
return max(diff + spec, vec3(0,0,0));
}
#endif
......@@ -211,7 +211,7 @@ vec3 calc_illumination_from(int lod, vec2 tex_size, ivec2 src_uv, vec2 shaded_uv
} else {
// fetch the light emitted by the src pixel, modulate it by the calculated factor and return it
vec3 radiance = texelFetch(color_sampler, src_uv, 0).rgb/1000.0;
vec3 radiance = texelFetch(color_sampler, src_uv, 0).rgb;
return radiance * weight;
}
}
......
......@@ -129,7 +129,7 @@ void main() {
float factor_normal = mix(1, 1.0 - smoothstep(0.6, 0.9, abs(dot(N, hit_N))), step(0.0001, hit_mat_data.b));
vec3 color = sample_color_lod(roughness, hit_uv, dir, coneTheta)/1000.0;
vec3 color = sample_color_lod(roughness, hit_uv, dir, coneTheta);
out_color.rgb = max(color * factor_distance * factor_normal, vec3(0));
......@@ -147,7 +147,7 @@ void main() {
else
history_weight = 1.0-1.0/(1+history_weight);
out_color *= 1.0 - min(history_weight, 0.96);
out_color *= 1.0 - min(history_weight, 0.94);
out_color = max(out_color, vec4(0));
}
......
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "global_uniforms.glsl"
#include "normal_encoding.glsl"
#include "poisson.glsl"
#include "random.glsl"
#include "brdf.glsl"
layout(location = 0) out vec4 out_color;
layout(location = 1) out vec4 out_color_diff;
layout(input_attachment_index = 0, set=1, binding = 0) uniform subpassInput depth_sampler;
layout(input_attachment_index = 1, set=1, binding = 1) uniform subpassInput albedo_mat_id_sampler;
layout(input_attachment_index = 2, set=1, binding = 2) uniform subpassInput mat_data_sampler;
layout(push_constant) uniform Per_model_uniforms {
mat4 transform;
vec4 light_color;
vec4 light_data; // R=src_radius, GBA=position
vec4 light_data2; // R=shadowmapID, GB=screen width/height
} model_uniforms;
const float PI = 3.14159265359;
float calc_att(float dist) {
dist /= model_uniforms.light_data.r;
float att = 1.0 / max(dist*dist, 0.01*0.01);
return att;
}
void main() {
float depth = subpassLoad(depth_sampler).r;
vec3 position = position_from_ldepth(gl_FragCoord.xy/model_uniforms.light_data2.gb, depth);
vec3 L = model_uniforms.light_data.gba - position;
float dist = length(L);
L /= dist;
dist /= model_uniforms.light_data.r;
float att = 1.0 / max(dist*dist, 0.01*0.01);
float intensity = model_uniforms.light_color.a * calc_att(dist);
intensity = max(0.0, intensity-0.005) / (1.0 - 0.01);
if(intensity<=0.0) {
out_color = vec4(0,0,0,0);
out_color_diff = vec4(0,0,0,0);
return;
}
vec3 radiance = model_uniforms.light_color.rgb * intensity;
vec4 albedo_mat_id = subpassLoad(albedo_mat_id_sampler);
vec4 mat_data = subpassLoad(mat_data_sampler);
vec3 V = -normalize(position);
vec3 albedo = albedo_mat_id.rgb;
int material = int(albedo_mat_id.a*255);
vec3 N = decode_normal(mat_data.rg);
float roughness = mat_data.b;
float metallic = mat_data.a;
vec3 F0 = mix(vec3(0.04), albedo.rgb, metallic);
albedo.rgb *= 1.0 - metallic;
vec3 diffuse;
out_color = vec4(brdf(albedo, F0, roughness, N, V, L, radiance, diffuse), 1.0);
out_color_diff = vec4(diffuse, 1.0);
}
#version 450
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
#include "global_uniforms.glsl"
layout(location = 0) in vec3 position;
layout(push_constant) uniform Per_model_uniforms {
mat4 transform;
vec4 light_color;
vec4 light_data; // R=src_radius, GBA=position
vec4 light_data2; // R=shadowmapID
} model_uniforms;
out gl_PerVertex {
vec4 gl_Position;
};
void main() {
gl_Position = model_uniforms.transform * vec4(position, 1.0f);
}
......@@ -94,13 +94,12 @@ void main() {
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 = 1.08; // neural adaption time
float pigment_regen_speed = 0.01;
float t0_neural = 0.08; // neural adaption time
float n = total;
uint median = 0;
if(n>0) {
float median_idx = (n+1)/2.0;
float median_idx = (n+1)*0.8;
float sum = 0;
for(uint i=0; i<HISTOGRAM_SLOTS; i++) {
sum += local_histogram[i];
......@@ -112,15 +111,17 @@ void main() {
}
float La = exp(index_to_log_lum(clamp(int(median), 0, HISTOGRAM_SLOTS-1)));
La = clamp(La, 0.001, 15);
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 La_scale = 100.8225 - 99.99274*exp(-0.4800563*La);
//La /= max(1, La_scale);
float pLa = 0.0001 / (0.0001 + La);
float p = pLa + (p0-pLa) * exp(-t/(t0_pigment*max(pLa,pigment_regen_speed)));
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;
......@@ -140,6 +141,9 @@ void main() {
/(pow(L, 0.8471) + pow(1048.0,0.8471)) +0.01820);
*/
sigma = sigma_b * sigma_n * sigma_c;
sigma = clamp(sigma, 1, 4e3);
//sigma = La;
histogram[HISTOGRAM_SLOTS] = floatBitsToUint(L);
histogram[HISTOGRAM_SLOTS+1] = floatBitsToUint(p);
......@@ -264,11 +268,13 @@ void main() {
float curr_lum = exp(index_to_log_lum(i));
float factor = exp(DISPLAY_MIN + display_range * float(prefix_sum[i])/sum);
factor = (factor - exp(DISPLAY_MIN)) / (exp(DISPLAY_MAX)-exp(DISPLAY_MIN));
factor = clamp(factor / curr_lum, 0.001, 1);
//factor = clamp(factor / curr_lum, 0.001, 1);
factor /= curr_lum;
if(!isnan(prev) && !isinf(prev))
factor = mix(prev, factor, global_uniforms.time.z/0.5);
imageStore(adjustment_factor, ivec2(i,0), vec4(factor));
}
}
......@@ -24,13 +24,12 @@ float calc_histogram_index_fp(float luminance) {
}
void main() {
float min_mesoptic = 0.00031622776f/2;
float max_mesoptic = 3.16227766017f/2;
float min_mesoptic = 0.00031622776f;
float max_mesoptic = 3.16227766017f;
vec3 cie_white = vec3(0.950456,1.,1.08906);
vec3 color = textureLod(color_sampler, vertex_out.tex_coords, 0).rgb;
color *= 10;
vec3 color = textureLod(color_sampler, vertex_out.tex_coords, 0).rgb*10000.0;
vec3 cie_color = rgb2cie(color);
float lum = cie_color.y;
......
......@@ -53,8 +53,8 @@ void main() {
vec2 rel_p = (vec2(x,y)*2 - data_size) / min(data_size.x, data_size.y);
float dist2 = dot(rel_p,rel_p);
if(dist2 < 1) {
vec3 color = imageLoad(input_image, ivec2(x,y)).rgb;
float lum = log(tm_luminance(color*10));
vec3 color = imageLoad(input_image, ivec2(x,y)).rgb*10000.0;
float lum = log(tm_luminance(color));
atomicAdd(local_histogram[calc_histogram_index(lum)], 1);
}
}
......
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