diff options
-rw-r--r-- | drivers/gles2/rasterizer_gles2.cpp | 11 | ||||
-rw-r--r-- | drivers/gles2/shaders/material.glsl | 10 | ||||
-rw-r--r-- | scene/resources/baked_light.cpp | 46 | ||||
-rw-r--r-- | scene/resources/baked_light.h | 9 | ||||
-rw-r--r-- | servers/visual/rasterizer.h | 4 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.cpp | 60 | ||||
-rw-r--r-- | servers/visual/visual_server_raster.h | 9 | ||||
-rw-r--r-- | servers/visual/visual_server_wrap_mt.h | 8 | ||||
-rw-r--r-- | servers/visual_server.h | 9 |
9 files changed, 165 insertions, 1 deletions
diff --git a/drivers/gles2/rasterizer_gles2.cpp b/drivers/gles2/rasterizer_gles2.cpp index e43487d719..f9b58939dc 100644 --- a/drivers/gles2/rasterizer_gles2.cpp +++ b/drivers/gles2/rasterizer_gles2.cpp @@ -6561,8 +6561,19 @@ void RasterizerGLES2::_render_list_forward(RenderList *p_render_list,const Trans material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_LIGHTMAP,false); material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER,false); + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_COLOR, false); + + if (material->flags[VS::MATERIAL_FLAG_UNSHADED] == false && current_debug != VS::SCENARIO_DEBUG_SHADELESS) { + if (baked_light != NULL) { + if (baked_light->realtime_color_enabled) { + float realtime_energy = baked_light->realtime_energy; + material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_COLOR, true); + material_shader.set_uniform(MaterialShaderGLES2::AMBIENT_COLOR, Vector3(baked_light->realtime_color.r*realtime_energy, baked_light->realtime_color.g*realtime_energy, baked_light->realtime_color.b*realtime_energy)); + } + } + if (e->instance->sampled_light.is_valid()) { SampledLight *sl = sampled_light_owner.get(e->instance->sampled_light); diff --git a/drivers/gles2/shaders/material.glsl b/drivers/gles2/shaders/material.glsl index ccd80bf2f0..e68949b056 100644 --- a/drivers/gles2/shaders/material.glsl +++ b/drivers/gles2/shaders/material.glsl @@ -618,6 +618,12 @@ uniform float ambient_dp_sampler_multiplier; #endif +#ifdef ENABLE_AMBIENT_COLOR + +uniform vec3 ambient_color; + +#endif + FRAGMENT_SHADER_GLOBALS @@ -1262,7 +1268,9 @@ LIGHT_SHADER_CODE #if defined(ENABLE_AMBIENT_OCTREE) || defined(ENABLE_AMBIENT_LIGHTMAP) || defined(ENABLE_AMBIENT_DP_SAMPLER) - +#if defined(ENABLE_AMBIENT_COLOR) + ambientmap_color*=ambient_color; +#endif diffuse.rgb+=ambientmap_color; #endif diff --git a/scene/resources/baked_light.cpp b/scene/resources/baked_light.cpp index 31282a0274..aa4aae03cb 100644 --- a/scene/resources/baked_light.cpp +++ b/scene/resources/baked_light.cpp @@ -256,6 +256,38 @@ float BakedLight::get_ao_strength() const { return ao_strength; } +void BakedLight::set_realtime_color_enabled(const bool p_realtime_color_enabled) { + + VS::get_singleton()->baked_light_set_realtime_color_enabled(baked_light, p_realtime_color_enabled); +} + +bool BakedLight::get_realtime_color_enabled() const { + + return VS::get_singleton()->baked_light_get_realtime_color_enabled(baked_light); +} + + +void BakedLight::set_realtime_color(const Color &p_realtime_color) { + + VS::get_singleton()->baked_light_set_realtime_color(baked_light, p_realtime_color); +} + +Color BakedLight::get_realtime_color() const { + + return VS::get_singleton()->baked_light_get_realtime_color(baked_light); +} + +void BakedLight::set_realtime_energy(const float p_realtime_energy) { + + VS::get_singleton()->baked_light_set_realtime_energy(baked_light, p_realtime_energy); +} + +float BakedLight::get_realtime_energy() const { + + return VS::get_singleton()->baked_light_get_realtime_energy(baked_light); +} + + void BakedLight::set_energy_multiplier(float p_multiplier){ @@ -434,6 +466,15 @@ void BakedLight::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_ao_strength","ao_strength"),&BakedLight::set_ao_strength); ObjectTypeDB::bind_method(_MD("get_ao_strength"),&BakedLight::get_ao_strength); + ObjectTypeDB::bind_method(_MD("set_realtime_color_enabled", "enabled"), &BakedLight::set_realtime_color_enabled); + ObjectTypeDB::bind_method(_MD("get_realtime_color_enabled"), &BakedLight::get_realtime_color_enabled); + + ObjectTypeDB::bind_method(_MD("set_realtime_color", "tint"), &BakedLight::set_realtime_color); + ObjectTypeDB::bind_method(_MD("get_realtime_color"), &BakedLight::get_realtime_color); + + ObjectTypeDB::bind_method(_MD("set_realtime_energy", "energy"), &BakedLight::set_realtime_energy); + ObjectTypeDB::bind_method(_MD("get_realtime_energy"), &BakedLight::get_realtime_energy); + ObjectTypeDB::bind_method(_MD("set_format","format"),&BakedLight::set_format); ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_format); @@ -480,6 +521,11 @@ void BakedLight::_bind_methods(){ ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/ao_radius",PROPERTY_HINT_RANGE,"0.0,16.0,0.01"),_SCS("set_ao_radius"),_SCS("get_ao_radius")); ADD_PROPERTY( PropertyInfo(Variant::REAL,"advanced/ao_strength",PROPERTY_HINT_RANGE,"0.0,1.0,0.01"),_SCS("set_ao_strength"),_SCS("get_ao_strength")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "realtime/enabled"), _SCS("set_realtime_color_enabled"), _SCS("get_realtime_color_enabled")); + ADD_PROPERTY(PropertyInfo(Variant::COLOR, "realtime/color", PROPERTY_HINT_COLOR_NO_ALPHA), _SCS("set_realtime_color"), _SCS("get_realtime_color")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "realtime/energy", PROPERTY_HINT_RANGE, "0.01,4096.0,0.01"), _SCS("set_realtime_energy"), _SCS("get_realtime_energy")); + + BIND_CONSTANT( MODE_OCTREE ); BIND_CONSTANT( MODE_LIGHTMAPS ); diff --git a/scene/resources/baked_light.h b/scene/resources/baked_light.h index 41e1e5f9e0..f9a1368e8d 100644 --- a/scene/resources/baked_light.h +++ b/scene/resources/baked_light.h @@ -116,6 +116,15 @@ public: void set_ao_strength(float p_ao_strength); float get_ao_strength() const; + void set_realtime_color_enabled(const bool p_enabled); + bool get_realtime_color_enabled() const; + + void set_realtime_color(const Color& p_realtime_color); + Color get_realtime_color() const; + + void set_realtime_energy(const float p_realtime_energy); + float get_realtime_energy() const; + void set_bake_flag(BakeFlags p_flags,bool p_enable); bool get_bake_flag(BakeFlags p_flags) const; diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 194df9596a..e2de20785a 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -528,6 +528,10 @@ public: int octree_steps; Vector2 octree_tex_pixel_size; Vector2 light_tex_pixel_size; + + bool realtime_color_enabled; + Color realtime_color; + float realtime_energy; }; struct InstanceData { diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 6d293f0ce8..1db7971d3b 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -1081,6 +1081,9 @@ RID VisualServerRaster::baked_light_create() { baked_light->data.octree_lattice_divide=0; baked_light->data.octree_steps=1; baked_light->data.lightmap_multiplier=1.0; + baked_light->data.realtime_color_enabled=false; + baked_light->data.realtime_color=Color(1.0, 1.0, 1.0); + baked_light->data.realtime_energy = 1.0; return baked_light_owner.make_rid( baked_light ); @@ -1326,6 +1329,63 @@ void VisualServerRaster::baked_light_clear_lightmaps(RID p_baked_light){ } +void VisualServerRaster::baked_light_set_realtime_color_enabled(RID p_baked_light, const bool p_enabled) { + + VS_CHANGED; + BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND(!baked_light); + + baked_light->data.realtime_color_enabled = p_enabled; + +} + +bool VisualServerRaster::baked_light_get_realtime_color_enabled(RID p_baked_light) const{ + + const BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND_V(!baked_light, false); + + return baked_light->data.realtime_color_enabled; + +} + +void VisualServerRaster::baked_light_set_realtime_color(RID p_baked_light, const Color& p_color) { + + VS_CHANGED; + BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND(!baked_light); + + baked_light->data.realtime_color = p_color; + +} + +Color VisualServerRaster::baked_light_get_realtime_color(RID p_baked_light) const{ + + const BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND_V(!baked_light, Color(1.0, 1.0, 1.0)); + + return baked_light->data.realtime_color; + +} + +void VisualServerRaster::baked_light_set_realtime_energy(RID p_baked_light, const float p_energy) { + + VS_CHANGED; + BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND(!baked_light); + + baked_light->data.realtime_energy = p_energy; + +} + +float VisualServerRaster::baked_light_get_realtime_energy(RID p_baked_light) const{ + + const BakedLight *baked_light = baked_light_owner.get(p_baked_light); + ERR_FAIL_COND_V(!baked_light, 1.0f); + + return baked_light->data.realtime_energy; + +} + /* BAKED LIGHT SAMPLER */ diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index 06501d1b81..2b72b0b900 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -949,6 +949,15 @@ public: virtual void baked_light_add_lightmap(RID p_baked_light,const RID p_texture,int p_id); virtual void baked_light_clear_lightmaps(RID p_baked_light); + virtual void baked_light_set_realtime_color_enabled(RID p_baked_light, const bool p_enabled); + virtual bool baked_light_get_realtime_color_enabled(RID p_baked_light) const; + + virtual void baked_light_set_realtime_color(RID p_baked_light, const Color& p_color); + virtual Color baked_light_get_realtime_color(RID p_baked_light) const; + + virtual void baked_light_set_realtime_energy(RID p_baked_light, const float p_energy); + virtual float baked_light_get_realtime_energy(RID p_baked_light) const; + /* BAKED LIGHT SAMPLER */ virtual RID baked_light_sampler_create(); diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index 52e38c8438..b6018f1c25 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -391,6 +391,14 @@ public: FUNC3(baked_light_add_lightmap,RID,RID,int); FUNC1(baked_light_clear_lightmaps,RID); + FUNC2(baked_light_set_realtime_color_enabled, RID, const bool); + FUNC1RC(bool, baked_light_get_realtime_color_enabled, RID); + + FUNC2(baked_light_set_realtime_color, RID, const Color&); + FUNC1RC(Color, baked_light_get_realtime_color, RID); + + FUNC2(baked_light_set_realtime_energy, RID, const float); + FUNC1RC(float, baked_light_get_realtime_energy, RID); FUNC0R(RID,baked_light_sampler_create); diff --git a/servers/visual_server.h b/servers/visual_server.h index 3a5b3d8d37..c70a72ef2a 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -626,6 +626,15 @@ public: virtual void baked_light_add_lightmap(RID p_baked_light,const RID p_texture,int p_id)=0; virtual void baked_light_clear_lightmaps(RID p_baked_light)=0; + virtual void baked_light_set_realtime_color_enabled(RID p_baked_light, const bool p_enabled)=0; + virtual bool baked_light_get_realtime_color_enabled(RID p_baked_light) const=0; + + virtual void baked_light_set_realtime_color(RID p_baked_light, const Color& p_color)=0; + virtual Color baked_light_get_realtime_color(RID p_baked_light) const=0; + + virtual void baked_light_set_realtime_energy(RID p_baked_light, const float p_energy) = 0; + virtual float baked_light_get_realtime_energy(RID p_baked_light) const = 0; + /* BAKED LIGHT SAMPLER */ virtual RID baked_light_sampler_create()=0; |