ability to adjust propagation in gi probe

This commit is contained in:
Juan Linietsky 2017-02-06 05:12:15 -03:00
parent 6f2e16306a
commit 5cc63dee0f
9 changed files with 101 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -445,6 +445,7 @@ public:
Vector< PoolVector<CompBlockS3TC> > 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<uint32_t> *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);

View File

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