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

Merge branch 'master' into develop

parents e80dee4c dc7a4135
......@@ -2,6 +2,9 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
// Based on:
// http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
// https://learnopengl.com/#!PBR/IBL/Specular-IBL
layout(location = 0) in Vertex_data {
vec2 tex_coords;
......
......@@ -52,10 +52,12 @@ void main() {
vec4 center_depths = vec4(depth_00.y, depth_10.x, depth_11.w, depth_01.z);
vec4 score = vec4(g2(avg_depth - center_depths.x),
g2(avg_depth - center_depths.y),
g2(avg_depth - center_depths.z),
g2(avg_depth - center_depths.w) );
vec4 score = vec4(0.8, 0.8, 0.8, 1.0);
score *= vec4(g2(avg_depth - center_depths.x),
g2(avg_depth - center_depths.y),
g2(avg_depth - center_depths.z),
g2(avg_depth - center_depths.w) );
vec4 normal_x_00 = textureGather(mat_data_sampler, uv_00, 0);
......@@ -89,13 +91,21 @@ void main() {
g1(avg_normal_y - center_normals_y.z),
g1(avg_normal_y - center_normals_y.w) );
int max_index = 0;
if(score.y > score.x)
int max_index = 3;
float s = score.w;
if(score.x > s) {
max_index = 0;
s = score.x;
}
if(score.y > s) {
max_index = 1;
if(score.z > score.y)
s = score.y;
}
if(score.z > s) {
max_index = 2;
if(score.w > score.z)
max_index = 3;
s = score.z;
}
out_depth = texelFetch(depth_sampler, ivec2(vertex_out.tex_coords * tex_size) + center_offsets[max_index], 0);
......
......@@ -124,7 +124,7 @@ vec3 gi_sample(int lod, int base_mip) {
float angle_step = 1.0 / float(SAMPLES) * PI * 2.0 * 19.0;
for(int i=0; i<SAMPLES; i++) {
float r = mix(LAST_SAMPLE==1 ? 2.0 : R/2.0, R, float(i)/float(SAMPLES));
float r = max(4, mix(LAST_SAMPLE==1 ? 4.0 : R/2.0, R, float(i)/float(SAMPLES)));
angle += angle_step;
float sin_angle = sin(angle);
......@@ -168,7 +168,7 @@ vec3 calc_illumination_from(int lod, vec2 tex_size, ivec2 src_uv, vec2 shaded_uv
vec3 dir = normalize(diff);
float r2 = max(dot(diff, diff), 0.01*0.01);
float visibility = 1.0; // TODO: raycast
float visibility = 1.0; // TODO
vec4 mat_data = texelFetch(mat_data_sampler, src_uv, 0);
vec3 N = decode_normal(mat_data.rg);
......@@ -189,7 +189,7 @@ vec3 calc_illumination_from(int lod, vec2 tex_size, ivec2 src_uv, vec2 shaded_uv
float R2 = REC_PI * NdotL_src * ds;
float area = R2 / (r2 + R2); // point-to-differential area form-factor
weight = visibility * NdotL_dst * area;
weight = visibility * NdotL_dst * area * step(0.1, r2);
return max(vec3(0.0), radiance * weight);
}
......
......@@ -2,6 +2,9 @@
#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable
// losely based on https://www.gamedev.net/topic/658702-help-with-gpu-pro-5-hi-z-screen-space-reflections/?view=findpost&p=5173175
// and http://roar11.com/2015/07/screen-space-glossy-reflections/
layout(location = 0) in Vertex_data {
vec2 tex_coords;
......@@ -36,13 +39,9 @@ float luminance_norm(vec3 c) {
return sqrt(c.r*c.r*f.r + c.g*c.g*f.g + c.b*c.b*f.b);
}
// losely based on https://www.gamedev.net/topic/658702-help-with-gpu-pro-5-hi-z-screen-space-reflections/?view=findpost&p=5173175
// and http://roar11.com/2015/07/screen-space-glossy-reflections/
float roughness_to_spec_lobe_angle(float roughness) {
// see: http://graphicrants.blogspot.de/2013/08/specular-brdf-reference.html
float power = clamp(2/max(0.0001, roughness*roughness) - 2, 32.0, 1024*20);
float power = clamp(2/max(0.0001, roughness*roughness) - 2, 4.0, 1024*16);
return acos(pow(0.244, 1.0/(power + 1.0)));
}
......@@ -62,7 +61,7 @@ float isosceles_triangle_next_adjacent(float adjacentLength, float incircleRadiu
return adjacentLength - (incircleRadius * 2.0f);
}
vec3 cone_tracing(float roughness, vec2 hit_uv, vec3 L, float coneTheta) {
vec3 sample_color_lod(float roughness, vec2 hit_uv, vec3 L, float coneTheta) {
float min_lod = pcs.prev_projection[0][3];
float max_lod = max(min_lod, pcs.prev_projection[1][3]);
vec2 depth_size = textureSize(depth_sampler, int(min_lod + 0.5));
......@@ -71,46 +70,13 @@ vec3 cone_tracing(float roughness, vec2 hit_uv, vec3 L, float coneTheta) {
vec2 delta = (hit_uv - vertex_out.tex_coords);
float adjacent_length = length(delta);
if(adjacent_length<0.00001)
if(adjacent_length<0.0001)
return vec3(0,0,0);
vec2 adjacent_unit = delta / adjacent_length;
vec4 color = vec4(0,0,0,0);
float glossiness_mult = glossiness;
float remaining_alpha = 1.0;
for(int i=0; i<14; i++) {
float opposite_length = isosceles_triangle_opposite(adjacent_length, coneTheta);
float incircle_size = isosceles_triangle_inradius(adjacent_length, opposite_length);
vec2 uv = (vertex_out.tex_coords + adjacent_unit*(adjacent_length - incircle_size));
float lod = incircle_size<0.00001 ? min_lod : clamp(log2(incircle_size * screen_size)-1, min_lod, max_lod);
vec4 s = vec4(textureLod(color_sampler, uv, lod).rgb, 1) * glossiness_mult;
if(lod > max_lod-0.5) {
s.rgb *= 1.0 - min(0.5, lod-(max_lod-0.5))*2;
} else {
int ilod = int(lod + 0.5);
vec3 N = decode_normal(texelFetch(mat_data_sampler, ivec2(uv*textureSize(mat_data_sampler, ilod)), ilod).rg);
s.rgb *= clamp(1.0 - dot(L, N), 0, 1);
}
remaining_alpha -= s.a;
if(remaining_alpha < 0.0) {
s.rgb *= (1.0 - abs(remaining_alpha));
}
color += s;
if(color.a >= 1.0) {
break;
}
adjacent_length = isosceles_triangle_next_adjacent(adjacent_length, incircle_size);
glossiness_mult *= glossiness;
}
return color.rgb * (1 - max(0.0, remaining_alpha));
float opposite_length = isosceles_triangle_opposite(adjacent_length, coneTheta);
float incircle_size = isosceles_triangle_inradius(adjacent_length, opposite_length);
float lod = incircle_size<0.00001 ? min_lod : max(log2(incircle_size * screen_size), min_lod);
return textureLod(color_sampler, hit_uv, lod).rgb;
}
void main() {
......@@ -148,7 +114,7 @@ void main() {
vec3 raycast_hit_point;
if(spec_visible &&
traceScreenSpaceRay1(P+dir*0.25, dir, pcs.projection, depth_sampler,
depthSize, 2.0, global_uniforms.proj_planes.x,
depthSize, 1.0, global_uniforms.proj_planes.x,
10, 0.5*jitter.z, max_distance, max_steps, int(startLod + 0.5),
raycast_hit_uv, raycast_hit_point)) {
......@@ -163,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 = cone_tracing(roughness, hit_uv, dir, coneTheta);
vec3 color = sample_color_lod(roughness, hit_uv, dir, coneTheta);
out_color.rgb = max(color * factor_distance * factor_normal, vec3(0));
......
......@@ -66,15 +66,13 @@ vec3 decode_tangent_normal(vec2 tn) {
vec3 tangent_space_to_world(vec3 N) {
vec3 VN = normalize(normal);
// calculate tangent (assimp generated tangent contain weird artifacts)
// calculate tangent
vec3 p_dx = dFdx(view_pos);
vec3 p_dy = dFdy(view_pos);
vec2 tc_dx = dFdx(tex_coords);
vec2 tc_dy = dFdy(tex_coords);
// TODO: check alternativ
vec3 p_dy_N = cross(p_dy, VN);
vec3 p_dx_N = cross(VN, p_dx);
......@@ -84,16 +82,5 @@ vec3 tangent_space_to_world(vec3 N) {
float inv_max = inversesqrt(max(dot(T,T), dot(B,B)));
mat3 TBN = mat3(T*inv_max, B*inv_max, VN);
return normalize(TBN * N);
/*
vec3 VT = normalize( tc_dy.y * p_dx - tc_dx.y * p_dy );
VT = normalize(VT - dot(VT, VN) * VN);
vec3 VB = cross(VT, VN);
mat3 TBN = mat3(VT, VB, VN);
return normalize(TBN * N);*/
}
// By Morgan McGuire and Michael Mara at Williams College 2014
// Released as open source under the BSD 2-Clause License
// http://opensource.org/licenses/BSD-2-Clause
// see also: http://casual-effects.blogspot.de/2014/08/screen-space-ray-tracing.html
#ifndef RAYCAST_INCLUDED
#define RAYCAST_INCLUDED
......
......@@ -30,6 +30,7 @@
"F1": {"type":"once", "action":"start_record"},
"F2": {"type":"once", "action":"save_record"},
"F3": {"type":"once", "action":"playback"},
"Space": {"type":"once", "action":"pause"},
"F11": {"type":"once", "action":"toggle_ui"}
},
......
......@@ -166,8 +166,10 @@ namespace mirrage::systems {
if(!_playing)
return;
_current_position +=
dt / _playing->frame_length(static_cast<int>(_current_position)) * _playback_speed;
if(!_paused) {
_current_position +=
dt / _playing->frame_length(static_cast<int>(_current_position)) * _playback_speed;
}
if(_loop) {
_current_position = static_cast<float>(std::fmod(_current_position, _playing->frames()));
......
......@@ -102,6 +102,11 @@ namespace mirrage::systems {
void stop();
void pause() { _paused = true; }
void unpause() { _paused = false; }
void toggle_pause() { _paused = !_paused; }
auto paused() const { return _paused; }
void start_recording(Nim_sequence&);
// appends the current state of all relevant objects
void record(util::Time length, Nim_sequence&);
......@@ -118,6 +123,7 @@ namespace mirrage::systems {
float _current_position;
int _end_position;
bool _loop;
bool _paused = false;
void _update_lookup_table();
};
......
......@@ -137,6 +137,10 @@ namespace mirrage {
_meta_system.nims().play_looped(rec);
});
break;
case "pause"_strid:
MIRRAGE_INFO("Pause/Unpause playback");
_meta_system.nims().toggle_pause();
break;
case "toggle_ui"_strid: _show_ui = !_show_ui; break;
......
......@@ -231,7 +231,7 @@ namespace mirrage::renderer {
2,
sample_count,
4,
prioritise_near_samples ? 1 : 0)
prioritise_near_samples)
.shader("vert_shader:gi_sample"_aid, graphic::Shader_stage::vertex);
pass.stage("sample_last"_strid)
......
Supports Markdown
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