Commit a9cfdbe6 authored by frankie's avatar frankie 💬

option to modify influence of modifiers depending on particle's lifetime

parent c4de2d1c
......@@ -100,6 +100,9 @@ void FutariAttractor::refresh() {
_data.changed_strength_decay =
_data.strength_decay != strength_decay_texture ||
_data.strength_decay.is_valid() != strength_decay_texture.is_valid();
_data.changed_lifetime =
_data.lifetime != lifetime_texture ||
_data.lifetime.is_valid() != lifetime_texture.is_valid();
_data.changed_range = _data.range != range;
_data.changed_velocity_mult = _data.velocity_mult != velocity_mult;
_data.changed_position_mult = _data.position_mult != position_mult;
......@@ -110,6 +113,7 @@ void FutariAttractor::refresh() {
_data.changed_orientation ||
_data.changed_strength ||
_data.changed_strength_decay ||
_data.changed_lifetime ||
_data.changed_range ||
_data.changed_velocity_mult ||
_data.changed_position_mult;
......@@ -120,6 +124,7 @@ void FutariAttractor::refresh() {
_data.orientation = o;
_data.strength = s;
_data.strength_decay = strength_decay_texture;
_data.lifetime = lifetime_texture;
_data.range = range;
_data.velocity_mult = velocity_mult;
_data.position_mult = position_mult;
......@@ -135,6 +140,7 @@ void FutariAttractor::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range", PROPERTY_HINT_RANGE, prop), "set_range", "get_range");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "-500,500,or_greater,or_lesser"), "set_strength", "get_strength");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "strength_decay_texture", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_strength_decay_texture", "get_strength_decay_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "lifetime_texture", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_lifetime_texture", "get_lifetime_texture");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "velocity_mult", PROPERTY_HINT_RANGE, "0,1"), "set_velocity_mult", "get_velocity_mult");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "position_mult", PROPERTY_HINT_RANGE, "0,1"), "set_position_mult", "get_position_mult");
......
......@@ -102,6 +102,14 @@ Ref<GradientTexture> FutariModifier::get_strength_decay_texture() const {
return strength_decay_texture;
}
void FutariModifier::set_lifetime_texture(const Ref<GradientTexture> &tex) {
lifetime_texture = tex;
}
Ref<GradientTexture> FutariModifier::get_lifetime_texture() const {
return lifetime_texture;
}
void FutariModifier::set_velocity_mult(real_t r) {
if ( r < 0 ) {
r = 0;
......@@ -217,6 +225,9 @@ void FutariModifier::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_strength_decay_texture", "strength_decay"), &FutariModifier::set_strength_decay_texture);
ClassDB::bind_method(D_METHOD("get_strength_decay_texture"), &FutariModifier::get_strength_decay_texture);
ClassDB::bind_method(D_METHOD("set_lifetime_texture", "lifetime"), &FutariModifier::set_lifetime_texture);
ClassDB::bind_method(D_METHOD("get_lifetime_texture"), &FutariModifier::get_lifetime_texture);
ClassDB::bind_method(D_METHOD("set_velocity_mult", "velocity_mult"), &FutariModifier::set_velocity_mult);
ClassDB::bind_method(D_METHOD("get_velocity_mult"), &FutariModifier::get_velocity_mult);
......
......@@ -95,6 +95,7 @@ public:
// textures
Ref<GradientTexture> strength_decay;
Ref<GradientTexture> lifetime;
bool changed;
bool changed_enabled;
......@@ -102,6 +103,7 @@ public:
bool changed_orientation;
bool changed_strength;
bool changed_strength_decay;
bool changed_lifetime;
bool changed_range;
bool changed_velocity_mult;
bool changed_position_mult;
......@@ -119,6 +121,7 @@ public:
changed_orientation( false ),
changed_strength( false ),
changed_strength_decay( false ),
changed_lifetime( false ),
changed_range( false ),
changed_velocity_mult( false ),
changed_position_mult( false ) {
......@@ -133,6 +136,7 @@ public:
changed_orientation = false;
changed_strength = false;
changed_strength_decay = false;
changed_lifetime = false;
changed_range = false;
changed_velocity_mult = false;
changed_position_mult = false;
......@@ -151,6 +155,7 @@ public:
position_mult = src.position_mult;
strength_decay = src.strength_decay;
lifetime = src.lifetime;
changed = src.changed;
changed_enabled = src.changed_enabled;
......@@ -158,6 +163,7 @@ public:
changed_orientation = src.changed_orientation;
changed_strength = src.changed_strength;
changed_strength_decay = src.changed_strength_decay;
changed_lifetime = src.changed_lifetime;
changed_range = src.changed_range;
changed_velocity_mult = src.changed_velocity_mult;
......@@ -190,6 +196,9 @@ public:
void set_strength_decay_texture( const Ref<GradientTexture> &tex );
Ref<GradientTexture> get_strength_decay_texture( ) const;
void set_lifetime_texture( const Ref<GradientTexture> &tex );
Ref<GradientTexture> get_lifetime_texture( ) const;
void set_velocity_mult( real_t r );
real_t get_velocity_mult( ) const;
......@@ -215,6 +224,7 @@ protected:
real_t position_mult;
Ref<GradientTexture> strength_decay_texture;
Ref<GradientTexture> lifetime_texture;
};
......
......@@ -180,7 +180,11 @@ void FutariParticles::_internal_process() {
if (fmd->changed) {
_params_refresh = true;
}
if (fmd->changed_strength_decay || fmd->changed_enabled) {
if (
fmd->changed_strength_decay ||
fmd->changed_lifetime ||
fmd->changed_enabled
) {
_procmat_refresh = true;
}
if (!fmd->enabled) {
......@@ -302,14 +306,19 @@ void FutariParticles::_internal_process() {
if (fmd->strength_decay.is_valid()) {
apart.ss_declaration << "uniform sampler2D attractor_strength_decay_" << id << " : hint_white;\n";
}
if (fmd->lifetime.is_valid()) {
apart.ss_declaration << "uniform sampler2D attractor_lifetime_" << id << " : hint_white;\n";
}
apart.ss_vertex_normal << "fut_v3 = attractor_position_" << id << " - pos;\n";
apart.ss_vertex_normal << "fut_d = 1.0 - min( 1.0, (fut_v3.x*fut_v3.x + fut_v3.y*fut_v3.y + fut_v3.z*fut_v3.z) / attractor_range_" << id << " );\n";
if (fmd->strength_decay.is_valid()) {
apart.ss_vertex_normal << "fut_d = textureLod(attractor_strength_decay_" << id << ", vec2( fut_d, 0.0 ), 0.0).x;\n";
apart.ss_vertex_normal << "fut_d = textureLod(attractor_strength_decay_" << id << ", vec2( fut_d, 0.0 ), 0.0).r;\n";
}
apart.ss_vertex_normal << "fut_v3 = normalize( fut_v3 ) * attractor_strength_" << id << " * fut_d;\n";
if (fmd->lifetime.is_valid()) {
apart.ss_vertex_normal << "fut_v3 = fut_v3 * textureLod(attractor_lifetime_" << id << ", vec2( CUSTOM.y, 0.0 ), 0.0).r;\n";
}
apart.ss_vertex_normal << "futari_force += fut_v3 * attractor_vmult_" << id << ";\n";
apart.ss_vertex_normal << "futari_push += fut_v3 * attractor_pmult_" << id << ";\n";
......@@ -331,14 +340,19 @@ void FutariParticles::_internal_process() {
if (fmd->strength_decay.is_valid()) {
wpart.ss_declaration << "uniform sampler2D wind_strength_decay_" << id << " : hint_white;\n";
}
if (fmd->lifetime.is_valid()) {
wpart.ss_declaration << "uniform sampler2D wind_lifetime_" << id << " : hint_white;\n";
}
wpart.ss_vertex_normal << "fut_v3 = pos - wind_position_" << id << ";\n";
wpart.ss_vertex_normal << "fut_d = 1.0 - min( 1.0, (fut_v3.x*fut_v3.x + fut_v3.y*fut_v3.y + fut_v3.z*fut_v3.z) / wind_range_" << id << " );\n";
if (fmd->strength_decay.is_valid()) {
wpart.ss_vertex_normal << "fut_d = textureLod(wind_strength_decay_" << id << ", vec2( fut_d, 0.0 ), 0.0).x;\n";
wpart.ss_vertex_normal << "fut_d = textureLod(wind_strength_decay_" << id << ", vec2( fut_d, 0.0 ), 0.0).r;\n";
}
wpart.ss_vertex_normal << "fut_v3 = wind_orientation_" << id << " * wind_strength_" << id << " * fut_d;\n";
if (fmd->lifetime.is_valid()) {
wpart.ss_vertex_normal << "fut_v3 = fut_v3 * textureLod(wind_lifetime_" << id << ", vec2( CUSTOM.y, 0.0 ), 0.0).r;\n";
}
wpart.ss_vertex_normal << "futari_force += fut_v3 * wind_vmult_" << id << ";\n";
wpart.ss_vertex_normal << "futari_push += fut_v3 * wind_pmult_" << id << ";\n";
......@@ -372,10 +386,12 @@ void FutariParticles::_internal_process() {
}
}
if (fvd->height_tex.is_valid()) {
vpart.ss_declaration << "uniform sampler2D vortex_gradient_height_" << id << " : hint_white;\n";
}
if (fvd->lifetime.is_valid()) {
vpart.ss_declaration << "uniform sampler2D vortex_lifetime_" << id << " : hint_white;\n";
}
// vortex is a cylinder, therefore we need to compute 2 ratio:
// - position on height, between -1 & 1
......@@ -444,6 +460,10 @@ void FutariParticles::_internal_process() {
}
if (fvd->lifetime.is_valid()) {
vpart.ss_vertex_normal << "fut_v3_total = fut_v3_total * textureLod(vortex_lifetime_" << id << ", vec2( CUSTOM.y, 0.0 ), 0.0).r;\n";
}
vpart.ss_vertex_normal << "futari_force += fut_v3_total * vortex_vmult_" << id << ";\n";
vpart.ss_vertex_normal << "futari_push += fut_v3_total * vortex_pmult_" << id << ";\n";
......@@ -503,6 +523,9 @@ void FutariParticles::_internal_process() {
if (fwd->strength_decay.is_valid()) {
procmat->set_futari_param_tex("wind_strength_decay_" + suffix, fwd->strength_decay);
}
if (fwd->lifetime.is_valid()) {
procmat->set_futari_param_tex("wind_lifetime_" + suffix, fwd->lifetime);
}
} else if (fwd->changed) {
......@@ -550,6 +573,9 @@ void FutariParticles::_internal_process() {
if (fad->strength_decay.is_valid()) {
procmat->set_futari_param_tex("attractor_strength_decay_" + suffix, fad->strength_decay);
}
if (fad->lifetime.is_valid()) {
procmat->set_futari_param_tex("attractor_lifetime_" + suffix, fad->lifetime);
}
} else if (fad->changed) {
......@@ -603,6 +629,9 @@ void FutariParticles::_internal_process() {
if (fvd->height_tex.is_valid()) {
procmat->set_futari_param_tex("vortex_gradient_height_" + suffix, fvd->height_tex);
}
if (fvd->lifetime.is_valid()) {
procmat->set_futari_param_tex("vortex_lifetime_" + suffix, fvd->lifetime);
}
} else if (fvd->changed) {
......
......@@ -142,6 +142,9 @@ void FutariVortex::refresh() {
FutariVortex::_data.changed_strength_decay =
FutariVortex::_data.strength_decay != strength_decay_texture ||
FutariVortex::_data.strength_decay.is_valid() != strength_decay_texture.is_valid();
FutariVortex::_data.changed_lifetime =
FutariVortex::_data.lifetime != lifetime_texture ||
FutariVortex::_data.lifetime.is_valid() != lifetime_texture.is_valid();
FutariVortex::_data.changed_range = FutariVortex::_data.range != range;
FutariVortex::_data.changed_height = FutariVortex::_data.height != height;
FutariVortex::_data.changed_velocity_mult = FutariVortex::_data.velocity_mult != velocity_mult;
......@@ -163,6 +166,7 @@ void FutariVortex::refresh() {
FutariVortex::_data.changed_orientation ||
FutariVortex::_data.changed_strength ||
FutariVortex::_data.changed_strength_decay ||
FutariVortex::_data.changed_lifetime ||
FutariVortex::_data.changed_range ||
FutariVortex::_data.changed_height ||
FutariVortex::_data.changed_top_tex ||
......@@ -178,6 +182,7 @@ void FutariVortex::refresh() {
FutariVortex::_data.orientation = o;
FutariVortex::_data.strength = s;
FutariVortex::_data.strength_decay = strength_decay_texture;
FutariVortex::_data.lifetime = lifetime_texture;
FutariVortex::_data.range = range;
FutariVortex::_data.height = height;
FutariVortex::_data.top_tex = top_texture;
......@@ -219,6 +224,7 @@ void FutariVortex::_bind_methods() {
prop = String::num_real(FUTARI_VORTEX_MINHEIGHT) + ",100,0.01,or_greater";
ADD_PROPERTY(PropertyInfo(Variant::REAL, "height", PROPERTY_HINT_RANGE, prop), "set_height", "get_height");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "-100,100,0.01,or_greater"), "set_strength", "get_strength");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "lifetime_texture", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_lifetime_texture", "get_lifetime_texture");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "velocity_mult", PROPERTY_HINT_RANGE, "0,1"), "set_velocity_mult", "get_velocity_mult");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "position_mult", PROPERTY_HINT_RANGE, "0,1"), "set_position_mult", "get_position_mult");
......
......@@ -94,6 +94,9 @@ void FutariWind::refresh() {
FutariWind::_data.changed_strength_decay =
FutariWind::_data.strength_decay != strength_decay_texture ||
FutariWind::_data.strength_decay.is_valid() != strength_decay_texture.is_valid();
FutariWind::_data.changed_lifetime =
FutariWind::_data.lifetime != lifetime_texture ||
FutariWind::_data.lifetime.is_valid() != lifetime_texture.is_valid();
FutariWind::_data.changed_range = FutariWind::_data.range != range;
FutariWind::_data.changed_velocity_mult = FutariWind::_data.velocity_mult != velocity_mult;
FutariWind::_data.changed_position_mult = FutariWind::_data.position_mult != position_mult;
......@@ -104,6 +107,7 @@ void FutariWind::refresh() {
FutariWind::_data.changed_orientation ||
FutariWind::_data.changed_strength ||
FutariWind::_data.changed_strength_decay ||
FutariWind::_data.changed_lifetime ||
FutariWind::_data.changed_range ||
FutariWind::_data.changed_velocity_mult ||
FutariWind::_data.changed_position_mult;
......@@ -114,6 +118,7 @@ void FutariWind::refresh() {
FutariWind::_data.orientation = o;
FutariWind::_data.strength = s;
FutariWind::_data.strength_decay = strength_decay_texture;
FutariWind::_data.lifetime = lifetime_texture;
FutariWind::_data.range = range;
FutariWind::_data.velocity_mult = velocity_mult;
FutariWind::_data.position_mult = position_mult;
......@@ -133,6 +138,7 @@ void FutariWind::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::REAL, "range", PROPERTY_HINT_RANGE, prop), "set_range", "get_range");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "strength", PROPERTY_HINT_RANGE, "0,100,0.01,or_greater"), "set_strength", "get_strength");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "strength_decay_texture", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_strength_decay_texture", "get_strength_decay_texture");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "lifetime_texture", PROPERTY_HINT_RESOURCE_TYPE, "GradientTexture"), "set_lifetime_texture", "get_lifetime_texture");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "velocity_mult", PROPERTY_HINT_RANGE, "0,1"), "set_velocity_mult", "get_velocity_mult");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "position_mult", PROPERTY_HINT_RANGE, "0,1"), "set_position_mult", "get_position_mult");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment