From ddc0e7fd3bc00afa33432ed594038dbb80c7fea3 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Tue, 17 Jun 2014 11:58:35 -0300 Subject: [PATCH] FineTune HDR and Other Stuff -=-=-=-=-=-=-=-=-=-=-=-=-=- -More parameters to ESM shadows -LightMap Octree now can bake to "hdr" (use HDR8 for now) -New resource PolygonPathFinder, polygon based pathfinder using A-star algorithm. (will add nodes to use it more easily soon) --- core/image.cpp | 338 +++++++++++++++++- core/image.h | 3 + core/variant_call.cpp | 2 + drivers/gles2/rasterizer_gles2.cpp | 1 + drivers/gles2/shaders/material.glsl | 3 +- scene/gui/scroll_bar.cpp | 43 +++ scene/gui/scroll_bar.h | 10 +- scene/resources/baked_light.cpp | 16 + scene/resources/baked_light.h | 11 + scene/resources/polygon_path_finder.cpp | 80 ++++- scene/resources/polygon_path_finder.h | 11 +- servers/visual/rasterizer.h | 1 + servers/visual/visual_server_raster.cpp | 1 + tools/editor/plugins/baked_light_baker.cpp | 6 + .../plugins/baked_light_editor_plugin.cpp | 2 + 15 files changed, 517 insertions(+), 11 deletions(-) diff --git a/core/image.cpp b/core/image.cpp index e5489c06fa8..d9ba6c15942 100644 --- a/core/image.cpp +++ b/core/image.cpp @@ -1399,10 +1399,344 @@ int Image::get_format_pallete_size(Format p_format) { } + + +Error Image::_decompress_bc() { + + print_line("decompressing bc"); + + int mm; + int size = _get_dst_image_size(width,height,FORMAT_RGBA,mm,mipmaps); + + DVector newdata; + newdata.resize(size); + + DVector::Write w = newdata.write(); + DVector::Read r = data.read(); + + int rofs=0; + int wofs=0; + int wd=width,ht=height; + + for(int i=0;i<=mm;i++) { + + switch(format) { + + case FORMAT_BC1: { + + int len = (wd*ht)/16; + uint8_t* dst=&w[wofs]; + + uint32_t ofs_table[16]; + for(int x=0;x<4;x++) { + + for(int y=0;y<4;y++) { + + ofs_table[15-(y*4+(3-x))]=(x+y*wd)*4; + } + } + + + for(int j=0;j>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 }, + { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 }, + {0,0,0,255}, + {0,0,0,255} + }; + + if (col_a>1; + table[2][1]=(int(table[0][1])+int(table[1][1]))>>1; + table[2][2]=(int(table[0][2])+int(table[1][2]))>>1; + table[3][3]=0; //premul alpha black + } else { + //gradient + table[2][0]=(int(table[0][0])*2+int(table[1][0]))/3; + table[2][1]=(int(table[0][1])*2+int(table[1][1]))/3; + table[2][2]=(int(table[0][2])*2+int(table[1][2]))/3; + table[3][0]=(int(table[0][0])+int(table[1][0])*2)/3; + table[3][1]=(int(table[0][1])+int(table[1][1])*2)/3; + table[3][2]=(int(table[0][2])+int(table[1][2])*2)/3; + } + + uint32_t block=src[4]; + block<<=8; + block|=src[5]; + block<<=8; + block|=src[6]; + block<<=8; + block|=src[7]; + + int y = (j/(wd/4))*4; + int x = (j%(wd/4))*4; + int pixofs = (y*wd+x)*4; + + for(int k=0;k<16;k++) { + int idx = pixofs+ofs_table[k]; + dst[idx+0]=table[block&0x3][0]; + dst[idx+1]=table[block&0x3][1]; + dst[idx+2]=table[block&0x3][2]; + dst[idx+3]=table[block&0x3][3]; + block>>=2; + } + + } + + rofs+=len*8; + wofs+=wd*ht*4; + + + wd/=2; + ht/=2; + + } break; + case FORMAT_BC2: { + + int len = (wd*ht)/16; + uint8_t* dst=&w[wofs]; + + uint32_t ofs_table[16]; + for(int x=0;x<4;x++) { + + for(int y=0;y<4;y++) { + + ofs_table[15-(y*4+(3-x))]=(x+y*wd)*4; + } + } + + + for(int j=0;j>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 }, + { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 }, + {0,0,0,255}, + {0,0,0,255} + }; + + //always gradient + table[2][0]=(int(table[0][0])*2+int(table[1][0]))/3; + table[2][1]=(int(table[0][1])*2+int(table[1][1]))/3; + table[2][2]=(int(table[0][2])*2+int(table[1][2]))/3; + table[3][0]=(int(table[0][0])+int(table[1][0])*2)/3; + table[3][1]=(int(table[0][1])+int(table[1][1])*2)/3; + table[3][2]=(int(table[0][2])+int(table[1][2])*2)/3; + + uint32_t block=src[4+8]; + block<<=8; + block|=src[5+8]; + block<<=8; + block|=src[6+8]; + block<<=8; + block|=src[7+8]; + + int y = (j/(wd/4))*4; + int x = (j%(wd/4))*4; + int pixofs = (y*wd+x)*4; + + for(int k=0;k<16;k++) { + uint8_t alpha = ablock&0xf; + alpha=int(alpha)*255/15; //right way for alpha + int idx = pixofs+ofs_table[k]; + dst[idx+0]=table[block&0x3][0]; + dst[idx+1]=table[block&0x3][1]; + dst[idx+2]=table[block&0x3][2]; + dst[idx+3]=alpha; + block>>=2; + ablock>>=4; + } + + } + + rofs+=len*16; + wofs+=wd*ht*4; + + + wd/=2; + ht/=2; + + } break; + case FORMAT_BC3: { + + int len = (wd*ht)/16; + uint8_t* dst=&w[wofs]; + + uint32_t ofs_table[16]; + for(int x=0;x<4;x++) { + + for(int y=0;y<4;y++) { + + ofs_table[15-(y*4+(3-x))]=(x+y*wd)*4; + } + } + + + + for(int j=0;ja_end) { + + atable[0]=(int(a_start)*7+int(a_end)*0)/7; + atable[1]=(int(a_start)*6+int(a_end)*1)/7; + atable[2]=(int(a_start)*5+int(a_end)*2)/7; + atable[3]=(int(a_start)*4+int(a_end)*3)/7; + atable[4]=(int(a_start)*3+int(a_end)*4)/7; + atable[5]=(int(a_start)*2+int(a_end)*5)/7; + atable[6]=(int(a_start)*1+int(a_end)*6)/7; + atable[7]=(int(a_start)*0+int(a_end)*7)/7; + } else { + + atable[0]=(int(a_start)*5+int(a_end)*0)/5; + atable[1]=(int(a_start)*4+int(a_end)*1)/5; + atable[2]=(int(a_start)*3+int(a_end)*2)/5; + atable[3]=(int(a_start)*2+int(a_end)*3)/5; + atable[4]=(int(a_start)*1+int(a_end)*4)/5; + atable[5]=(int(a_start)*0+int(a_end)*5)/5; + atable[6]=0; + atable[7]=255; + + } + + + uint16_t col_a=src[8+1]; + col_a<<=8; + col_a|=src[8+0]; + uint16_t col_b=src[8+3]; + col_b<<=8; + col_b|=src[8+2]; + + uint8_t table[4][4]={ + { (col_a>>11)<<3, ((col_a>>5)&0x3f)<<2, ((col_a)&0x1f)<<3, 255 }, + { (col_b>>11)<<3, ((col_b>>5)&0x3f)<<2, ((col_b)&0x1f)<<3, 255 }, + {0,0,0,255}, + {0,0,0,255} + }; + + //always gradient + table[2][0]=(int(table[0][0])*2+int(table[1][0]))/3; + table[2][1]=(int(table[0][1])*2+int(table[1][1]))/3; + table[2][2]=(int(table[0][2])*2+int(table[1][2]))/3; + table[3][0]=(int(table[0][0])+int(table[1][0])*2)/3; + table[3][1]=(int(table[0][1])+int(table[1][1])*2)/3; + table[3][2]=(int(table[0][2])+int(table[1][2])*2)/3; + + + uint32_t block=src[4+8]; + block<<=8; + block|=src[5+8]; + block<<=8; + block|=src[6+8]; + block<<=8; + block|=src[7+8]; + + int y = (j/(wd/4))*4; + int x = (j%(wd/4))*4; + int pixofs = (y*wd+x)*4; + + + + for(int k=0;k<16;k++) { + uint8_t alpha = ablock&0x7; + int idx = pixofs+ofs_table[k]; + dst[idx+0]=table[block&0x3][0]; + dst[idx+1]=table[block&0x3][1]; + dst[idx+2]=table[block&0x3][2]; + dst[idx+3]=atable[alpha]; + block>>=2; + ablock>>=3; + } + + } + + rofs+=len*16; + wofs+=wd*ht*4; + + + wd/=2; + ht/=2; + + } break; + } + + } + + w=DVector::Write(); + r=DVector::Read(); + + data=newdata; + format=FORMAT_RGBA; + + return OK; +} + + +Image Image::decompressed() const { + + Image img=*this; + img.decompress(); + return img; +} + Error Image::decompress() { - if (format>=FORMAT_BC1 && format<=FORMAT_BC5 && _image_decompress_bc) - _image_decompress_bc(this); + if (format>=FORMAT_BC1 && format<=FORMAT_BC5 ) + _decompress_bc();//_image_decompress_bc(this); else if (format>=FORMAT_PVRTC2 && format<=FORMAT_PVRTC4_ALPHA && _image_decompress_pvrtc) _image_decompress_pvrtc(this); else if (format==FORMAT_ETC && _image_decompress_etc) diff --git a/core/image.h b/core/image.h index ce189f330d4..7a6ee1e4b01 100644 --- a/core/image.h +++ b/core/image.h @@ -99,6 +99,8 @@ public: static void (*_image_decompress_bc)(Image *); static void (*_image_decompress_etc)(Image *); + Error _decompress_bc(); + static DVector (*lossy_packer)(const Image& p_image,float p_quality); static Image (*lossy_unpacker)(const DVector& p_buffer); static DVector (*lossless_packer)(const Image& p_image); @@ -318,6 +320,7 @@ public: Error compress(CompressMode p_mode=COMPRESS_BC); Image compressed(int p_mode); /* from the Image::CompressMode enum */ Error decompress(); + Image decompressed() const; void fix_alpha_edges(); void premultiply_alpha(); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index c245e01ee08..8cdfce1b0ae 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -539,6 +539,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_PTR3(Image,brush_transfer); VCALL_PTR1R(Image,get_rect); VCALL_PTR1R(Image,compressed); + VCALL_PTR0R(Image,decompressed); VCALL_PTR3R(Image, resized); VCALL_PTR0R(Image, get_data); VCALL_PTR3(Image, blit_rect); @@ -1266,6 +1267,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(IMAGE, RECT2, Image, get_used_rect, varray(0)); ADDFUNC1(IMAGE, IMAGE, Image, get_rect, RECT2, "area", varray(0)); ADDFUNC1(IMAGE, IMAGE, Image, compressed, INT, "format", varray(0)); + ADDFUNC0(IMAGE, IMAGE, Image, decompressed, varray(0)); ADDFUNC3(IMAGE, IMAGE, Image, resized, INT, "x", INT, "y", INT, "interpolation", varray(((int)Image::INTERPOLATE_BILINEAR))); ADDFUNC0(IMAGE, RAW_ARRAY, Image, get_data, varray()); ADDFUNC3(IMAGE, NIL, Image, blit_rect, IMAGE, "src", RECT2, "src_rect", VECTOR2, "dest", varray(0)); diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index 307db4b7624..c9952c6fb8c 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -5739,6 +5739,7 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_LATTICE_DIVIDE, baked_light->octree_lattice_divide); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_STEPS, baked_light->octree_steps); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_TEX,5); + material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_MULTIPLIER,baked_light->texture_multiplier); material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_OCTREE_PIX_SIZE,baked_light->octree_tex_pixel_size); diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl index 3aed9820edc..8e7d321fe77 100644 --- a/drivers/gles2/shaders/material.glsl +++ b/drivers/gles2/shaders/material.glsl @@ -548,6 +548,7 @@ uniform highp float ambient_octree_lattice_size; uniform highp vec2 ambient_octree_pix_size; uniform highp float ambient_octree_lattice_divide; uniform highp sampler2D ambient_octree_tex; +uniform float ambient_octree_multiplier; uniform int ambient_octree_steps; #endif @@ -824,7 +825,7 @@ FRAGMENT_SHADER_CODE vec3 col_up=texture2D(ambient_octree_tex,octant_uv).rgb; octant_uv.y+=ambient_octree_pix_size.y*2.0; vec3 col_down=texture2D(ambient_octree_tex,octant_uv).rgb; - ambientmap_color=mix(col_up,col_down,sub.z); + ambientmap_color=mix(col_up,col_down,sub.z)*ambient_octree_multiplier; ambientmap_color*=diffuse.rgb; diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index fdd30c5f603..b13fdabea94 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -432,6 +432,46 @@ float ScrollBar::get_custom_step() const { } +void ScrollBar::_drag_slave_exit() { + + +} + + +void ScrollBar::_drag_slave_input(const InputEvent& p_input) { + + +} + +void ScrollBar::set_drag_slave(const NodePath& p_path) { + + if (drag_slave) { + drag_slave->disconnect("input_event",this,"_drag_slave_input"); + drag_slave->disconnect("exit_scene",this,"_drag_slave_exit"); + } + + drag_slave=NULL; + drag_slave_path=p_path; + if (has_node(p_path)) { + Node *n = get_node(p_path); + drag_slave=n->cast_to(); + } + + if (drag_slave) { + drag_slave->connect("input_event",this,"_drag_slave_input"); + drag_slave->connect("exit_scene",this,"_drag_slave_exit",varray(),CONNECT_ONESHOT); + } + +} + +NodePath ScrollBar::get_drag_slave() const{ + + + return drag_slave_path; +} + + + #if 0 void ScrollBar::mouse_button(const Point2& p_pos, int b.button_index,bool b.pressed,int p_modifier_mask) { @@ -571,6 +611,8 @@ void ScrollBar::_bind_methods() { ObjectTypeDB::bind_method(_MD("_input_event"),&ScrollBar::_input_event); ObjectTypeDB::bind_method(_MD("set_custom_step","step"),&ScrollBar::set_custom_step); ObjectTypeDB::bind_method(_MD("get_custom_step"),&ScrollBar::get_custom_step); + ObjectTypeDB::bind_method(_MD("_drag_slave_input"),&ScrollBar::_drag_slave_input); + ObjectTypeDB::bind_method(_MD("_drag_slave_exit"),&ScrollBar::_drag_slave_exit); ADD_PROPERTY( PropertyInfo(Variant::REAL,"custom_step",PROPERTY_HINT_RANGE,"-1,4096"), _SCS("set_custom_step"),_SCS("get_custom_step")); @@ -584,6 +626,7 @@ ScrollBar::ScrollBar(Orientation p_orientation) orientation=p_orientation; hilite=HILITE_NONE; custom_step=-1; + drag_slave=NULL; drag.active=false; diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index 663d3ecd85c..0c209820836 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -70,7 +70,12 @@ class ScrollBar : public Range { double get_grabber_offset() const; static void set_can_focus_by_default(bool p_can_focus); - + + Node* drag_slave; + NodePath drag_slave_path; + + void _drag_slave_exit(); + void _drag_slave_input(const InputEvent& p_input); void _input_event(InputEvent p_event); protected: @@ -83,6 +88,9 @@ public: void set_custom_step(float p_custom_step); float get_custom_step() const; + void set_drag_slave(const NodePath& p_path); + NodePath get_drag_slave() const; + virtual Size2 get_minimum_size() const; ScrollBar(Orientation p_orientation=VERTICAL); ~ScrollBar(); diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp index b3de7143ee6..725ac1c9462 100644 --- a/scene/resources/baked_light.cpp +++ b/scene/resources/baked_light.cpp @@ -201,6 +201,16 @@ bool BakedLight::get_bake_flag(BakeFlags p_flags) const{ return flags[p_flags]; } +void BakedLight::set_format(Format p_format) { + + format=p_format; + +} + +BakedLight::Format BakedLight::get_format() const{ + + return format; +} void BakedLight::_bind_methods(){ @@ -240,6 +250,10 @@ void BakedLight::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_normal_damp","normal_damp"),&BakedLight::set_normal_damp); ObjectTypeDB::bind_method(_MD("get_normal_damp"),&BakedLight::get_normal_damp); + ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format); + ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format); + + ObjectTypeDB::bind_method(_MD("set_energy_multiplier","energy_multiplier"),&BakedLight::set_energy_multiplier); ObjectTypeDB::bind_method(_MD("get_energy_multiplier"),&BakedLight::get_energy_multiplier); @@ -251,6 +265,7 @@ void BakedLight::_bind_methods(){ ADD_PROPERTY( PropertyInfo(Variant::INT,"mode/mode",PROPERTY_HINT_ENUM,"Octree,Lightmaps"),_SCS("set_mode"),_SCS("get_mode")); + ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/format",PROPERTY_HINT_ENUM,"RGB,HDR8,HDR16"),_SCS("set_format"),_SCS("get_format")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/cell_subdiv",PROPERTY_HINT_RANGE,"4,14,1"),_SCS("set_cell_subdivision"),_SCS("get_cell_subdivision")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/lattice_subdiv",PROPERTY_HINT_RANGE,"1,5,1"),_SCS("set_initial_lattice_subdiv"),_SCS("get_initial_lattice_subdiv")); ADD_PROPERTY( PropertyInfo(Variant::INT,"baking/light_bounces",PROPERTY_HINT_RANGE,"0,3,1"),_SCS("set_bounces"),_SCS("get_bounces")); @@ -292,6 +307,7 @@ BakedLight::BakedLight() { cell_extra_margin=0.05; edge_damp=0.0; normal_damp=0.0; + format=FORMAT_RGB; flags[BAKE_DIFFUSE]=true; flags[BAKE_SPECULAR]=false; diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h index 8b50f6e0d3d..df86f98c084 100644 --- a/scene/resources/baked_light.h +++ b/scene/resources/baked_light.h @@ -14,6 +14,13 @@ public: MODE_LIGHTMAPS }; + enum Format { + + FORMAT_RGB, + FORMAT_HDR8, + FORMAT_HDR16 + }; + enum BakeFlags { BAKE_DIFFUSE, BAKE_SPECULAR, @@ -38,6 +45,7 @@ private: float edge_damp; float normal_damp; int bounces; + Format format; bool flags[BAKE_MAX]; @@ -80,6 +88,8 @@ public: void set_bake_flag(BakeFlags p_flags,bool p_enable); bool get_bake_flag(BakeFlags p_flags) const; + void set_format(Format p_margin); + Format get_format() const; void set_mode(Mode p_mode); Mode get_mode() const; @@ -100,6 +110,7 @@ public: }; +VARIANT_ENUM_CAST(BakedLight::Format); VARIANT_ENUM_CAST(BakedLight::Mode); VARIANT_ENUM_CAST(BakedLight::BakeFlags); diff --git a/scene/resources/polygon_path_finder.cpp b/scene/resources/polygon_path_finder.cpp index 9f7b6d5b9e7..ca8b6bc110e 100644 --- a/scene/resources/polygon_path_finder.cpp +++ b/scene/resources/polygon_path_finder.cpp @@ -2,7 +2,7 @@ #include "geometry.h" -bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) { +bool PolygonPathFinder::_is_point_inside(const Vector2& p_point) const { int crosses=0; @@ -36,6 +36,7 @@ void PolygonPathFinder::setup(const Vector& p_points, const Vector int point_count=p_points.size(); points.resize(point_count+2); + bounds=Rect2(); for(int i=0;i& p_points, const Vector outside_point.x = i==0?p_points[0].x:(MAX( p_points[i].x, outside_point.x )); outside_point.y = i==0?p_points[0].y:(MAX( p_points[i].y, outside_point.y )); + + if (i==0) { + bounds.pos=points[i].pos; + } else { + bounds.expand_to(points[i].pos); + } } outside_point.x+=20.451+Math::randf()*10.2039; @@ -108,10 +115,14 @@ void PolygonPathFinder::setup(const Vector& p_points, const Vector Vector PolygonPathFinder::find_path(const Vector2& p_from, const Vector2& p_to) { Vector path; - if (!_is_point_inside(p_from)) + if (!_is_point_inside(p_from)) { + printf("p_from outside\n"); return path; - if (!_is_point_inside(p_to)) + }; + if (!_is_point_inside(p_to)) { + printf("p_to outside\n"); return path; + }; //test direct connection { @@ -148,8 +159,8 @@ Vector PolygonPathFinder::find_path(const Vector2& p_from, const Vector points[bidx].pos=p_to; points[aidx].distance=0; points[bidx].distance=0; - points[aidx].distance=0; - points[bidx].distance=0; + points[aidx].prev=-1; + points[bidx].prev=-1; for(int i=0;i PolygonPathFinder::find_path(const Vector2& p_from, const Vector } if (!valid_a && !valid_b) - continue; + break; } @@ -220,6 +231,7 @@ Vector PolygonPathFinder::find_path(const Vector2& p_from, const Vector while(true) { if (open_list.size()==0) { + printf("open list empty\n"); break; } //check open list @@ -315,6 +327,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) { ERR_FAIL_COND(!p_data.has("points")); ERR_FAIL_COND(!p_data.has("connections")); ERR_FAIL_COND(!p_data.has("segments")); + ERR_FAIL_COND(!p_data.has("bounds")); DVector p=p_data["points"]; Array c=p_data["connections"]; @@ -348,6 +361,7 @@ void PolygonPathFinder::_set_data(const Dictionary& p_data) { Edge e(sr[i],sr[i+1]); edges.insert(e); } + bounds=p_data["bounds"]; } @@ -387,6 +401,7 @@ Dictionary PolygonPathFinder::_get_data() const{ } + d["bounds"]=bounds; d["points"]=p; d["connections"]=connections; d["segments"]=ind; @@ -395,10 +410,63 @@ Dictionary PolygonPathFinder::_get_data() const{ } +bool PolygonPathFinder::is_point_inside(const Vector2& p_point) const { + + return _is_point_inside(p_point); +} + +Vector2 PolygonPathFinder::get_closest_point(const Vector2& p_point) const { + + int closest_idx=-1; + float closest_dist=1e20; + for(int i=0;i PolygonPathFinder::get_intersections(const Vector2& p_from, const Vector2& p_to) const { + + Vector inters; + + for (Set::Element *E=edges.front();E;E=E->next()) { + Vector2 a = points[E->get().points[0]].pos; + Vector2 b = points[E->get().points[1]].pos; + + Vector2 res; + if (Geometry::segment_intersects_segment_2d(a,b,p_from,p_to,&res)) { + inters.push_back(res); + } + } + + return inters; + +} + +Rect2 PolygonPathFinder::get_bounds() const { + + return bounds; +} + + void PolygonPathFinder::_bind_methods() { ObjectTypeDB::bind_method(_MD("setup","points","connections"),&PolygonPathFinder::setup); ObjectTypeDB::bind_method(_MD("find_path","from","to"),&PolygonPathFinder::find_path); + ObjectTypeDB::bind_method(_MD("get_intersections","from","to"),&PolygonPathFinder::get_intersections); + ObjectTypeDB::bind_method(_MD("get_closest_point","point"),&PolygonPathFinder::get_closest_point); + ObjectTypeDB::bind_method(_MD("is_point_inside","point"),&PolygonPathFinder::is_point_inside); + ObjectTypeDB::bind_method(_MD("get_bounds"),&PolygonPathFinder::get_bounds); ObjectTypeDB::bind_method(_MD("_set_data"),&PolygonPathFinder::_set_data); ObjectTypeDB::bind_method(_MD("_get_data"),&PolygonPathFinder::_get_data); diff --git a/scene/resources/polygon_path_finder.h b/scene/resources/polygon_path_finder.h index 31253e3177b..002ce709ec8 100644 --- a/scene/resources/polygon_path_finder.h +++ b/scene/resources/polygon_path_finder.h @@ -31,15 +31,18 @@ class PolygonPathFinder : public Resource { if (a>b) { SWAP(a,b); } + points[0] = a; + points[1] = b; } }; Vector2 outside_point; + Rect2 bounds; Vector points; Set edges; - bool _is_point_inside(const Vector2& p_point); + bool _is_point_inside(const Vector2& p_point) const; void _set_data(const Dictionary& p_data); Dictionary _get_data() const; @@ -52,6 +55,12 @@ public: void setup(const Vector& p_points, const Vector& p_connections); Vector find_path(const Vector2& p_from, const Vector2& p_to); + bool is_point_inside(const Vector2& p_point) const; + Vector2 get_closest_point(const Vector2& p_point) const; + Vector get_intersections(const Vector2& p_from, const Vector2& p_to) const; + Rect2 get_bounds() const; + + PolygonPathFinder(); }; diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 2e94f3fe9d1..dc43a789845 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -508,6 +508,7 @@ public: float octree_lattice_size; float octree_lattice_divide; + float texture_multiplier; int octree_steps; Vector2 octree_tex_pixel_size; }; diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 8f1d444185d..4e14e8b26cb 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -1098,6 +1098,7 @@ void VisualServerRaster::baked_light_set_octree(RID p_baked_light,const DVector< baked_light->data.octree_steps=decode_uint32(&r[16]); baked_light->data.octree_tex_pixel_size.x=1.0/tex_w; baked_light->data.octree_tex_pixel_size.y=1.0/tex_h; + baked_light->data.texture_multiplier=decode_uint32(&r[20]); baked_light->octree_aabb.pos.x=decode_float(&r[32]); diff --git a/tools/editor/plugins/baked_light_baker.cpp b/tools/editor/plugins/baked_light_baker.cpp index 36948673a89..1fa4d8d06c7 100644 --- a/tools/editor/plugins/baked_light_baker.cpp +++ b/tools/editor/plugins/baked_light_baker.cpp @@ -1498,11 +1498,16 @@ void BakedLightBaker::update_octree_image(DVector &p_image) { w[i+3]=0xFF; } + float multiplier=1.0; + + if (baked_light->get_format()==BakedLight::FORMAT_HDR8) + multiplier=8; encode_uint32(baked_octree_texture_w,&w[0]); encode_uint32(baked_octree_texture_h,&w[4]); encode_uint32(0,&w[8]); encode_float(1< &p_image) { const double *normptr=norm_arr.ptr(); int lz=lights.size(); + mult/=multiplier; for(int i=0;iget_ticks_msec()-t)); t=OS::get_singleton()->get_ticks_msec(); node->get_baked_light()->set_octree(octree_texture); + node->get_baked_light()->set_edited(true); + print_line("MSSET: "+itos(OS::get_singleton()->get_ticks_msec()-t));