Bladeren bron

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)

Juan Linietsky 11 jaren geleden
bovenliggende
commit
ddc0e7fd3b

+ 336 - 2
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<uint8_t> newdata;
+	newdata.resize(size);
+
+	DVector<uint8_t>::Write w = newdata.write();
+	DVector<uint8_t>::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<len;j++) {
+
+					const uint8_t* src=&r[rofs+j*8];
+					uint16_t col_a=src[1];
+					col_a<<=8;
+					col_a|=src[0];
+					uint16_t col_b=src[3];
+					col_b<<=8;
+					col_b|=src[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}
+					};
+
+					if (col_a<col_b) {
+						//punchrough
+						table[2][0]=(int(table[0][0])+int(table[1][0]))>>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<len;j++) {
+
+					const uint8_t* src=&r[rofs+j*16];
+
+					uint64_t ablock=src[1];
+					ablock<<=8;
+					ablock|=src[0];
+					ablock<<=8;
+					ablock|=src[3];
+					ablock<<=8;
+					ablock|=src[2];
+					ablock<<=8;
+					ablock|=src[5];
+					ablock<<=8;
+					ablock|=src[4];
+					ablock<<=8;
+					ablock|=src[7];
+					ablock<<=8;
+					ablock|=src[6];
+
+
+					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&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;j<len;j++) {
+
+					const uint8_t* src=&r[rofs+j*16];
+
+					uint8_t a_start=src[1];
+					uint8_t a_end=src[0];
+
+					uint64_t ablock=src[3];
+					ablock<<=8;
+					ablock|=src[2];
+					ablock<<=8;
+					ablock|=src[5];
+					ablock<<=8;
+					ablock|=src[4];
+					ablock<<=8;
+					ablock|=src[7];
+					ablock<<=8;
+					ablock|=src[6];
+
+					uint8_t atable[8];
+
+					if (a_start>a_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<uint8_t>::Write();
+	r=DVector<uint8_t>::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)

+ 3 - 0
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<uint8_t> (*lossy_packer)(const Image& p_image,float p_quality);
 	static Image (*lossy_unpacker)(const DVector<uint8_t>& p_buffer);
 	static DVector<uint8_t> (*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();

+ 2 - 0
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));

+ 1 - 0
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);
 
 

+ 2 - 1
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;
 

+ 43 - 0
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<Control>();
+	}
+
+	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;
 	

+ 9 - 1
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();

+ 16 - 0
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;

+ 11 - 0
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);
 

+ 74 - 6
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<Vector2>& p_points, const Vector<int>
 
 	int point_count=p_points.size();
 	points.resize(point_count+2);
+	bounds=Rect2();
 
 	for(int i=0;i<p_points.size();i++) {
 
@@ -43,6 +44,12 @@ void PolygonPathFinder::setup(const Vector<Vector2>& p_points, const Vector<int>
 
 		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<Vector2>& p_points, const Vector<int>
 Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector2& p_to) {
 
 	Vector<Vector2> 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<Vector2> 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<points.size()-2;i++) {
@@ -185,7 +196,7 @@ Vector<Vector2> PolygonPathFinder::find_path(const Vector2& p_from, const Vector
 			}
 
 			if (!valid_a && !valid_b)
-				continue;
+				break;
 
 		}
 
@@ -220,6 +231,7 @@ Vector<Vector2> 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<Vector2> 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<points.size()-2;i++) {
+
+		float d = p_point.distance_squared_to(points[i].pos);
+		if (d<closest_dist) {
+			d=closest_dist;
+			closest_idx=i;
+		}
+
+	}
+
+	ERR_FAIL_COND_V(closest_idx==-1,Vector2());
+
+	return points[closest_idx].pos;
+}
+
+
+Vector<Vector2> PolygonPathFinder::get_intersections(const Vector2& p_from, const Vector2& p_to) const {
+
+	Vector<Vector2> inters;
+
+	for (Set<Edge>::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);
 

+ 10 - 1
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<Point> points;
 	Set<Edge> 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<Vector2>& p_points, const Vector<int>& p_connections);
 	Vector<Vector2> 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<Vector2> get_intersections(const Vector2& p_from, const Vector2& p_to) const;
+	Rect2 get_bounds() const;
+
+
 	PolygonPathFinder();
 };
 

+ 1 - 0
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;
 	};

+ 1 - 0
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]);

+ 6 - 0
tools/editor/plugins/baked_light_baker.cpp

@@ -1498,11 +1498,16 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &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<<lattice_size,&w[12]);
 	encode_uint32(octree_depth-lattice_size,&w[16]);
+	encode_uint32(multiplier,&w[20]);
 
 	encode_float(octree_aabb.pos.x,&w[32]);
 	encode_float(octree_aabb.pos.y,&w[36]);
@@ -1538,6 +1543,7 @@ void BakedLightBaker::update_octree_image(DVector<uint8_t> &p_image) {
 	const double *normptr=norm_arr.ptr();
 
 	int lz=lights.size();
+	mult/=multiplier;
 
 	for(int i=0;i<octant_count;i++) {
 

+ 2 - 0
tools/editor/plugins/baked_light_editor_plugin.cpp

@@ -125,6 +125,8 @@ void BakedLightEditor::_notification(int p_option) {
 				print_line("MSUPDATE: "+itos(OS::get_singleton()->get_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));