Improved Voxel AO settings.

This commit is contained in:
Juan Linietsky 2019-11-04 18:17:53 -03:00
parent 4949d578f2
commit b509c814fc
13 changed files with 53 additions and 37 deletions

View File

@ -166,13 +166,13 @@ float GIProbeData::get_ao() const {
return ao;
}
void GIProbeData::set_ao_strength(float p_ao_strength) {
VS::get_singleton()->gi_probe_set_ao_strength(probe, p_ao_strength);
ao_strength = p_ao_strength;
void GIProbeData::set_ao_size(float p_ao_size) {
VS::get_singleton()->gi_probe_set_ao_size(probe, p_ao_size);
ao_size = p_ao_size;
}
float GIProbeData::get_ao_strength() const {
return ao_strength;
float GIProbeData::get_ao_size() const {
return ao_size;
}
void GIProbeData::set_bias(float p_bias) {
@ -257,8 +257,8 @@ void GIProbeData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_ao", "ao"), &GIProbeData::set_ao);
ClassDB::bind_method(D_METHOD("get_ao"), &GIProbeData::get_ao);
ClassDB::bind_method(D_METHOD("set_ao_strength", "strength"), &GIProbeData::set_ao_strength);
ClassDB::bind_method(D_METHOD("get_ao_strength"), &GIProbeData::get_ao_strength);
ClassDB::bind_method(D_METHOD("set_ao_size", "strength"), &GIProbeData::set_ao_size);
ClassDB::bind_method(D_METHOD("get_ao_size"), &GIProbeData::get_ao_size);
ClassDB::bind_method(D_METHOD("set_interior", "interior"), &GIProbeData::set_interior);
ClassDB::bind_method(D_METHOD("is_interior"), &GIProbeData::is_interior);
@ -278,7 +278,7 @@ void GIProbeData::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "propagation", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_propagation", "get_propagation");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "anisotropy_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_anisotropy_strength", "get_anisotropy_strength");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao", "get_ao");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao_strength", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao_strength", "get_ao_strength");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "ao_size", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_ao_size", "get_ao_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_two_bounces"), "set_use_two_bounces", "is_using_two_bounces");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "interior"), "set_interior", "is_interior");
}
@ -286,7 +286,7 @@ void GIProbeData::_bind_methods() {
GIProbeData::GIProbeData() {
ao = 0.0;
ao_strength = 0.5;
ao_size = 0.5;
dynamic_range = 4;
energy = 1.0;
bias = 1.5;

View File

@ -54,7 +54,7 @@ class GIProbeData : public Resource {
float propagation;
float anisotropy_strength;
float ao;
float ao_strength;
float ao_size;
bool interior;
bool use_two_bounces;
@ -84,8 +84,8 @@ public:
void set_ao(float p_ao);
float get_ao() const;
void set_ao_strength(float p_ao_strength);
float get_ao_strength() const;
void set_ao_size(float p_ao_size);
float get_ao_size() const;
void set_energy(float p_energy);
float get_energy() const;

View File

@ -511,8 +511,8 @@ public:
virtual void gi_probe_set_ao(RID p_gi_probe, float p_ao) = 0;
virtual float gi_probe_get_ao(RID p_gi_probe) const = 0;
virtual void gi_probe_set_ao_strength(RID p_gi_probe, float p_strength) = 0;
virtual float gi_probe_get_ao_strength(RID p_gi_probe) const = 0;
virtual void gi_probe_set_ao_size(RID p_gi_probe, float p_strength) = 0;
virtual float gi_probe_get_ao_size(RID p_gi_probe) const = 0;
virtual void gi_probe_set_bias(RID p_gi_probe, float p_bias) = 0;
virtual float gi_probe_get_bias(RID p_gi_probe) const = 0;

View File

@ -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;

View File

@ -263,7 +263,7 @@ class RasterizerSceneForwardRD : public RasterizerSceneRD {
float anisotropy_strength;
float ao;
float ao_strength;
float ao_size;
uint32_t pad[1];
};

View File

@ -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;

View File

@ -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) {

View File

@ -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;

View File

@ -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) {
float ao = 0.0;
if (gi_probes.data[index].ambient_occlusion > 0.001) {
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);
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;
}
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);

View File

@ -208,7 +208,7 @@ struct GIProbeData {
float anisotropy_strength;
float ambient_occlusion;
float ambient_occlusion_strength;
float ambient_occlusion_size;
uint pad2;
};

View File

@ -366,8 +366,8 @@ public:
BIND2(gi_probe_set_ao, RID, float)
BIND1RC(float, gi_probe_get_ao, RID)
BIND2(gi_probe_set_ao_strength, RID, float)
BIND1RC(float, gi_probe_get_ao_strength, RID)
BIND2(gi_probe_set_ao_size, RID, float)
BIND1RC(float, gi_probe_get_ao_size, RID)
BIND2(gi_probe_set_bias, RID, float)
BIND1RC(float, gi_probe_get_bias, RID)

View File

@ -290,8 +290,8 @@ public:
FUNC2(gi_probe_set_ao, RID, float)
FUNC1RC(float, gi_probe_get_ao, RID)
FUNC2(gi_probe_set_ao_strength, RID, float)
FUNC1RC(float, gi_probe_get_ao_strength, RID)
FUNC2(gi_probe_set_ao_size, RID, float)
FUNC1RC(float, gi_probe_get_ao_size, RID)
FUNC2(gi_probe_set_bias, RID, float)
FUNC1RC(float, gi_probe_get_bias, RID)

View File

@ -487,8 +487,8 @@ public:
virtual void gi_probe_set_ao(RID p_gi_probe, float p_ao) = 0;
virtual float gi_probe_get_ao(RID p_gi_probe) const = 0;
virtual void gi_probe_set_ao_strength(RID p_gi_probe, float p_strength) = 0;
virtual float gi_probe_get_ao_strength(RID p_gi_probe) const = 0;
virtual void gi_probe_set_ao_size(RID p_gi_probe, float p_strength) = 0;
virtual float gi_probe_get_ao_size(RID p_gi_probe) const = 0;
virtual void gi_probe_set_bias(RID p_gi_probe, float p_bias) = 0;
virtual float gi_probe_get_bias(RID p_gi_probe) const = 0;