From 3da3a36034bff7988e9ade868d06cec7977ca8af Mon Sep 17 00:00:00 2001
From: Juan Linietsky <reduzio@gmail.com>
Date: Sat, 15 Jul 2017 23:24:37 -0300
Subject: [PATCH] Many fixes to improve GI Probe quality

---
 drivers/gles3/rasterizer_scene_gles3.cpp   |  7 +++--
 drivers/gles3/rasterizer_storage_gles3.cpp | 17 +++++++++++
 drivers/gles3/rasterizer_storage_gles3.h   |  4 +++
 drivers/gles3/shaders/scene.glsl           | 27 ++++++++++-------
 modules/gridmap/grid_map.cpp               |  1 +
 scene/3d/gi_probe.cpp                      | 34 +++++++++++++++++++++-
 scene/3d/gi_probe.h                        |  7 +++++
 servers/visual/rasterizer.h                | 12 +++++---
 servers/visual/visual_server_raster.h      |  3 ++
 servers/visual/visual_server_scene.cpp     |  5 ++++
 servers/visual/visual_server_wrap_mt.h     |  3 ++
 servers/visual_server.h                    |  3 ++
 12 files changed, 105 insertions(+), 18 deletions(-)

diff --git a/drivers/gles3/rasterizer_scene_gles3.cpp b/drivers/gles3/rasterizer_scene_gles3.cpp
index f87b4336fe9..8dfa91473ac 100644
--- a/drivers/gles3/rasterizer_scene_gles3.cpp
+++ b/drivers/gles3/rasterizer_scene_gles3.cpp
@@ -1834,12 +1834,14 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform
 
 		GIProbeInstance *gipi = gi_probe_instance_owner.getptr(ridp[0]);
 
+		float bias_scale = e->instance->baked_light ? 1 : 0;
 		glActiveTexture(GL_TEXTURE0 + storage->config.max_texture_image_units - 9);
 		glBindTexture(GL_TEXTURE_3D, gipi->tex_cache);
 		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_XFORM1, gipi->transform_to_data * p_view_transform);
 		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS1, gipi->bounds);
 		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER1, gipi->probe ? gipi->probe->dynamic_range * gipi->probe->energy : 0.0);
-		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS1, gipi->probe ? gipi->probe->bias : 0.0);
+		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS1, gipi->probe ? gipi->probe->bias * bias_scale : 0.0);
+		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_NORMAL_BIAS1, gipi->probe ? gipi->probe->normal_bias * bias_scale : 0.0);
 		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT1, gipi->probe ? !gipi->probe->interior : false);
 		state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE1, gipi->cell_size_cache);
 		if (gi_probe_count > 1) {
@@ -1852,7 +1854,8 @@ void RasterizerSceneGLES3::_setup_light(RenderList::Element *e, const Transform
 			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BOUNDS2, gipi2->bounds);
 			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_CELL_SIZE2, gipi2->cell_size_cache);
 			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_MULTIPLIER2, gipi2->probe ? gipi2->probe->dynamic_range * gipi2->probe->energy : 0.0);
