Ability to colourize baked lighting in real time.

This commit is contained in:
Saracen 2016-01-31 12:56:53 +00:00
parent 987bfb4b5e
commit de5281c398
9 changed files with 165 additions and 1 deletions

View File

@ -6545,8 +6545,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_LIGHTMAP,false);
material_shader.set_conditional(MaterialShaderGLES2::ENABLE_AMBIENT_DP_SAMPLER,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 (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()) { if (e->instance->sampled_light.is_valid()) {
SampledLight *sl = sampled_light_owner.get(e->instance->sampled_light); SampledLight *sl = sampled_light_owner.get(e->instance->sampled_light);

View File

@ -618,6 +618,12 @@ uniform float ambient_dp_sampler_multiplier;
#endif #endif
#ifdef ENABLE_AMBIENT_COLOR
uniform vec3 ambient_color;
#endif
FRAGMENT_SHADER_GLOBALS 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_OCTREE) || defined(ENABLE_AMBIENT_LIGHTMAP) || defined(ENABLE_AMBIENT_DP_SAMPLER)
#if defined(ENABLE_AMBIENT_COLOR)
ambientmap_color*=ambient_color;
#endif
diffuse.rgb+=ambientmap_color; diffuse.rgb+=ambientmap_color;
#endif #endif

View File

@ -256,6 +256,38 @@ float BakedLight::get_ao_strength() const {
return ao_strength; 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){ 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("set_ao_strength","ao_strength"),&BakedLight::set_ao_strength);
ObjectTypeDB::bind_method(_MD("get_ao_strength"),&BakedLight::get_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("set_format","format"),&BakedLight::set_format);
ObjectTypeDB::bind_method(_MD("get_format"),&BakedLight::get_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_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::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_OCTREE );
BIND_CONSTANT( MODE_LIGHTMAPS ); BIND_CONSTANT( MODE_LIGHTMAPS );

View File

@ -116,6 +116,15 @@ public:
void set_ao_strength(float p_ao_strength); void set_ao_strength(float p_ao_strength);
float get_ao_strength() const; 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); void set_bake_flag(BakeFlags p_flags,bool p_enable);
bool get_bake_flag(BakeFlags p_flags) const; bool get_bake_flag(BakeFlags p_flags) const;

View File

@ -528,6 +528,10 @@ public:
int octree_steps; int octree_steps;
Vector2 octree_tex_pixel_size; Vector2 octree_tex_pixel_size;
Vector2 light_tex_pixel_size; Vector2 light_tex_pixel_size;
bool realtime_color_enabled;
Color realtime_color;
float realtime_energy;
}; };
struct InstanceData { struct InstanceData {

View File

@ -1081,6 +1081,9 @@ RID VisualServerRaster::baked_light_create() {
baked_light->data.octree_lattice_divide=0; baked_light->data.octree_lattice_divide=0;
baked_light->data.octree_steps=1; baked_light->data.octree_steps=1;
baked_light->data.lightmap_multiplier=1.0; 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 ); 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 */ /* BAKED LIGHT SAMPLER */

View File

@ -951,6 +951,15 @@ public:
virtual void baked_light_add_lightmap(RID p_baked_light,const RID p_texture,int p_id); 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_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 */ /* BAKED LIGHT SAMPLER */
virtual RID baked_light_sampler_create(); virtual RID baked_light_sampler_create();

View File

@ -391,6 +391,14 @@ public:
FUNC3(baked_light_add_lightmap,RID,RID,int); FUNC3(baked_light_add_lightmap,RID,RID,int);
FUNC1(baked_light_clear_lightmaps,RID); 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); FUNC0R(RID,baked_light_sampler_create);

View File

@ -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_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_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 */ /* BAKED LIGHT SAMPLER */
virtual RID baked_light_sampler_create()=0; virtual RID baked_light_sampler_create()=0;