Commit 7d2a23c8 authored by Florian Oetke's avatar Florian Oetke
Browse files

small optimizations

parent f4ebbde1
......@@ -27,13 +27,10 @@ layout(push_constant) uniform Push_constants {
void main() {
vec3 diffuse;
vec3 radiance = upsampled_result(depth_sampler, mat_data_sampler,
lowres_depth_sampler, lowres_mat_data_sampler,
result_diff_sampler, vertex_out.tex_coords);
vec3 radiance = textureLod(result_diff_sampler, vertex_out.tex_coords, 0).rgb;
vec3 specular = textureLod(result_spec_sampler, vertex_out.tex_coords, 0).rgb;
out_color = vec4(calculate_gi(vertex_out.tex_coords, radiance, specular, albedo_sampler, mat_data_sampler, brdf_sampler, diffuse), 0);
out_color = vec4(calculate_gi(vertex_out.tex_coords, radiance, specular, albedo_sampler, mat_data_sampler, brdf_sampler), 0);
if(pcs.prev_projection[2][3]==0) {
......
......@@ -13,8 +13,7 @@ float luminance_norm(vec3 c) {
}
vec3 calculate_gi(vec2 uv, vec3 radiance, vec3 specular,
sampler2D albedo_sampler, sampler2D mat_sampler, sampler2D brdf_sampler,
out vec3 diffuse) {
sampler2D albedo_sampler, sampler2D mat_sampler, sampler2D brdf_sampler) {
const float PI = 3.14159265359;
radiance /= max(1, 1 - luminance_norm(radiance));
......@@ -43,19 +42,16 @@ 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);
diffuse = albedo * radiance/PI + F0*radiance/(2.0*PI);
return clamp(diff + spec, vec3(0,0,0), vec3(10,10,10));
}
vec3 calculate_gi(vec2 uv, vec2 gi_uv, int gi_lod, sampler2D diff_sampler, sampler2D spec_sampler,
sampler2D albedo_sampler, sampler2D mat_sampler, sampler2D brdf_sampler,
out vec3 diffuse) {
sampler2D albedo_sampler, sampler2D mat_sampler, sampler2D brdf_sampler) {
// load diff + spec GI
vec3 radiance = textureLod(diff_sampler, gi_uv, 0).rgb;
vec3 specular = textureLod(spec_sampler, gi_uv, 0).rgb;
return calculate_gi(uv, radiance, specular, albedo_sampler, mat_sampler, brdf_sampler, diffuse);
return calculate_gi(uv, radiance, specular, albedo_sampler, mat_sampler, brdf_sampler);
}
#endif
......@@ -76,9 +76,8 @@ void main() {
vec3 radiance = textureLod(history_diff_sampler, prev_uv.xy, 0).rgb;
vec3 specular = textureLod(history_spec_sampler, prev_uv.xy, 0).rgb;
vec3 diffuse;
vec3 gi = calculate_gi(vertex_out.tex_coords, radiance, specular,
albedo_sampler, mat_data_sampler, brdf_sampler, diffuse);
albedo_sampler, mat_data_sampler, brdf_sampler);
out_input = vec4(gi, 0.0);
......
......@@ -133,7 +133,6 @@ vec3 gi_sample(int lod, int base_mip) {
float cos_angle = cos(a);
ivec2 p = ivec2(uv + vec2(sin_angle * r, cos_angle * r));
float weight;
c += calc_illumination_from(lod, texture_size, p, uv, depth, P, N);
}
......@@ -148,11 +147,6 @@ vec3 calc_illumination_from(int lod, vec2 tex_size, ivec2 src_uv, vec2 shaded_uv
vec3 N = decode_normal(mat_data.rg);
float depth = texelFetch(depth_sampler, src_uv, 0).r;
if(depth>=0.9999) {
// we hit the skybox => reduce depth so it still contributes some light
depth = 0.1;
}
// reconstruct the position (x_i) of the src point and calculate the direction and distance^2 to x
vec3 P = position_from_ldepth(src_uv / tex_size, depth);
vec3 Pn = normalize(P);
......
......@@ -115,7 +115,7 @@ void main() {
if(spec_visible &&
traceScreenSpaceRay1(P+(dir*0.25+jitter*0.1), dir, pcs.projection, depth_sampler,
depthSize, 1.0, global_uniforms.proj_planes.x,
10, 0.5*jitter.z, max_steps, max_distance, int(startLod + 0.5),
20, 0.5*jitter.z, max_steps, max_distance, int(startLod + 0.5),
raycast_hit_uv, raycast_hit_point)) {
vec3 L = raycast_hit_point - P;
......
......@@ -78,7 +78,6 @@ namespace mirrage::graphic {
double _frame_start_time = 0;
float _delta_time_smoothed = 0;
float _cpu_delta_time_smoothed = 0;
float _time_since_last_FPS_output = 0;
void _update_fps_timer(double present_started);
......
......@@ -92,24 +92,19 @@ namespace mirrage::graphic {
_update_fps_timer(present_started);
}
void Window::_update_fps_timer(double present_started)
void Window::_update_fps_timer(double)
{
auto delta_time = static_cast<float>(util::current_time_sec() - _frame_start_time);
float smooth_factor = 0.1f;
_delta_time_smoothed = (1.0f - smooth_factor) * _delta_time_smoothed + smooth_factor * delta_time;
auto cpu_delta_time = static_cast<float>(present_started - _frame_start_time);
_cpu_delta_time_smoothed =
(1.0f - smooth_factor) * _cpu_delta_time_smoothed + smooth_factor * cpu_delta_time;
_time_since_last_FPS_output += delta_time;
if(_time_since_last_FPS_output >= 1.0f) {
_time_since_last_FPS_output = 0.0f;
std::ostringstream osstr;
osstr << _title << " (" << (int((1.0f / _delta_time_smoothed) * 10.0f) / 10.0f) << " FPS, ";
osstr << (int(_delta_time_smoothed * 10000.0f) / 10.0f) << " ms/frame, ";
osstr << (int(_cpu_delta_time_smoothed * 10000.0f) / 10.0f) << " ms/frame [cpu])";
osstr << (int(_delta_time_smoothed * 10000.0f) / 10.0f) << " ms/frame)";
SDL_SetWindowTitle(_window.get(), osstr.str().c_str());
}
......
......@@ -35,7 +35,7 @@ namespace mirrage::renderer {
int gi_diffuse_mip_level = 1;
int gi_min_mip_level = 0;
int gi_samples = 64;
int gi_lowres_samples = 1024;
int gi_lowres_samples = 512;
bool gi_jitter_samples = false;
int gi_low_quality_mip_levels = 0;
float exposure_override = 0.f;
......
......@@ -317,7 +317,6 @@ namespace mirrage::renderer {
inst->recreate();
}
}
_device->wait_idle();
}
void Deferred_renderer_factory::_present()
{
......
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