From 965185c765bf5d17f0f035b7685dbaf4611e5288 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Thu, 3 Oct 2019 20:15:38 -0300 Subject: Better GIProbe quality settings. --- servers/visual/rasterizer.h | 5 +++++ .../rasterizer_rd/rasterizer_scene_forward_rd.cpp | 10 +++++++--- .../visual/rasterizer_rd/rasterizer_scene_rd.cpp | 7 +++---- servers/visual/rasterizer_rd/rasterizer_scene_rd.h | 11 +++++++++-- .../rasterizer_rd/shaders/scene_forward.glsl | 22 +++++++++++++++++----- servers/visual/visual_server_raster.cpp | 2 +- servers/visual_server.cpp | 3 ++- 7 files changed, 44 insertions(+), 16 deletions(-) (limited to 'servers') diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 85e2b8aadc..9d59f87edd 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -629,6 +629,11 @@ public: Color get_default_clear_color() const { return default_clear_color; } +#define TIMESTAMP_BEGIN() \ + { \ + if (VSG::storage->capturing_timestamps) VSG::storage->capture_timestamps_begin(); \ + } + #define RENDER_TIMESTAMP(m_text) \ { \ if (VSG::storage->capturing_timestamps) VSG::storage->capture_timestamp(m_text); \ diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp index 6e74ea91b5..3b0c59ddc6 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp @@ -1866,8 +1866,6 @@ void RasterizerSceneForwardRD::_render_scene(RenderBufferData *p_buffer_data, co } } - RENDER_TIMESTAMP("Render Opaque Pass"); - _setup_render_pass_uniform_set(RID(), RID(), RID(), RID(), radiance_cubemap, p_shadow_atlas, p_reflection_atlas); render_list.sort_by_key(false); @@ -1880,11 +1878,13 @@ void RasterizerSceneForwardRD::_render_scene(RenderBufferData *p_buffer_data, co bool depth_pre_pass = depth_framebuffer.is_valid(); if (depth_pre_pass) { //depth pre pass + RENDER_TIMESTAMP("Render Depth Pre-Pass"); RD::DrawListID draw_list = RD::get_singleton()->draw_list_begin(depth_framebuffer, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_CONTINUE, RD::INITIAL_ACTION_CLEAR, RD::FINAL_ACTION_CONTINUE); _render_list(draw_list, RD::get_singleton()->framebuffer_get_format(depth_framebuffer), render_list.elements, render_list.element_count, false, PASS_MODE_DEPTH, render_buffer == nullptr); RD::get_singleton()->draw_list_end(); } + RENDER_TIMESTAMP("Render Opaque Pass"); { bool will_continue = (can_continue || draw_sky || debug_giprobes); @@ -2365,9 +2365,13 @@ RasterizerSceneForwardRD::RasterizerSceneForwardRD(RasterizerStorageRD *p_storag slot_count *= 3; defines += "\n#define GI_PROBE_USE_ANISOTROPY\n"; } - if (gi_probe_is_high_quality()) { + + if (gi_probe_get_quality() == GIPROBE_QUALITY_ULTRA_LOW) { + defines += "\n#define GI_PROBE_LOW_QUALITY\n"; + } else if (gi_probe_get_quality() == GIPROBE_QUALITY_HIGH) { defines += "\n#define GI_PROBE_HIGH_QUALITY\n"; } + defines += "\n#define MAX_GI_PROBE_TEXTURES " + itos(slot_count) + "\n"; uint32_t giprobe_buffer_size; diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp index e292f9c69b..1b7d5a8e47 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp @@ -1558,7 +1558,6 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, const Vector &p_light_ } gi_probe->last_probe_version = storage->gi_probe_get_version(gi_probe->probe); - print_line("update GI"); } void RasterizerSceneRD::_debug_giprobe(RID p_gi_probe, RD::DrawListID p_draw_list, RID p_framebuffer, const CameraMatrix &p_camera_with_transform, bool p_lighting, float p_alpha) { @@ -1651,8 +1650,8 @@ void RasterizerSceneRD::gi_probe_slots_make_not_dirty() { gi_probe_slots_dirty = false; } -bool RasterizerSceneRD::gi_probe_is_high_quality() const { - return gi_probe_use_6_cones; +RasterizerSceneRD::GIProbeQuality RasterizerSceneRD::gi_probe_get_quality() const { + return gi_probe_quality; } //////////////////////////////// @@ -1958,7 +1957,7 @@ RasterizerSceneRD::RasterizerSceneRD(RasterizerStorageRD *p_storage) { gi_probe_lights_uniform = RD::get_singleton()->uniform_buffer_create(gi_probe_max_lights * sizeof(GIProbeLight)); gi_probe_use_anisotropy = GLOBAL_GET("rendering/quality/gi_probes/anisotropic"); - gi_probe_use_6_cones = GLOBAL_GET("rendering/quality/gi_probes/high_quality"); + gi_probe_quality = GIProbeQuality(CLAMP(int(GLOBAL_GET("rendering/quality/gi_probes/quality")), 0, 2)); if (textures_per_stage <= 16) { gi_probe_slots.resize(2); //thats all you can get diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h index cb32880e13..7acb66c587 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.h +++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.h @@ -9,6 +9,13 @@ #include "servers/visual/rendering_device.h" class RasterizerSceneRD : public RasterizerScene { +public: + enum GIProbeQuality { + GIPROBE_QUALITY_ULTRA_LOW, + GIPROBE_QUALITY_MEDIUM, + GIPROBE_QUALITY_HIGH, + }; + protected: struct RenderBufferData { @@ -182,7 +189,7 @@ private: RID gi_probe_lights_uniform; bool gi_probe_use_anisotropy = false; - bool gi_probe_use_6_cones = false; + GIProbeQuality gi_probe_quality = GIPROBE_QUALITY_MEDIUM; bool gi_probe_slots_dirty = true; Vector gi_probe_slots; @@ -709,7 +716,7 @@ public: _FORCE_INLINE_ bool gi_probe_is_anisotropic() const { return gi_probe_use_anisotropy; } - bool gi_probe_is_high_quality() const; + GIProbeQuality gi_probe_get_quality() const; RID render_buffers_create(); void render_buffers_configure(RID p_render_buffers, RID p_render_target, int p_width, int p_height, VS::ViewportMSAA p_msaa); diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl index 95e64f8778..2070df3952 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl @@ -887,7 +887,7 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 normal,float roughness reflection_accum += reflection; } -#ifndef USE_LIGHTMAP +#if !defined(USE_LIGHTMAP) && !defined(USE_VOXEL_CONE_TRACING) if (reflections.data[ref_index].ambient.a > 0.0) { //compute ambient using skybox vec3 local_amb_vec = (reflections.data[ref_index].local_matrix * vec4(normal, 0.0)).xyz; @@ -915,7 +915,7 @@ void reflection_process(uint ref_index, vec3 vertex, vec3 normal,float roughness ambient_out.rgb *= ambient_out.a; ambient_accum += ambient_out; } -#endif //USE_LIGHTMAP +#endif //USE_LIGHTMAP or VCT } #ifdef USE_VOXEL_CONE_TRACING @@ -1103,6 +1103,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 vec3 cell_size = 1.0 / gi_probes.data[index].bounds; //radiance + #ifdef GI_PROBE_HIGH_QUALITY #define MAX_CONE_DIRS 6 @@ -1116,7 +1117,17 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 float cone_weights[MAX_CONE_DIRS] = float[](0.25, 0.15, 0.15, 0.15, 0.15, 0.15); float cone_angle_tan = 0.577; -#else + +#elif defined(GI_PROBE_LOW_QUALITY) + +#define MAX_CONE_DIRS 1 + + vec3 cone_dirs[MAX_CONE_DIRS] = vec3[]( + vec3(0.0, 0.0, 1.0)); + + float cone_weights[MAX_CONE_DIRS] = float[](1.0); + float cone_angle_tan = 4; //~76 degrees +#else // MEDIUM QUALITY #define MAX_CONE_DIRS 4 @@ -1136,7 +1147,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 vec3 dir = normalize((gi_probes.data[index].xform * vec4(normal_xform * cone_dirs[i], 0.0)).xyz); -#ifdef GI_PROBE_HIGH_QUALITY +#if defined(GI_PROBE_HIGH_QUALITY) || defined(GI_PROBE_LOW_QUALITY) #ifdef GI_PROBE_USE_ANISOTROPY vec4 cone_light = voxel_cone_trace_anisotropic(gi_probe_textures[gi_probes.data[index].texture_slot],gi_probe_textures[gi_probes.data[index].texture_slot+1],gi_probe_textures[gi_probes.data[index].texture_slot+2],normalize(mix(dir,normal,gi_probes.data[index].anisotropy_strength)),cell_size, position, dir, cone_angle_tan, max_distance, gi_probes.data[index].bias); @@ -1164,7 +1175,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 out_diff += vec4(light * blend, blend); //irradiance - +#ifndef GI_PROBE_LOW_QUALITY vec4 irr_light = voxel_cone_trace(gi_probe_textures[gi_probes.data[index].texture_slot], cell_size, position, ref_vec, tan(roughness * 0.5 * M_PI * 0.99), max_distance, gi_probes.data[index].bias); if (gi_probes.data[index].blend_ambient) { irr_light.rgb = mix(environment,irr_light.rgb, min(1.0, irr_light.a / 0.95)); @@ -1173,6 +1184,7 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 //irr_light=vec3(0.0); out_spec += vec4(irr_light.rgb * blend, blend); +#endif } #endif //USE_VOXEL_CONE_TRACING diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 513393c9c9..5bdbe6e93d 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -103,7 +103,7 @@ void VisualServerRaster::draw(bool p_swap_buffers, double frame_step) { VSG::rasterizer->begin_frame(frame_step); - VSG::storage->capture_timestamps_begin(); + TIMESTAMP_BEGIN() VSG::scene_render->update(); //update scenes stuff before updating instances diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index b3ce7103a9..5092b1e693 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -2303,7 +2303,8 @@ VisualServer::VisualServer() { GLOBAL_DEF("rendering/quality/reflection_atlas/reflection_count", 64); GLOBAL_DEF("rendering/quality/gi_probes/anisotropic", false); - GLOBAL_DEF("rendering/quality/gi_probes/high_quality", false); + GLOBAL_DEF("rendering/quality/gi_probes/quality", 1); + ProjectSettings::get_singleton()->set_custom_property_info("rendering/quality/gi_probes/quality", PropertyInfo(Variant::INT, "rendering/quality/gi_probes/quality", PROPERTY_HINT_ENUM, "Ultra-Low (1 cone),Medium (4 cones), High (6 cones)")); GLOBAL_DEF("rendering/quality/shading/force_vertex_shading", false); GLOBAL_DEF("rendering/quality/shading/force_vertex_shading.mobile", true); -- cgit v1.2.3