Commit c4de2d1c authored by frankie's avatar frankie 💬

logical error fix in shader + XYZ angle multipliers

parent 92a97e1d
......@@ -79,6 +79,10 @@ void FutariMaterial::init_shaders() {
shader_names->scale = "scale";
shader_names->anim_speed = "anim_speed";
shader_names->anim_offset = "anim_offset";
shader_names->angle_x_mult = "angle_x_mult";
shader_names->angle_y_mult = "angle_y_mult";
shader_names->angle_z_mult = "angle_z_mult";
shader_names->initial_linear_velocity_random = "initial_linear_velocity_random";
shader_names->initial_angle_random = "initial_angle_random";
......@@ -153,6 +157,13 @@ void FutariMaterial::_update_shader() {
code += "uniform float flatness;\n";
code += "uniform float initial_linear_velocity;\n";
code += "uniform float initial_angle;\n";
if ( flags[FUFLA_ROTATE_X] || flags[FUFLA_ROTATE_Z] ) {
code += "uniform float angle_x_mult;\n"
"uniform float angle_y_mult;\n"
"uniform float angle_z_mult;\n";
}
code += "uniform float angular_velocity;\n";
code += "uniform float orbit_velocity;\n";
code += "uniform float linear_accel;\n";
......@@ -561,10 +572,10 @@ void FutariMaterial::_update_shader() {
code += "\n";
// turn particle by rotation in Y
if (flags[FUFLA_ROTATE_Y] && (flags[FUFLA_ROTATE_X] || flags[FUFLA_ROTATE_Z])) {
if (flags[FUFLA_ROTATE_X] || flags[FUFLA_ROTATE_Z]) {
if (flags[FUFLA_ROTATE_X]) {
code += "float rrx = CUSTOM.x; "
code += "float rrx = CUSTOM.x * angle_x_mult; "
"float rrcx = cos(rrx); "
"float rrsx = sin(rrx);\n"
"mat4 rmx = mat4( vec4( 1.0,0.0,0.0,0.0 ), vec4( 0.0,rrcx,rrsx,0.0 ), vec4( 0.0,-rrsx,rrcx,0.0 ), vec4( 0.0,0.0,0.0,1.0 ) );\n";
......@@ -572,7 +583,7 @@ void FutariMaterial::_update_shader() {
code += "mat4 rmx = mat4( vec4( 1.0,0.0,0.0,0.0 ), vec4( 0.0,1.0,0.0,0.0 ), vec4( 0.0,0.0,1.0,0.0 ), vec4( 0.0,0.0,0.0,1.0 ) );\n";
}
if (flags[FUFLA_ROTATE_Y]) {
code += "float rry = CUSTOM.x; "
code += "float rry = CUSTOM.x * angle_y_mult; "
"float rrcy = cos(rry); "
"float rrsy= sin(rry);\n"
"mat4 rmy = mat4( vec4( rrcy,0.0,-rrsy,0.0 ), vec4( 0.0,1.0,0.0,0.0 ), vec4( rrsy,0.0,rrcy,0.0 ), vec4( 0.0,0.0,0.0,1.0 ) );\n";
......@@ -580,7 +591,7 @@ void FutariMaterial::_update_shader() {
code += "mat4 rmy = mat4( vec4( 1.0,0.0,0.0,0.0 ), vec4( 0.0,1.0,0.0,0.0 ), vec4( 0.0,0.0,1.0,0.0 ), vec4( 0.0,0.0,0.0,1.0 ) );\n";
}
if (flags[FUFLA_ROTATE_Z]) {
code += "float rrz = CUSTOM.x; "
code += "float rrz = CUSTOM.x * angle_z_mult; "
"float rrcz = cos(rrz); "
"float rrsz= sin(rrz);\n"
"mat4 rmz = mat4( vec4( rrcz,rrsz,0.0,0.0 ), vec4( -rrsz,rrcz,0.0,0.0 ), vec4( 0.0,0.0,1.0,0.0 ), vec4( 0.0,0.0,0.0,1.0 ) );\n";
......@@ -980,6 +991,33 @@ float FutariMaterial::get_scale() const {
return scale;
}
void FutariMaterial::set_angle_x_mult(const float &p_angle_x_mult) {
angle_x_mult = p_angle_x_mult;
VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_x_mult, angle_x_mult);
}
float FutariMaterial::get_angle_x_mult() const {
return angle_x_mult;
}
void FutariMaterial::set_angle_y_mult(const float &p_angle_y_mult) {
angle_y_mult = p_angle_y_mult;
VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_y_mult, angle_y_mult);
}
float FutariMaterial::get_angle_y_mult() const {
return angle_y_mult;
}
void FutariMaterial::set_angle_z_mult(const float &p_angle_z_mult) {
angle_z_mult = p_angle_z_mult;
VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->angle_z_mult, angle_z_mult);
}
float FutariMaterial::get_angle_z_mult() const {
return angle_z_mult;
}
void FutariMaterial::set_scale_random(const float &p_scale_random) {
scale_random = p_scale_random;
VisualServer::get_singleton()->material_set_param(_get_material(), shader_names->scale_random, scale_random);
......@@ -1009,7 +1047,10 @@ void FutariMaterial::set_flag(FFlags p_flag, bool p_enable) {
p_flag == FUFLA_DISABLE_Z ||
p_flag == FUFLA_ENABLE_WIND ||
p_flag == FUFLA_ENABLE_ATTRACTOR ||
p_flag == FUFLA_ENABLE_VORTEX
p_flag == FUFLA_ENABLE_VORTEX ||
p_flag == FUFLA_ROTATE_X ||
p_flag == FUFLA_ROTATE_Y ||
p_flag == FUFLA_ROTATE_Z
) {
_change_notify();
}
......@@ -1317,6 +1358,16 @@ void FutariMaterial::_validate_property(PropertyInfo &property) const {
property.usage = 0;
}
if (property.name == "angle_x_mult" && ( !flags[FUFLA_ROTATE_X] && !flags[FUFLA_ROTATE_Z] )) {
property.usage = 0;
}
if (property.name == "angle_y_mult" && ( !flags[FUFLA_ROTATE_X] && !flags[FUFLA_ROTATE_Z] )) {
property.usage = 0;
}
if (property.name == "angle_z_mult" && ( !flags[FUFLA_ROTATE_X] && !flags[FUFLA_ROTATE_Z] )) {
property.usage = 0;
}
}
Shader::Mode FutariMaterial::get_shader_mode() const {
......@@ -1356,6 +1407,13 @@ void FutariMaterial::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_scale_gradient", "scale_gradient"), &FutariMaterial::set_scale_gradient);
ClassDB::bind_method(D_METHOD("get_scale_gradient"), &FutariMaterial::get_scale_gradient);
ClassDB::bind_method(D_METHOD("set_angle_x_mult", "angle_x_mult"), &FutariMaterial::set_angle_x_mult);
ClassDB::bind_method(D_METHOD("get_angle_x_mult"), &FutariMaterial::get_angle_x_mult);
ClassDB::bind_method(D_METHOD("set_angle_y_mult", "angle_y_mult"), &FutariMaterial::set_angle_y_mult);
ClassDB::bind_method(D_METHOD("get_angle_y_mult"), &FutariMaterial::get_angle_y_mult);
ClassDB::bind_method(D_METHOD("set_angle_z_mult", "angle_z_mult"), &FutariMaterial::set_angle_z_mult);
ClassDB::bind_method(D_METHOD("get_angle_z_mult"), &FutariMaterial::get_angle_z_mult);
ClassDB::bind_method(D_METHOD("set_flag", "flag", "enable"), &FutariMaterial::set_flag);
ClassDB::bind_method(D_METHOD("get_flag", "flag"), &FutariMaterial::get_flag);
......@@ -1471,7 +1529,10 @@ void FutariMaterial::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angle", PROPERTY_HINT_RANGE, "-720,720,0.1,or_lesser,or_greater"), "set_param", "get_param", FUPA_ANGLE);
ADD_PROPERTYI(PropertyInfo(Variant::REAL, "angle_random", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_param_randomness", "get_param_randomness", FUPA_ANGLE);
ADD_PROPERTYI(PropertyInfo(Variant::OBJECT, "angle_curve", PROPERTY_HINT_RESOURCE_TYPE, "CurveTexture"), "set_param_texture", "get_param_texture", FUPA_ANGLE);
ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle_x_mult", PROPERTY_HINT_RANGE, "-1,1,0.001,or_lesser,or_greater"), "set_angle_x_mult", "get_angle_x_mult");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle_y_mult", PROPERTY_HINT_RANGE, "-1,1,0.001,or_lesser,or_greater"), "set_angle_y_mult", "get_angle_y_mult");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "angle_z_mult", PROPERTY_HINT_RANGE, "-1,1,0.001,or_lesser,or_greater"), "set_angle_z_mult", "get_angle_z_mult");
ADD_GROUP("Scale", "");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale", PROPERTY_HINT_RANGE, "0,1000,0.01,or_greater,or_lesser"), "set_scale", "get_scale");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale_random", PROPERTY_HINT_RANGE, "0,1,0.01,or_greater,or_lesser"), "set_scale_random", "get_scale_random");
......@@ -1551,6 +1612,10 @@ dump_shader(false) {
set_scale(1);
set_scale_random(0);
set_angle_x_mult( 1 );
set_angle_y_mult( 1 );
set_angle_z_mult( 1 );
emission_point_count = 1;
......
......@@ -193,6 +193,10 @@ protected:
StringName scale;
StringName anim_speed;
StringName anim_offset;
StringName angle_x_mult;
StringName angle_y_mult;
StringName angle_z_mult;
StringName initial_linear_velocity_random;
StringName initial_angle_random;
......@@ -258,6 +262,10 @@ protected:
float scale;
float scale_random;
Ref<Texture> scale_gradient;
float angle_x_mult;
float angle_y_mult;
float angle_z_mult;
bool flags[FUFLA_MAX];
......@@ -322,6 +330,15 @@ public:
void set_scale( const float &p_scale );
float get_scale( ) const;
void set_angle_x_mult( const float &p_angle_x_mult );
float get_angle_x_mult( ) const;
void set_angle_y_mult( const float &p_angle_y_mult );
float get_angle_y_mult( ) const;
void set_angle_z_mult( const float &p_angle_z_mult );
float get_angle_z_mult( ) const;
void set_scale_random( const float &p_scale_random );
float get_scale_random( ) const;
......
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