diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp index 1cc346410bb..3282bc16eb9 100644 --- a/drivers/gles3/rasterizer_storage_gles3.cpp +++ b/drivers/gles3/rasterizer_storage_gles3.cpp @@ -4777,6 +4777,7 @@ RID RasterizerStorageGLES3::gi_probe_create() { gip->bounds=Rect3(Vector3(),Vector3(1,1,1)); gip->dynamic_range=1.0; gip->energy=1.0; + gip->propagation=1.0; gip->interior=false; gip->compress=false; gip->version=1; @@ -4882,6 +4883,15 @@ void RasterizerStorageGLES3::gi_probe_set_energy(RID p_probe,float p_range){ } +void RasterizerStorageGLES3::gi_probe_set_propagation(RID p_probe,float p_range){ + + GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND(!gip); + + gip->propagation=p_range; + +} + void RasterizerStorageGLES3::gi_probe_set_interior(RID p_probe,bool p_enable) { GIProbe *gip = gi_probe_owner.getornull(p_probe); @@ -4926,6 +4936,16 @@ float RasterizerStorageGLES3::gi_probe_get_energy(RID p_probe) const{ return gip->energy; } +float RasterizerStorageGLES3::gi_probe_get_propagation(RID p_probe) const{ + + const GIProbe *gip = gi_probe_owner.getornull(p_probe); + ERR_FAIL_COND_V(!gip,0); + + return gip->propagation; +} + + + uint32_t RasterizerStorageGLES3::gi_probe_get_version(RID p_probe) { diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h index 5beb6e48aa8..fcce9f12dbb 100644 --- a/drivers/gles3/rasterizer_storage_gles3.h +++ b/drivers/gles3/rasterizer_storage_gles3.h @@ -921,6 +921,7 @@ public: int dynamic_range; float energy; + float propagation; bool interior; bool compress; @@ -953,6 +954,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range); virtual float gi_probe_get_energy(RID p_probe) const; + virtual void gi_probe_set_propagation(RID p_probe,float p_range); + virtual float gi_probe_get_propagation(RID p_probe) const; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable); virtual bool gi_probe_is_interior(RID p_probe) const; diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 2b15af1c3c8..4c335905682 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -64,6 +64,18 @@ float GIProbeData::get_energy() const{ } +void GIProbeData::set_propagation(float p_range) { + + VS::get_singleton()->gi_probe_set_propagation(probe,p_range); +} + +float GIProbeData::get_propagation() const{ + + return VS::get_singleton()->gi_probe_get_propagation(probe); + +} + + void GIProbeData::set_interior(bool p_enable) { VS::get_singleton()->gi_probe_set_interior(probe,p_enable); @@ -121,6 +133,9 @@ void GIProbeData::_bind_methods() { ClassDB::bind_method(_MD("set_energy","energy"),&GIProbeData::set_energy); ClassDB::bind_method(_MD("get_energy"),&GIProbeData::get_energy); + ClassDB::bind_method(_MD("set_propagation","propagation"),&GIProbeData::set_propagation); + ClassDB::bind_method(_MD("get_propagation"),&GIProbeData::get_propagation); + ClassDB::bind_method(_MD("set_interior","interior"),&GIProbeData::set_interior); ClassDB::bind_method(_MD("is_interior"),&GIProbeData::is_interior); @@ -134,6 +149,7 @@ void GIProbeData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY,"dynamic_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_data"),_SCS("get_dynamic_data")); ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_propagation"),_SCS("get_propagation")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_interior"),_SCS("is_interior")); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"compress",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("set_compress"),_SCS("is_compressed")); @@ -214,6 +230,18 @@ float GIProbe::get_energy() const { return energy; } +void GIProbe::set_propagation(float p_propagation) { + + propagation=p_propagation; + if (probe_data.is_valid()) { + probe_data->set_propagation(propagation); + } +} +float GIProbe::get_propagation() const { + + return propagation; +} + void GIProbe::set_interior(bool p_enable) { interior=p_enable; @@ -1371,6 +1399,9 @@ void GIProbe::_bind_methods() { ClassDB::bind_method(_MD("set_energy","max"),&GIProbe::set_energy); ClassDB::bind_method(_MD("get_energy"),&GIProbe::get_energy); + ClassDB::bind_method(_MD("set_propagation","max"),&GIProbe::set_propagation); + ClassDB::bind_method(_MD("get_propagation"),&GIProbe::get_propagation); + ClassDB::bind_method(_MD("set_interior","enable"),&GIProbe::set_interior); ClassDB::bind_method(_MD("is_interior"),&GIProbe::is_interior); @@ -1385,6 +1416,7 @@ void GIProbe::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::VECTOR3,"extents"),_SCS("set_extents"),_SCS("get_extents")); ADD_PROPERTY( PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_RANGE,"1,16,1"),_SCS("set_dynamic_range"),_SCS("get_dynamic_range")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0,16,0.01"),_SCS("set_energy"),_SCS("get_energy")); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_RANGE,"0,1,0.01"),_SCS("set_propagation"),_SCS("get_propagation")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior"),_SCS("set_interior"),_SCS("is_interior")); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"compress"),_SCS("set_compress"),_SCS("is_compressed")); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"data",PROPERTY_HINT_RESOURCE_TYPE,"GIProbeData"),_SCS("set_probe_data"),_SCS("get_probe_data")); @@ -1402,6 +1434,7 @@ GIProbe::GIProbe() { subdiv=SUBDIV_128; dynamic_range=4; energy=1.0; + propagation=1.0; extents=Vector3(10,10,10); color_scan_cell_width=4; bake_texture_size=128; diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index 71e226ff3b4..f03a5589082 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -32,6 +32,9 @@ public: void set_dynamic_range(int p_range); int get_dynamic_range() const; + void set_propagation(float p_range); + float get_propagation() const; + void set_energy(float p_range); float get_energy() const; @@ -134,6 +137,7 @@ private: Vector3 extents; int dynamic_range; float energy; + float propagation; bool interior; bool compress; @@ -172,6 +176,9 @@ public: void set_energy(float p_energy); float get_energy() const; + void set_propagation(float p_propagation); + float get_propagation() const; + void set_interior(bool p_enable); bool is_interior() const; diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 84043c1a8c6..21f7f0769f4 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -432,6 +432,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range)=0; virtual float gi_probe_get_energy(RID p_probe) const=0; + virtual void gi_probe_set_propagation(RID p_probe,float p_range)=0; + virtual float gi_probe_get_propagation(RID p_probe) const=0; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 9184c64c210..ad0cb664c53 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -825,6 +825,9 @@ public: BIND2(gi_probe_set_energy,RID,float) BIND1RC(float,gi_probe_get_energy,RID) + BIND2(gi_probe_set_propagation,RID,float) + BIND1RC(float,gi_probe_get_propagation,RID) + BIND2(gi_probe_set_interior,RID,bool) BIND1RC(bool,gi_probe_is_interior,RID) diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp index 157a85be985..1d18a3e1263 100644 --- a/servers/visual/visual_server_scene.cpp +++ b/servers/visual/visual_server_scene.cpp @@ -2448,6 +2448,7 @@ void VisualServerScene::_setup_gi_probe(Instance *p_instance) { probe->dynamic.bake_dynamic_range=VSG::storage->gi_probe_get_dynamic_range(p_instance->base); probe->dynamic.mipmaps_3d.clear(); + probe->dynamic.propagate=VSG::storage->gi_probe_get_propagation(p_instance->base); probe->dynamic.grid_size[0]=header->width; probe->dynamic.grid_size[1]=header->height; @@ -2942,14 +2943,12 @@ void VisualServerScene::_bake_gi_probe_light(const GIProbeDataHeader *header,con } -void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data) { +void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data,float p_propagate) { //average light to upper level - p_local_data[p_idx].energy[0]=0; - p_local_data[p_idx].energy[1]=0; - p_local_data[p_idx].energy[2]=0; - int divisor=0; + float divisor=0; + float sum[3]={0.0,0.0,0.0}; for(int i=0;i<8;i++) { @@ -2959,20 +2958,25 @@ void VisualServerScene::_bake_gi_downscale_light(int p_idx, int p_level, const G continue; if (p_level+1 < (int)p_header->cell_subdiv-1) { - _bake_gi_downscale_light(child,p_level+1,p_cells,p_header,p_local_data); + _bake_gi_downscale_light(child,p_level+1,p_cells,p_header,p_local_data,p_propagate); } - p_local_data[p_idx].energy[0]+=p_local_data[child].energy[0]; - p_local_data[p_idx].energy[1]+=p_local_data[child].energy[1]; - p_local_data[p_idx].energy[2]+=p_local_data[child].energy[2]; - divisor++; + sum[0]+=p_local_data[child].energy[0]; + sum[1]+=p_local_data[child].energy[1]; + sum[2]+=p_local_data[child].energy[2]; + divisor+=1.0; } + divisor=Math::lerp(8.0,divisor,p_propagate); + sum[0]/=divisor; + sum[1]/=divisor; + sum[2]/=divisor; + //divide by eight for average - p_local_data[p_idx].energy[0]/=divisor; - p_local_data[p_idx].energy[1]/=divisor; - p_local_data[p_idx].energy[2]/=divisor; + p_local_data[p_idx].energy[0]=Math::fast_ftoi(sum[0]); + p_local_data[p_idx].energy[1]=Math::fast_ftoi(sum[1]); + p_local_data[p_idx].energy[2]=Math::fast_ftoi(sum[2]); } @@ -3024,7 +3028,7 @@ void VisualServerScene::_bake_gi_probe(Instance *p_gi_probe) { SWAP(probe_data->dynamic.light_cache_changes,probe_data->dynamic.light_cache); //downscale to lower res levels - _bake_gi_downscale_light(0,0,cells,header,local_data); + _bake_gi_downscale_light(0,0,cells,header,local_data,probe_data->dynamic.propagate); //plot result to 3D texture! @@ -3337,6 +3341,14 @@ void VisualServerScene::render_probes() { force_lighting=true; } + float propagate = VSG::storage->gi_probe_get_propagation(instance_probe->base); + + if (probe->dynamic.propagate!=propagate) { + probe->dynamic.propagate=propagate; + force_lighting=true; + } + + if (probe->invalid==false && probe->dynamic.enabled) { switch(probe->dynamic.updating_stage) { diff --git a/servers/visual/visual_server_scene.h b/servers/visual/visual_server_scene.h index 1f7de3d0059..f9a5dde1ace 100644 --- a/servers/visual/visual_server_scene.h +++ b/servers/visual/visual_server_scene.h @@ -445,6 +445,7 @@ public: Vector< PoolVector > mipmaps_s3tc; //for s3tc int updating_stage; + float propagate; int grid_size[3]; @@ -570,7 +571,7 @@ public: void _gi_probe_fill_local_data(int p_idx,int p_level,int p_x,int p_y,int p_z,const GIProbeDataCell* p_cell,const GIProbeDataHeader *p_header,InstanceGIProbeData::LocalData *p_local_data,Vector *prev_cell); _FORCE_INLINE_ uint32_t _gi_bake_find_cell(const GIProbeDataCell *cells,int x,int y, int z,int p_cell_subdiv); - void _bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data); + void _bake_gi_downscale_light(int p_idx, int p_level, const GIProbeDataCell* p_cells, const GIProbeDataHeader *p_header, InstanceGIProbeData::LocalData *p_local_data, float p_propagate); void _bake_gi_probe_light(const GIProbeDataHeader *header,const GIProbeDataCell *cells,InstanceGIProbeData::LocalData *local_data,const uint32_t *leaves,int p_leaf_count, const InstanceGIProbeData::LightCache& light_cache,int p_sign); void _bake_gi_probe(Instance *p_probe); bool _check_gi_probe(Instance *p_gi_probe); diff --git a/servers/visual_server.h b/servers/visual_server.h index 4924851a550..cda77216531 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -474,6 +474,9 @@ public: virtual void gi_probe_set_energy(RID p_probe,float p_range)=0; virtual float gi_probe_get_energy(RID p_probe) const=0; + virtual void gi_probe_set_propagation(RID p_probe,float p_range)=0; + virtual float gi_probe_get_propagation(RID p_probe) const=0; + virtual void gi_probe_set_interior(RID p_probe,bool p_enable)=0; virtual bool gi_probe_is_interior(RID p_probe) const=0;