summaryrefslogtreecommitdiff
path: root/scene/resources/particles_material.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/particles_material.cpp')
-rw-r--r--scene/resources/particles_material.cpp59
1 files changed, 0 insertions, 59 deletions
diff --git a/scene/resources/particles_material.cpp b/scene/resources/particles_material.cpp
index 1a28e2586d..e24cddd013 100644
--- a/scene/resources/particles_material.cpp
+++ b/scene/resources/particles_material.cpp
@@ -36,7 +36,6 @@ Map<ParticlesMaterial::MaterialKey, ParticlesMaterial::ShaderData> ParticlesMate
ParticlesMaterial::ShaderNames *ParticlesMaterial::shader_names = nullptr;
void ParticlesMaterial::init_shaders() {
-
dirty_materials = memnew(SelfList<ParticlesMaterial>::List);
shader_names = memnew(ShaderNames);
@@ -102,7 +101,6 @@ void ParticlesMaterial::init_shaders() {
}
void ParticlesMaterial::finish_shaders() {
-
memdelete(dirty_materials);
dirty_materials = nullptr;
@@ -110,7 +108,6 @@ void ParticlesMaterial::finish_shaders() {
}
void ParticlesMaterial::_update_shader() {
-
dirty_materials->remove(&element);
MaterialKey mk = _compute_key();
@@ -129,7 +126,6 @@ void ParticlesMaterial::_update_shader() {
current_key = mk;
if (shader_map.has(mk)) {
-
RS::get_singleton()->material_set_shader(_get_material(), shader_map[mk].shader);
shader_map[mk].users++;
return;
@@ -307,7 +303,6 @@ void ParticlesMaterial::_update_shader() {
code += " float spread_rad = spread * degree_to_rad;\n";
if (flags[FLAG_DISABLE_Z]) {
-
code += " float angle1_rad = rand_from_seed_m1_p1(alt_seed) * spread_rad;\n";
code += " angle1_rad += direction.x != 0.0 ? atan(direction.y, direction.x) : sign(direction.y) * (pi / 2.0);\n";
code += " vec3 rot = vec3(cos(angle1_rad), sin(angle1_rad), 0.0);\n";
@@ -352,7 +347,6 @@ void ParticlesMaterial::_update_shader() {
if (emission_shape == EMISSION_SHAPE_DIRECTED_POINTS) {
if (flags[FLAG_DISABLE_Z]) {
-
code += " mat2 rotm;";
code += " rotm[0] = texelFetch(emission_texture_normal, emission_tex_ofs, 0).xy;\n";
code += " rotm[1] = rotm[0].yx * vec2(1.0, -1.0);\n";
@@ -386,7 +380,6 @@ void ParticlesMaterial::_update_shader() {
code += " float tex_linear_velocity = 0.0;\n";
if (flags[FLAG_DISABLE_Z]) {
-
if (tex_parameters[PARAM_ORBIT_VELOCITY].is_valid())
code += " float tex_orbit_velocity = textureLod(orbit_velocity_texture, vec2(CUSTOM.y, 0.0), 0.0).r;\n";
else
@@ -456,7 +449,6 @@ void ParticlesMaterial::_update_shader() {
code += " VELOCITY += force * DELTA;\n";
code += " // orbit velocity\n";
if (flags[FLAG_DISABLE_Z]) {
-
code += " float orbit_amount = (orbit_velocity + tex_orbit_velocity) * mix(1.0, rand_from_seed(alt_seed), orbit_velocity_random);\n";
code += " if (orbit_amount != 0.0) {\n";
code += " float ang = orbit_amount * DELTA * pi * 2.0;\n";
@@ -527,7 +519,6 @@ void ParticlesMaterial::_update_shader() {
code += "\n";
if (flags[FLAG_DISABLE_Z]) {
-
if (flags[FLAG_ALIGN_Y_TO_VELOCITY]) {
code += " if (length(VELOCITY) > 0.0) {\n";
code += " TRANSFORM[1].xyz = normalize(VELOCITY);\n";
@@ -603,17 +594,14 @@ void ParticlesMaterial::_update_shader() {
}
void ParticlesMaterial::flush_changes() {
-
MutexLock lock(material_mutex);
while (dirty_materials->first()) {
-
dirty_materials->first()->self()->_update_shader();
}
}
void ParticlesMaterial::_queue_shader_change() {
-
MutexLock lock(material_mutex);
if (!element.in_list()) {
@@ -622,46 +610,38 @@ void ParticlesMaterial::_queue_shader_change() {
}
bool ParticlesMaterial::_is_shader_dirty() const {
-
MutexLock lock(material_mutex);
return element.in_list();
}
void ParticlesMaterial::set_direction(Vector3 p_direction) {
-
direction = p_direction;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->direction, direction);
}
Vector3 ParticlesMaterial::get_direction() const {
-
return direction;
}
void ParticlesMaterial::set_spread(float p_spread) {
-
spread = p_spread;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->spread, p_spread);
}
float ParticlesMaterial::get_spread() const {
-
return spread;
}
void ParticlesMaterial::set_flatness(float p_flatness) {
-
flatness = p_flatness;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->flatness, p_flatness);
}
float ParticlesMaterial::get_flatness() const {
-
return flatness;
}
void ParticlesMaterial::set_param(Parameter p_param, float p_value) {
-
ERR_FAIL_INDEX(p_param, PARAM_MAX);
parameters[p_param] = p_value;
@@ -708,14 +688,12 @@ void ParticlesMaterial::set_param(Parameter p_param, float p_value) {
}
}
float ParticlesMaterial::get_param(Parameter p_param) const {
-
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return parameters[p_param];
}
void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) {
-
ERR_FAIL_INDEX(p_param, PARAM_MAX);
randomness[p_param] = p_value;
@@ -762,14 +740,12 @@ void ParticlesMaterial::set_param_randomness(Parameter p_param, float p_value) {
}
}
float ParticlesMaterial::get_param_randomness(Parameter p_param) const {
-
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return randomness[p_param];
}
static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, float p_max) {
-
Ref<CurveTexture> curve_tex = p_texture;
if (!curve_tex.is_valid())
return;
@@ -778,7 +754,6 @@ static void _adjust_curve_range(const Ref<Texture2D> &p_texture, float p_min, fl
}
void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D> &p_texture) {
-
ERR_FAIL_INDEX(p_param, PARAM_MAX);
tex_parameters[p_param] = p_texture;
@@ -837,25 +812,21 @@ void ParticlesMaterial::set_param_texture(Parameter p_param, const Ref<Texture2D
_queue_shader_change();
}
Ref<Texture2D> ParticlesMaterial::get_param_texture(Parameter p_param) const {
-
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, Ref<Texture2D>());
return tex_parameters[p_param];
}
void ParticlesMaterial::set_color(const Color &p_color) {
-
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color, p_color);
color = p_color;
}
Color ParticlesMaterial::get_color() const {
-
return color;
}
void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) {
-
color_ramp = p_texture;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->color_ramp, p_texture);
_queue_shader_change();
@@ -863,7 +834,6 @@ void ParticlesMaterial::set_color_ramp(const Ref<Texture2D> &p_texture) {
}
Ref<Texture2D> ParticlesMaterial::get_color_ramp() const {
-
return color_ramp;
}
@@ -889,87 +859,71 @@ void ParticlesMaterial::set_emission_shape(EmissionShape p_shape) {
}
void ParticlesMaterial::set_emission_sphere_radius(float p_radius) {
-
emission_sphere_radius = p_radius;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_sphere_radius, p_radius);
}
void ParticlesMaterial::set_emission_box_extents(Vector3 p_extents) {
-
emission_box_extents = p_extents;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_box_extents, p_extents);
}
void ParticlesMaterial::set_emission_point_texture(const Ref<Texture2D> &p_points) {
-
emission_point_texture = p_points;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_points, p_points);
}
void ParticlesMaterial::set_emission_normal_texture(const Ref<Texture2D> &p_normals) {
-
emission_normal_texture = p_normals;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_normal, p_normals);
}
void ParticlesMaterial::set_emission_color_texture(const Ref<Texture2D> &p_colors) {
-
emission_color_texture = p_colors;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_color, p_colors);
_queue_shader_change();
}
void ParticlesMaterial::set_emission_point_count(int p_count) {
-
emission_point_count = p_count;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->emission_texture_point_count, p_count);
}
ParticlesMaterial::EmissionShape ParticlesMaterial::get_emission_shape() const {
-
return emission_shape;
}
float ParticlesMaterial::get_emission_sphere_radius() const {
-
return emission_sphere_radius;
}
Vector3 ParticlesMaterial::get_emission_box_extents() const {
-
return emission_box_extents;
}
Ref<Texture2D> ParticlesMaterial::get_emission_point_texture() const {
-
return emission_point_texture;
}
Ref<Texture2D> ParticlesMaterial::get_emission_normal_texture() const {
-
return emission_normal_texture;
}
Ref<Texture2D> ParticlesMaterial::get_emission_color_texture() const {
-
return emission_color_texture;
}
int ParticlesMaterial::get_emission_point_count() const {
-
return emission_point_count;
}
void ParticlesMaterial::set_trail_divisor(int p_divisor) {
-
trail_divisor = p_divisor;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_divisor, p_divisor);
}
int ParticlesMaterial::get_trail_divisor() const {
-
return trail_divisor;
}
void ParticlesMaterial::set_trail_size_modifier(const Ref<CurveTexture> &p_trail_size_modifier) {
-
trail_size_modifier = p_trail_size_modifier;
Ref<CurveTexture> curve = trail_size_modifier;
@@ -982,24 +936,20 @@ void ParticlesMaterial::set_trail_size_modifier(const Ref<CurveTexture> &p_trail
}
Ref<CurveTexture> ParticlesMaterial::get_trail_size_modifier() const {
-
return trail_size_modifier;
}
void ParticlesMaterial::set_trail_color_modifier(const Ref<GradientTexture> &p_trail_color_modifier) {
-
trail_color_modifier = p_trail_color_modifier;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->trail_color_modifier, p_trail_color_modifier);
_queue_shader_change();
}
Ref<GradientTexture> ParticlesMaterial::get_trail_color_modifier() const {
-
return trail_color_modifier;
}
void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) {
-
gravity = p_gravity;
Vector3 gset = gravity;
if (gset == Vector3()) {
@@ -1009,29 +959,24 @@ void ParticlesMaterial::set_gravity(const Vector3 &p_gravity) {
}
Vector3 ParticlesMaterial::get_gravity() const {
-
return gravity;
}
void ParticlesMaterial::set_lifetime_randomness(float p_lifetime) {
-
lifetime_randomness = p_lifetime;
RenderingServer::get_singleton()->material_set_param(_get_material(), shader_names->lifetime_randomness, lifetime_randomness);
}
float ParticlesMaterial::get_lifetime_randomness() const {
-
return lifetime_randomness;
}
RID ParticlesMaterial::get_shader_rid() const {
-
ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
return shader_map[current_key].shader;
}
void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
-
if (property.name == "color" && color_ramp.is_valid()) {
property.usage = 0;
}
@@ -1062,12 +1007,10 @@ void ParticlesMaterial::_validate_property(PropertyInfo &property) const {
}
Shader::Mode ParticlesMaterial::get_shader_mode() const {
-
return Shader::MODE_PARTICLES;
}
void ParticlesMaterial::_bind_methods() {
-
ClassDB::bind_method(D_METHOD("set_direction", "degrees"), &ParticlesMaterial::set_direction);
ClassDB::bind_method(D_METHOD("get_direction"), &ParticlesMaterial::get_direction);
@@ -1235,7 +1178,6 @@ void ParticlesMaterial::_bind_methods() {
ParticlesMaterial::ParticlesMaterial() :
element(this) {
-
set_direction(Vector3(1, 0, 0));
set_spread(45);
set_flatness(0);
@@ -1276,7 +1218,6 @@ ParticlesMaterial::ParticlesMaterial() :
}
ParticlesMaterial::~ParticlesMaterial() {
-
MutexLock lock(material_mutex);
if (shader_map.has(current_key)) {