summaryrefslogtreecommitdiff
path: root/servers/visual/rasterizer_rd
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2019-11-04 18:17:53 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-02-11 12:05:05 +0100
commitb509c814fcf91dbd4a9c19a307882dc26dec13e3 (patch)
tree19a657662c616d2e02f6b29f565b39d38e98c7af /servers/visual/rasterizer_rd
parent4949d578f23d1d708ff4d36d98c74925578cf3ae (diff)
Improved Voxel AO settings.
Diffstat (limited to 'servers/visual/rasterizer_rd')
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.cpp2
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_forward_rd.h2
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_scene_rd.cpp6
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_storage_rd.cpp8
-rw-r--r--servers/visual/rasterizer_rd/rasterizer_storage_rd.h6
-rw-r--r--servers/visual/rasterizer_rd/shaders/scene_forward.glsl22
-rw-r--r--servers/visual/rasterizer_rd/shaders/scene_forward_inc.glsl2
7 files changed, 32 insertions, 16 deletions
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<<i) * 1.5) * cell_size;
- ao += textureLod(sampler3D(gi_probe_textures[gi_probes.data[index].texture_slot],material_samplers[SAMPLER_LINEAR_WITH_MIPMAPS_CLAMP]),ofs,float(i) ).a;
- light *= mix(max(0.0,1.0-(ao * gi_probes.data[index].ambient_occlusion )),1.0,gi_probes.data[index].ambient_occlusion_strength);
+ if (blend>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;
};