diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/gi_probe.cpp | 101 | ||||
-rw-r--r-- | scene/3d/gi_probe.h | 7 | ||||
-rw-r--r-- | scene/resources/material.cpp | 2 | ||||
-rw-r--r-- | scene/resources/texture.cpp | 5 |
4 files changed, 80 insertions, 35 deletions
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp index 1d40202318..e3c8ba09fc 100644 --- a/scene/3d/gi_probe.cpp +++ b/scene/3d/gi_probe.cpp @@ -64,6 +64,19 @@ float GIProbeData::get_energy() const{ } + +void GIProbeData::set_bias(float p_range) { + + VS::get_singleton()->gi_probe_set_bias(probe,p_range); +} + +float GIProbeData::get_bias() const{ + + return VS::get_singleton()->gi_probe_get_bias(probe); + +} + + void GIProbeData::set_propagation(float p_range) { VS::get_singleton()->gi_probe_set_propagation(probe,p_range); @@ -133,6 +146,9 @@ void GIProbeData::_bind_methods() { ClassDB::bind_method(D_METHOD("set_energy","energy"),&GIProbeData::set_energy); ClassDB::bind_method(D_METHOD("get_energy"),&GIProbeData::get_energy); + ClassDB::bind_method(D_METHOD("set_bias","bias"),&GIProbeData::set_bias); + ClassDB::bind_method(D_METHOD("get_bias"),&GIProbeData::get_bias); + ClassDB::bind_method(D_METHOD("set_propagation","propagation"),&GIProbeData::set_propagation); ClassDB::bind_method(D_METHOD("get_propagation"),&GIProbeData::get_propagation); @@ -149,6 +165,7 @@ void GIProbeData::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY,"dynamic_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_dynamic_data","get_dynamic_data"); ADD_PROPERTY(PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_dynamic_range","get_dynamic_range"); ADD_PROPERTY(PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_energy","get_energy"); + ADD_PROPERTY(PropertyInfo(Variant::REAL,"bias",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_bias","get_bias"); ADD_PROPERTY(PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_propagation","get_propagation"); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"interior",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_interior","is_interior"); ADD_PROPERTY(PropertyInfo(Variant::BOOL,"compress",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_compress","is_compressed"); @@ -230,6 +247,18 @@ float GIProbe::get_energy() const { return energy; } +void GIProbe::set_bias(float p_bias) { + + bias=p_bias; + if (probe_data.is_valid()) { + probe_data->set_bias(bias); + } +} +float GIProbe::get_bias() const { + + return bias; +} + void GIProbe::set_propagation(float p_propagation) { propagation=p_propagation; @@ -466,7 +495,8 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V int closest_axis; float closest_dot; - Vector3 normal = Plane(p_vtx[0],p_vtx[1],p_vtx[2]).normal; + Plane plane = Plane(p_vtx[0],p_vtx[1],p_vtx[2]); + Vector3 normal = plane.normal; for(int i=0;i<3;i++) { @@ -479,6 +509,7 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V } } + Vector3 axis; axis[closest_axis]=1.0; Vector3 t1; @@ -517,30 +548,23 @@ void GIProbe::_plot_face(int p_idx, int p_level,int p_x,int p_y,int p_z, const V Vector3 ray_from = from + (t1+t2)*0.5 - axis * p_aabb.size[closest_axis]; Vector3 ray_to = ray_from + axis * p_aabb.size[closest_axis]*2; + if (normal.dot(ray_from-ray_to)<0) { + SWAP(ray_from,ray_to); + } + Vector3 intersection; - if (!Geometry::ray_intersects_triangle(ray_from,ray_to,p_vtx[0],p_vtx[1],p_vtx[2],&intersection)) { - //no intersect? look in edges - - float closest_dist=1e20; - for(int j=0;j<3;j++) { - Vector3 c; - Vector3 inters; - Geometry::get_closest_points_between_segments(p_vtx[j],p_vtx[(j+1)%3],ray_from,ray_to,inters,c); - if (c==inters) { - closest_dist=0; - intersection=inters; - - } else { - float d=c.distance_to(intersection); - if (j==0 || d<closest_dist) { - closest_dist=d; - intersection=inters; - } - } + if (!plane.intersects_segment(ray_from,ray_to,&intersection)) { + if (ABS(plane.distance_to(ray_from)) < ABS(plane.distance_to(ray_to))) { + intersection = plane.project(ray_from); + } else { + + intersection = plane.project(ray_to); } } + intersection=Face3(p_vtx[0],p_vtx[1],p_vtx[2]).get_closest_point_to(intersection); + Vector2 uv = get_uv(intersection,p_vtx,p_uv); @@ -1245,26 +1269,30 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug){ } - Ref<GIProbeData> probe_data; - probe_data.instance(); - probe_data->set_bounds(Rect3(-extents,extents*2.0)); - probe_data->set_cell_size(baker.po2_bounds.size[longest_axis]/baker.axis_cell_size[longest_axis]); - probe_data->set_dynamic_data(data); - probe_data->set_dynamic_range(dynamic_range); - probe_data->set_energy(energy); - probe_data->set_interior(interior); - probe_data->set_compress(compress); - probe_data->set_to_cell_xform(baker.to_cell_space); - - set_probe_data(probe_data); + if (p_create_visual_debug) { + _create_debug_mesh(&baker); + } else { + Ref<GIProbeData> probe_data; + probe_data.instance(); + probe_data->set_bounds(Rect3(-extents,extents*2.0)); + probe_data->set_cell_size(baker.po2_bounds.size[longest_axis]/baker.axis_cell_size[longest_axis]); + probe_data->set_dynamic_data(data); + probe_data->set_dynamic_range(dynamic_range); + probe_data->set_energy(energy); + probe_data->set_bias(bias); + probe_data->set_propagation(propagation); + probe_data->set_interior(interior); + probe_data->set_compress(compress); + probe_data->set_to_cell_xform(baker.to_cell_space); - if (p_create_visual_debug) { - //_create_debug_mesh(&baker); + set_probe_data(probe_data); } + + } @@ -1436,6 +1464,9 @@ void GIProbe::_bind_methods() { ClassDB::bind_method(D_METHOD("set_energy","max"),&GIProbe::set_energy); ClassDB::bind_method(D_METHOD("get_energy"),&GIProbe::get_energy); + ClassDB::bind_method(D_METHOD("set_bias","max"),&GIProbe::set_bias); + ClassDB::bind_method(D_METHOD("get_bias"),&GIProbe::get_bias); + ClassDB::bind_method(D_METHOD("set_propagation","max"),&GIProbe::set_propagation); ClassDB::bind_method(D_METHOD("get_propagation"),&GIProbe::get_propagation); @@ -1454,6 +1485,7 @@ void GIProbe::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::INT,"dynamic_range",PROPERTY_HINT_RANGE,"1,16,1"),"set_dynamic_range","get_dynamic_range"); ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0,16,0.01"),"set_energy","get_energy"); ADD_PROPERTY( PropertyInfo(Variant::REAL,"propagation",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_propagation","get_propagation"); + ADD_PROPERTY( PropertyInfo(Variant::REAL,"bias",PROPERTY_HINT_RANGE,"0,4,0.001"),"set_bias","get_bias"); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"interior"),"set_interior","is_interior"); ADD_PROPERTY( PropertyInfo(Variant::BOOL,"compress"),"set_compress","is_compressed"); ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"data",PROPERTY_HINT_RESOURCE_TYPE,"GIProbeData"),"set_probe_data","get_probe_data"); @@ -1471,6 +1503,7 @@ GIProbe::GIProbe() { subdiv=SUBDIV_128; dynamic_range=4; energy=1.0; + bias=0.4; propagation=1.0; extents=Vector3(10,10,10); color_scan_cell_width=4; diff --git a/scene/3d/gi_probe.h b/scene/3d/gi_probe.h index f03a558908..0f003d7cb1 100644 --- a/scene/3d/gi_probe.h +++ b/scene/3d/gi_probe.h @@ -38,6 +38,9 @@ public: void set_energy(float p_range); float get_energy() const; + void set_bias(float p_range); + float get_bias() const; + void set_interior(bool p_enable); bool is_interior() const; @@ -137,6 +140,7 @@ private: Vector3 extents; int dynamic_range; float energy; + float bias; float propagation; bool interior; bool compress; @@ -176,6 +180,9 @@ public: void set_energy(float p_energy); float get_energy() const; + void set_bias(float p_bias); + float get_bias() const; + void set_propagation(float p_propagation); float get_propagation() const; diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index b7c8b1664d..3780c466a5 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -339,7 +339,7 @@ void FixedSpatialMaterial::_update_shader() { code+="\tROUGHNESS = specular_tex.a * roughness;\n"; } else { code+="\tvec4 specular_tex = texture(texture_specular,UV);\n"; - code+="\tSPECULAR = vec3(metalness * specular_tex.r);\n"; + code+="\tSPECULAR = vec3(ALBEDO.rgb * metalness * specular_tex.r);\n"; code+="\tROUGHNESS = specular_tex.a * roughness;\n"; } diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index e3a856ad4f..62feb7b37c 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -559,6 +559,11 @@ Error StreamTexture::_load_data(const String& p_path,int &tw,int &th,int& flags, int total_size=0; for(int i=0;i<mipmaps;i++) { + + if (i>0) { + size = f->get_32(); + } + PoolVector<uint8_t> pv; pv.resize(size); { |