From b509c814fcf91dbd4a9c19a307882dc26dec13e3 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Mon, 4 Nov 2019 18:17:53 -0300 Subject: Improved Voxel AO settings. --- .../rasterizer_rd/rasterizer_scene_forward_rd.cpp | 2 +- .../rasterizer_rd/rasterizer_scene_forward_rd.h | 2 +- .../visual/rasterizer_rd/rasterizer_scene_rd.cpp | 6 +++++- .../visual/rasterizer_rd/rasterizer_storage_rd.cpp | 8 ++++---- .../visual/rasterizer_rd/rasterizer_storage_rd.h | 6 +++--- .../rasterizer_rd/shaders/scene_forward.glsl | 22 +++++++++++++++++----- .../rasterizer_rd/shaders/scene_forward_inc.glsl | 2 +- 7 files changed, 32 insertions(+), 16 deletions(-) (limited to 'servers/visual/rasterizer_rd') diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp index d57c62b629..965ec17421 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp @@ -1556,7 +1556,7 @@ void RasterizerSceneForwardRD::_setup_gi_probes(RID *p_gi_probe_probe_cull_resul gi_probe_ubo.texture_slot = gi_probe_instance_get_slot(rpi); gi_probe_ubo.anisotropy_strength = storage->gi_probe_get_anisotropy_strength(base_probe); gi_probe_ubo.ao = storage->gi_probe_get_ao(base_probe); - gi_probe_ubo.ao_strength = storage->gi_probe_get_ao_strength(base_probe); + gi_probe_ubo.ao_size = Math::pow(storage->gi_probe_get_ao_size(base_probe),4.0); if (gi_probe_is_anisotropic()) { gi_probe_ubo.texture_slot *= 3; diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h index ce335287ce..676db253e9 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h +++ b/servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h @@ -263,7 +263,7 @@ class RasterizerSceneForwardRD : public RasterizerSceneRD { float anisotropy_strength; float ao; - float ao_strength; + float ao_size; uint32_t pad[1]; }; diff --git a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp index 4e2fd0a7f7..1d7a7e9542 100644 --- a/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp @@ -1680,9 +1680,13 @@ void RasterizerSceneRD::gi_probe_update(RID p_probe, bool p_update_light_instanc // UDPDATE TIME - if (gi_probe->has_dynamic_object_data) { + if (gi_probe->has_dynamic_object_data) { //if it has dynamic object data, it needs to be cleared RD::get_singleton()->texture_clear(gi_probe->texture, Color(0, 0, 0, 0), 0, gi_probe->mipmaps.size(), 0, 1, true); + if (gi_probe_is_anisotropic()) { + RD::get_singleton()->texture_clear(gi_probe->anisotropy[0], Color(0, 0, 0, 0), 0, gi_probe->mipmaps.size(), 0, 1, true); + RD::get_singleton()->texture_clear(gi_probe->anisotropy[1], Color(0, 0, 0, 0), 0, gi_probe->mipmaps.size(), 0, 1, true); + } } uint32_t light_count = 0; diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp index 4aa9164d90..58b4205b38 100644 --- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp +++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp @@ -3781,18 +3781,18 @@ float RasterizerStorageRD::gi_probe_get_ao(RID p_gi_probe) const { return gi_probe->ao; } -void RasterizerStorageRD::gi_probe_set_ao_strength(RID p_gi_probe, float p_strength) { +void RasterizerStorageRD::gi_probe_set_ao_size(RID p_gi_probe, float p_strength) { GIProbe *gi_probe = gi_probe_owner.getornull(p_gi_probe); ERR_FAIL_COND(!gi_probe); - gi_probe->ao_strength = p_strength; + gi_probe->ao_size = p_strength; } -float RasterizerStorageRD::gi_probe_get_ao_strength(RID p_gi_probe) const { +float RasterizerStorageRD::gi_probe_get_ao_size(RID p_gi_probe) const { GIProbe *gi_probe = gi_probe_owner.getornull(p_gi_probe); ERR_FAIL_COND_V(!gi_probe, 0); - return gi_probe->ao_strength; + return gi_probe->ao_size; } void RasterizerStorageRD::gi_probe_set_bias(RID p_gi_probe, float p_bias) { diff --git a/servers/visual/rasterizer_rd/rasterizer_storage_rd.h b/servers/visual/rasterizer_rd/rasterizer_storage_rd.h index 0708c8d071..849e7728b8 100644 --- a/servers/visual/rasterizer_rd/rasterizer_storage_rd.h +++ b/servers/visual/rasterizer_rd/rasterizer_storage_rd.h @@ -424,7 +424,7 @@ private: float dynamic_range = 4.0; float energy = 1.0; float ao = 0.0; - float ao_strength = 0.5; + float ao_size = 0.5; float bias = 1.4; float normal_bias = 0.0; float propagation = 0.7; @@ -992,8 +992,8 @@ public: void gi_probe_set_ao(RID p_gi_probe, float p_ao); float gi_probe_get_ao(RID p_gi_probe) const; - void gi_probe_set_ao_strength(RID p_gi_probe, float p_strength); - float gi_probe_get_ao_strength(RID p_gi_probe) const; + void gi_probe_set_ao_size(RID p_gi_probe, float p_strength); + float gi_probe_get_ao_size(RID p_gi_probe) const; void gi_probe_set_bias(RID p_gi_probe, float p_bias); float gi_probe_get_bias(RID p_gi_probe) const; diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl index f567970e4a..259904dd60 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward.glsl @@ -1164,14 +1164,26 @@ void gi_probe_compute(uint index, vec3 position, vec3 normal,vec3 ref_vec, mat3 light *= gi_probes.data[index].dynamic_range; - if (gi_probes.data[index].ambient_occlusion > 0.01) { + if (gi_probes.data[index].ambient_occlusion > 0.001) { + + float size = 1.0+gi_probes.data[index].ambient_occlusion_size*7.0; + + float taps,blend; + blend = modf(size, taps); float ao = 0.0; + for(float i=1.0;i<=taps;i++) { + vec3 ofs = (position + normal * (i*0.5+1.0)) * cell_size; + ao+=textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot],material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]),ofs,i-1.0).a*i; + } - for (int i=0;i<5;i++) { - vec3 ofs = (position + normal * float(1<0.001) { + vec3 ofs = (position + normal * ((taps+1.0)*0.5+1.0)) * cell_size; + ao+=textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot],material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]),ofs,taps).a*(taps+1.0)*blend; } + + ao = 1.0 - min(1.0,ao); + + light *= mix(1.0,ao,gi_probes.data[index].ambient_occlusion); } out_diff += vec4(light * blend, blend); diff --git a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl index 9e97f76c57..e616d7d0b6 100644 --- a/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl +++ b/servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl @@ -208,7 +208,7 @@ struct GIProbeData { float anisotropy_strength; float ambient_occlusion; - float ambient_occlusion_strength; + float ambient_occlusion_size; uint pad2; }; -- cgit v1.2.3