-			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS2, gipi2->probe ? gipi2->probe->bias : 0.0);
+			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BIAS2, gipi2->probe ? gipi2->probe->bias * bias_scale : 0.0);
+			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_NORMAL_BIAS2, gipi2->probe ? gipi2->probe->normal_bias * bias_scale : 0.0);
 			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE_BLEND_AMBIENT2, gipi2->probe ? !gipi2->probe->interior : false);
 			state.scene_shader.set_uniform(SceneShaderGLES3::GI_PROBE2_ENABLED, true);
 		} else {
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index 14fb36f3b0e..ab12bcef6d8 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -4866,6 +4866,7 @@ RID RasterizerStorageGLES3::gi_probe_create() {
 	gip->energy = 1.0;
 	gip->propagation = 1.0;
 	gip->bias = 0.4;
+	gip->normal_bias = 0.4;
 	gip->interior = false;
 	gip->compress = false;
 	gip->version = 1;
@@ -4972,6 +4973,14 @@ void RasterizerStorageGLES3::gi_probe_set_bias(RID p_probe, float p_range) {
 	gip->bias = p_range;
 }
 
+void RasterizerStorageGLES3::gi_probe_set_normal_bias(RID p_probe, float p_range) {
+
+	GIProbe *gip = gi_probe_owner.getornull(p_probe);
+	ERR_FAIL_COND(!gip);
+
+	gip->normal_bias = p_range;
+}
+
 void RasterizerStorageGLES3::gi_probe_set_propagation(RID p_probe, float p_range) {
 
 	GIProbe *gip = gi_probe_owner.getornull(p_probe);
@@ -5027,6 +5036,14 @@ float RasterizerStorageGLES3::gi_probe_get_bias(RID p_probe) const {
 	return gip->bias;
 }
 
+float RasterizerStorageGLES3::gi_probe_get_normal_bias(RID p_probe) const {
+
+	const GIProbe *gip = gi_probe_owner.getornull(p_probe);
+	ERR_FAIL_COND_V(!gip, 0);
+
+	return gip->normal_bias;
+}
+
 float RasterizerStorageGLES3::gi_probe_get_propagation(RID p_probe) const {
 
 	const GIProbe *gip = gi_probe_owner.getornull(p_probe);
diff --git a/drivers/gles3/rasterizer_storage_gles3.h b/drivers/gles3/rasterizer_storage_gles3.h
index 183db534acc..b24da44afdb 100644
--- a/drivers/gles3/rasterizer_storage_gles3.h
+++ b/drivers/gles3/rasterizer_storage_gles3.h
@@ -972,6 +972,7 @@ public:
 		int dynamic_range;
 		float energy;
 		float bias;
+		float normal_bias;
 		float propagation;
 		bool interior;
 		bool compress;
@@ -1006,6 +1007,9 @@ public:
 	virtual void gi_probe_set_bias(RID p_probe, float p_range);
 	virtual float gi_probe_get_bias(RID p_probe) const;
 
+	virtual void gi_probe_set_normal_bias(RID p_probe, float p_range);
+	virtual float gi_probe_get_normal_bias(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;
 
diff --git a/drivers/gles3/shaders/scene.glsl b/drivers/gles3/shaders/scene.glsl
index 7b785c85508..9d474d39021 100644
--- a/drivers/gles3/shaders/scene.glsl
+++ b/drivers/gles3/shaders/scene.glsl
@@ -1172,6 +1172,7 @@ uniform highp vec3 gi_probe_bounds1;
 uniform highp vec3 gi_probe_cell_size1;
 uniform highp float gi_probe_multiplier1;
 uniform highp float gi_probe_bias1;
+uniform highp float gi_probe_normal_bias1;
 uniform bool gi_probe_blend_ambient1;
 
 uniform mediump sampler3D gi_probe2; //texunit:-10
@@ -1180,12 +1181,12 @@ uniform highp vec3 gi_probe_bounds2;
 uniform highp vec3 gi_probe_cell_size2;
 uniform highp float gi_probe_multiplier2;
 uniform highp float gi_probe_bias2;
+uniform highp float gi_probe_normal_bias2;
 uniform bool gi_probe2_enabled;
 uniform bool gi_probe_blend_ambient2;
 
 vec3 voxel_cone_trace(sampler3D probe, vec3 cell_size, vec3 pos, vec3 ambient, bool blend_ambient, vec3 direction, float tan_half_angle, float max_distance, float p_bias) {
 
-
 	float dist = p_bias;//1.0; //dot(direction,mix(vec3(-1.0),vec3(1.0),greaterThan(direction,vec3(0.0))))*2.0;
 	float alpha=0.0;
 	vec3 color = vec3(0.0);
@@ -1206,27 +1207,30 @@ vec3 voxel_cone_trace(sampler3D probe, vec3 cell_size, vec3 pos, vec3 ambient, b
 	return color;
 }
 
-void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_size,vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient,float multiplier, mat3 normal_mtx,vec3 ref_vec, float roughness,float p_bias, out vec4 out_spec, out vec4 out_diff) {
+void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_size,vec3 pos, vec3 ambient, vec3 environment, bool blend_ambient,float multiplier, mat3 normal_mtx,vec3 ref_vec, float roughness,float p_bias,float p_normal_bias, inout vec4 out_spec, inout vec4 out_diff) {
 
 
 
 	vec3 probe_pos = (probe_xform * vec4(pos,1.0)).xyz;
 	vec3 ref_pos = (probe_xform * vec4(pos+ref_vec,1.0)).xyz;
-
 	ref_vec = normalize(ref_pos - probe_pos);
 
+	probe_pos+=(probe_xform * vec4(normal_mtx[2],0.0)).xyz*p_normal_bias;
+
 /*	out_diff.rgb = voxel_cone_trace(probe,cell_size,probe_pos,normalize((probe_xform * vec4(ref_vec,0.0)).xyz),0.0 ,100.0);
 	out_diff.a = 1.0;
 	return;*/
 	//out_diff = vec4(textureLod(probe,probe_pos*cell_size,3.0).rgb,1.0);
 	//return;
 
-	if (any(bvec2(any(lessThan(probe_pos,vec3(0.0))),any(greaterThan(probe_pos,bounds)))))
+	//this causes corrupted pixels, i have no idea why..
+	if (any(bvec2(any(lessThan(probe_pos,vec3(0.0))),any(greaterThan(probe_pos,bounds))))) {
 		return;
+	}
 
-	vec3 blendv = probe_pos/bounds * 2.0 - 1.0;
-	float blend = 1.001-max(blendv.x,max(blendv.y,blendv.z));
-	blend=1.0;
+	//vec3 blendv = probe_pos/bounds * 2.0 - 1.0;
+	//float blend = 1.001-max(blendv.x,max(blendv.y,blendv.z));
+	float blend=1.0;
 
 	float max_distance = length(bounds);
 
@@ -1273,7 +1277,7 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s
 
 	light*=multiplier;
 
-	out_diff = vec4(light*blend,blend);
+	out_diff += vec4(light*blend,blend);
 
 	//irradiance
 
@@ -1282,7 +1286,8 @@ void gi_probe_compute(sampler3D probe, mat4 probe_xform, vec3 bounds,vec3 cell_s
 	irr_light *= multiplier;
 	//irr_light=vec3(0.0);
 
-	out_spec = vec4(irr_light*blend,blend);
+	out_spec += vec4(irr_light*blend,blend);
+
 }
 
 
@@ -1308,11 +1313,11 @@ void gi_probes_compute(vec3 pos, vec3 normal, float roughness, inout vec3 out_sp
 
 	out_specular = vec3(0.0);
 
-	gi_probe_compute(gi_probe1,gi_probe_xform1,gi_probe_bounds1,gi_probe_cell_size1,pos,ambient,environment,gi_probe_blend_ambient1,gi_probe_multiplier1,normal_mat,ref_vec,roughness,gi_probe_bias1,spec_accum,diff_accum);
+	gi_probe_compute(gi_probe1,gi_probe_xform1,gi_probe_bounds1,gi_probe_cell_size1,pos,ambient,environment,gi_probe_blend_ambient1,gi_probe_multiplier1,normal_mat,ref_vec,roughness,gi_probe_bias1,gi_probe_normal_bias1,spec_accum,diff_accum);
 
 	if (gi_probe2_enabled) {
 
-		gi_probe_compute(gi_probe2,gi_probe_xform2,gi_probe_bounds2,gi_probe_cell_size2,pos,ambient,environment,gi_probe_blend_ambient2,gi_probe_multiplier2,normal_mat,ref_vec,roughness,gi_probe_bias2,spec_accum,diff_accum);
+		gi_probe_compute(gi_probe2,gi_probe_xform2,gi_probe_bounds2,gi_probe_cell_size2,pos,ambient,environment,gi_probe_blend_ambient2,gi_probe_multiplier2,normal_mat,ref_vec,roughness,gi_probe_bias2,gi_probe_normal_bias2,spec_accum,diff_accum);
 	}
 
 	if (diff_accum.a>0.0) {
diff --git a/modules/gridmap/grid_map.cpp b/modules/gridmap/grid_map.cpp
index 9d3da8227c9..8c2c2ea3451 100644
--- a/modules/gridmap/grid_map.cpp
+++ b/modules/gridmap/grid_map.cpp
@@ -380,6 +380,7 @@ void GridMap::set_cell_item(int p_x, int p_y, int p_z, int p_item, int p_rot) {
 		ii.multimesh->set_mesh(ii.mesh);
 		ii.multimesh_instance = VS::get_singleton()->instance_create();
 		VS::get_singleton()->instance_set_base(ii.multimesh_instance, ii.multimesh->get_rid());
+		VS::get_singleton()->instance_geometry_set_flag(ii.multimesh_instance, VS::INSTANCE_FLAG_USE_BAKED_LIGHT, true);
 
 		g.items[p_item] = ii;
 	}
diff --git a/scene/3d/gi_probe.cpp b/scene/3d/gi_probe.cpp
index adca1492c30..581dfb32c81 100644
--- a/scene/3d/gi_probe.cpp
+++ b/scene/3d/gi_probe.cpp
@@ -95,6 +95,16 @@ float GIProbeData::get_bias() const {
 	return VS::get_singleton()->gi_probe_get_bias(probe);
 }
 
+void GIProbeData::set_normal_bias(float p_range) {
+
+	VS::get_singleton()->gi_probe_set_normal_bias(probe, p_range);
+}
+
+float GIProbeData::get_normal_bias() const {
+
+	return VS::get_singleton()->gi_probe_get_normal_bias(probe);
+}
+
 void GIProbeData::set_propagation(float p_range) {
 
 	VS::get_singleton()->gi_probe_set_propagation(probe, p_range);
@@ -158,6 +168,9 @@ void GIProbeData::_bind_methods() {
 	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_normal_bias", "bias"), &GIProbeData::set_normal_bias);
+	ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbeData::get_normal_bias);
+
 	ClassDB::bind_method(D_METHOD("set_propagation", "propagation"), &GIProbeData::set_propagation);
 	ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbeData::get_propagation);
 
@@ -175,6 +188,7 @@ void GIProbeData::_bind_methods() {
 	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, "normal_bias", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_normal_bias", "get_normal_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");
@@ -265,6 +279,18 @@ float GIProbe::get_bias() const {
 	return bias;
 }
 
+void GIProbe::set_normal_bias(float p_normal_bias) {
+
+	normal_bias = p_normal_bias;
+	if (probe_data.is_valid()) {
+		probe_data->set_normal_bias(normal_bias);
+	}
+}
+float GIProbe::get_normal_bias() const {
+
+	return normal_bias;
+}
+
 void GIProbe::set_propagation(float p_propagation) {
 
 	propagation = p_propagation;
@@ -1261,6 +1287,7 @@ void GIProbe::bake(Node *p_from_node, bool p_create_visual_debug) {
 		probe_data->set_dynamic_range(dynamic_range);
 		probe_data->set_energy(energy);
 		probe_data->set_bias(bias);
+		probe_data->set_normal_bias(normal_bias);
 		probe_data->set_propagation(propagation);
 		probe_data->set_interior(interior);
 		probe_data->set_compress(compress);
@@ -1434,6 +1461,9 @@ void GIProbe::_bind_methods() {
 	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_normal_bias", "max"), &GIProbe::set_normal_bias);
+	ClassDB::bind_method(D_METHOD("get_normal_bias"), &GIProbe::get_normal_bias);
+
 	ClassDB::bind_method(D_METHOD("set_propagation", "max"), &GIProbe::set_propagation);
 	ClassDB::bind_method(D_METHOD("get_propagation"), &GIProbe::get_propagation);
 
@@ -1453,6 +1483,7 @@ void GIProbe::_bind_methods() {
 	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::REAL, "normal_bias", PROPERTY_HINT_RANGE, "0,4,0.001"), "set_normal_bias", "get_normal_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");
@@ -1468,7 +1499,8 @@ GIProbe::GIProbe() {
 	subdiv = SUBDIV_128;
 	dynamic_range = 4;
 	energy = 1.0;
-	bias = 1.8;
+	bias = 0.0;
+	normal_bias = 0.8;
 	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 b5ee86455ee..3f5a50a560b 100644
--- a/scene/3d/gi_probe.h
+++ b/scene/3d/gi_probe.h
@@ -67,6 +67,9 @@ public:
 	void set_bias(float p_range);
 	float get_bias() const;
 
+	void set_normal_bias(float p_range);
+	float get_normal_bias() const;
+
 	void set_interior(bool p_enable);
 	bool is_interior() const;
 
@@ -163,6 +166,7 @@ private:
 	int dynamic_range;
 	float energy;
 	float bias;
+	float normal_bias;
 	float propagation;
 	bool interior;
 	bool compress;
@@ -204,6 +208,9 @@ public:
 	void set_bias(float p_bias);
 	float get_bias() const;
 
+	void set_normal_bias(float p_normal_bias);
+	float get_normal_bias() const;
+
 	void set_propagation(float p_propagation);
 	float get_propagation() const;
 
diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h
index ca80d5e4572..9c264ead498 100644
--- a/servers/visual/rasterizer.h
+++ b/servers/visual/rasterizer.h
@@ -109,19 +109,20 @@ public:
 		bool mirror : 8;
 		bool receive_shadows : 8;
 		bool visible : 8;
+		bool baked_light : 8; //this flag is only to know if it actually did use baked light
 
 		float depth; //used for sorting
 
 		SelfList<InstanceBase> dependency_item;
-		InstanceBase *baked_light; //baked light to use
-		SelfList<InstanceBase> baked_light_item;
+		//InstanceBase *baked_light; //baked light to use
+		//SelfList<InstanceBase> baked_light_item;
 
 		virtual void base_removed() = 0;
 		virtual void base_changed() = 0;
 		virtual void base_material_changed() = 0;
 
 		InstanceBase()
-			: dependency_item(this), baked_light_item(this) {
+			: dependency_item(this) {
 
 			base_type = VS::INSTANCE_NONE;
 			cast_shadows = VS::SHADOW_CASTING_SETTING_ON;
@@ -129,7 +130,7 @@ public:
 			visible = true;
 			depth_layer = 0;
 			layer_mask = 1;
-			baked_light = NULL;
+			baked_light = false;
 		}
 	};
 
@@ -422,6 +423,9 @@ public:
 	virtual void gi_probe_set_bias(RID p_probe, float p_range) = 0;
 	virtual float gi_probe_get_bias(RID p_probe) const = 0;
 
+	virtual void gi_probe_set_normal_bias(RID p_probe, float p_range) = 0;
+	virtual float gi_probe_get_normal_bias(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;
 
diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h
index 1573116c509..58481fc3f61 100644
--- a/servers/visual/visual_server_raster.h
+++ b/servers/visual/visual_server_raster.h
@@ -844,6 +844,9 @@ public:
 	BIND2(gi_probe_set_bias, RID, float)
 	BIND1RC(float, gi_probe_get_bias, RID)
 
+	BIND2(gi_probe_set_normal_bias, RID, float)
+	BIND1RC(float, gi_probe_get_normal_bias, RID)
+
 	BIND2(gi_probe_set_propagation, RID, float)
 	BIND1RC(float, gi_probe_get_propagation, RID)
 
diff --git a/servers/visual/visual_server_scene.cpp b/servers/visual/visual_server_scene.cpp
index 13d1c7faa98..97583dc8490 100644
--- a/servers/visual/visual_server_scene.cpp
+++ b/servers/visual/visual_server_scene.cpp
@@ -993,6 +993,11 @@ void VisualServerScene::instance_geometry_set_flag(RID p_instance, VS::InstanceF
 			instance->visible_in_all_rooms = p_enabled;
 
 		} break;
+		case VS::INSTANCE_FLAG_USE_BAKED_LIGHT: {
+
+			instance->baked_light = p_enabled;
+
+		} break;
 	}
 }
 void VisualServerScene::instance_geometry_set_cast_shadows_setting(RID p_instance, VS::ShadowCastingSetting p_shadow_casting_setting) {
diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h
index 6a1b0f7e46a..4567d877069 100644
--- a/servers/visual/visual_server_wrap_mt.h
+++ b/servers/visual/visual_server_wrap_mt.h
@@ -288,6 +288,9 @@ public:
 	FUNC2(gi_probe_set_bias, RID, float)
 	FUNC1RC(float, gi_probe_get_bias, RID)
 
+	FUNC2(gi_probe_set_normal_bias, RID, float)
+	FUNC1RC(float, gi_probe_get_normal_bias, RID)
+
 	FUNC2(gi_probe_set_propagation, RID, float)
 	FUNC1RC(float, gi_probe_get_propagation, RID)
 
diff --git a/servers/visual_server.h b/servers/visual_server.h
index fbd7fc16ac1..f515a7b9903 100644
--- a/servers/visual_server.h
+++ b/servers/visual_server.h
@@ -463,6 +463,9 @@ public:
 	virtual void gi_probe_set_bias(RID p_probe, float p_range) = 0;
 	virtual float gi_probe_get_bias(RID p_probe) const = 0;
 
+	virtual void gi_probe_set_normal_bias(RID p_probe, float p_range) = 0;
+	virtual float gi_probe_get_normal_bias(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;