2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* particles.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
2017-01-01 21:01:57 +00:00
|
|
|
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
|
2017-04-07 22:11:42 +00:00
|
|
|
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef VISUALINSTANCEPARTICLES_H
|
|
|
|
#define VISUALINSTANCEPARTICLES_H
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "rid.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/3d/visual_instance.h"
|
|
|
|
#include "scene/main/timer.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/resources/material.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
@author Juan Linietsky <reduzio@gmail.com>
|
|
|
|
*/
|
2017-04-07 02:36:37 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class Particles : public GeometryInstance {
|
2017-04-07 02:36:37 +00:00
|
|
|
private:
|
|
|
|
GDCLASS(Particles, GeometryInstance);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-04-07 02:36:37 +00:00
|
|
|
enum DrawOrder {
|
|
|
|
DRAW_ORDER_INDEX,
|
|
|
|
DRAW_ORDER_LIFETIME,
|
|
|
|
DRAW_ORDER_VIEW_DEPTH,
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
enum {
|
|
|
|
MAX_DRAW_PASSES = 4
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
RID particles;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool emitting;
|
2017-06-25 11:01:15 +00:00
|
|
|
bool one_shot;
|
2017-04-07 02:36:37 +00:00
|
|
|
int amount;
|
|
|
|
float lifetime;
|
|
|
|
float pre_process_time;
|
|
|
|
float explosiveness_ratio;
|
|
|
|
float randomness_ratio;
|
2017-04-09 01:38:11 +00:00
|
|
|
float speed_scale;
|
|
|
|
Rect3 visibility_aabb;
|
2017-04-07 02:36:37 +00:00
|
|
|
bool local_coords;
|
|
|
|
int fixed_fps;
|
|
|
|
bool fractional_delta;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
Ref<Material> process_material;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
DrawOrder draw_order;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
Vector<Ref<Mesh> > draw_passes;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
protected:
|
2014-02-10 01:10:30 +00:00
|
|
|
static void _bind_methods();
|
2017-08-07 22:01:30 +00:00
|
|
|
void _notification(int p_what);
|
2017-04-07 02:36:37 +00:00
|
|
|
virtual void _validate_property(PropertyInfo &property) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2017-04-07 02:36:37 +00:00
|
|
|
Rect3 get_aabb() const;
|
2017-01-07 21:25:37 +00:00
|
|
|
PoolVector<Face3> get_faces(uint32_t p_usage_flags) const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_emitting(bool p_emitting);
|
2014-02-10 01:10:30 +00:00
|
|
|
void set_amount(int p_amount);
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_lifetime(float p_lifetime);
|
2017-06-25 11:01:15 +00:00
|
|
|
void set_one_shot(bool p_enabled);
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_pre_process_time(float p_time);
|
|
|
|
void set_explosiveness_ratio(float p_ratio);
|
|
|
|
void set_randomness_ratio(float p_ratio);
|
2017-04-09 01:38:11 +00:00
|
|
|
void set_visibility_aabb(const Rect3 &p_aabb);
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_use_local_coordinates(bool p_enable);
|
|
|
|
void set_process_material(const Ref<Material> &p_material);
|
2017-04-09 01:38:11 +00:00
|
|
|
void set_speed_scale(float p_scale);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
bool is_emitting() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
int get_amount() const;
|
|
|
|
float get_lifetime() const;
|
2017-06-25 11:01:15 +00:00
|
|
|
bool get_one_shot() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
float get_pre_process_time() const;
|
|
|
|
float get_explosiveness_ratio() const;
|
|
|
|
float get_randomness_ratio() const;
|
2017-04-09 01:38:11 +00:00
|
|
|
Rect3 get_visibility_aabb() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
bool get_use_local_coordinates() const;
|
|
|
|
Ref<Material> get_process_material() const;
|
2017-04-09 01:38:11 +00:00
|
|
|
float get_speed_scale() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_fixed_fps(int p_count);
|
|
|
|
int get_fixed_fps() const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_fractional_delta(bool p_enable);
|
|
|
|
bool get_fractional_delta() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_draw_order(DrawOrder p_order);
|
|
|
|
DrawOrder get_draw_order() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_draw_passes(int p_count);
|
|
|
|
int get_draw_passes() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
|
|
|
|
Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-09 01:38:11 +00:00
|
|
|
virtual String get_configuration_warning() const;
|
|
|
|
|
2017-06-25 11:01:15 +00:00
|
|
|
void restart();
|
|
|
|
|
2017-04-09 01:38:11 +00:00
|
|
|
Rect3 capture_aabb() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
Particles();
|
|
|
|
~Particles();
|
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
VARIANT_ENUM_CAST(Particles::DrawOrder)
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
class ParticlesMaterial : public Material {
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
GDCLASS(ParticlesMaterial, Material)
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
public:
|
|
|
|
enum Parameter {
|
|
|
|
|
|
|
|
PARAM_INITIAL_LINEAR_VELOCITY,
|
|
|
|
PARAM_ANGULAR_VELOCITY,
|
|
|
|
PARAM_ORBIT_VELOCITY,
|
|
|
|
PARAM_LINEAR_ACCEL,
|
|
|
|
PARAM_RADIAL_ACCEL,
|
|
|
|
PARAM_TANGENTIAL_ACCEL,
|
|
|
|
PARAM_DAMPING,
|
|
|
|
PARAM_ANGLE,
|
|
|
|
PARAM_SCALE,
|
|
|
|
PARAM_HUE_VARIATION,
|
|
|
|
PARAM_ANIM_SPEED,
|
|
|
|
PARAM_ANIM_OFFSET,
|
|
|
|
PARAM_MAX
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
enum Flags {
|
|
|
|
FLAG_ALIGN_Y_TO_VELOCITY,
|
|
|
|
FLAG_ROTATE_Y,
|
2017-06-21 19:25:45 +00:00
|
|
|
FLAG_DISABLE_Z,
|
|
|
|
FLAG_ANIM_LOOP,
|
2017-04-07 02:36:37 +00:00
|
|
|
FLAG_MAX
|
|
|
|
};
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
enum EmissionShape {
|
|
|
|
EMISSION_SHAPE_POINT,
|
|
|
|
EMISSION_SHAPE_SPHERE,
|
|
|
|
EMISSION_SHAPE_BOX,
|
|
|
|
EMISSION_SHAPE_POINTS,
|
|
|
|
EMISSION_SHAPE_DIRECTED_POINTS,
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
private:
|
|
|
|
union MaterialKey {
|
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t texture_mask : 16;
|
|
|
|
uint32_t texture_color : 1;
|
2017-06-21 19:25:45 +00:00
|
|
|
uint32_t flags : 4;
|
2017-04-07 02:36:37 +00:00
|
|
|
uint32_t emission_shape : 2;
|
|
|
|
uint32_t trail_size_texture : 1;
|
|
|
|
uint32_t trail_color_texture : 1;
|
|
|
|
uint32_t invalid_key : 1;
|
2017-06-21 19:25:45 +00:00
|
|
|
uint32_t has_emission_color : 1;
|
2017-04-07 02:36:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t key;
|
|
|
|
|
|
|
|
bool operator<(const MaterialKey &p_key) const {
|
|
|
|
return key < p_key.key;
|
|
|
|
}
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
struct ShaderData {
|
|
|
|
RID shader;
|
|
|
|
int users;
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
static Map<MaterialKey, ShaderData> shader_map;
|
|
|
|
|
|
|
|
MaterialKey current_key;
|
|
|
|
|
|
|
|
_FORCE_INLINE_ MaterialKey _compute_key() const {
|
|
|
|
|
|
|
|
MaterialKey mk;
|
|
|
|
mk.key = 0;
|
|
|
|
for (int i = 0; i < PARAM_MAX; i++) {
|
|
|
|
if (tex_parameters[i].is_valid()) {
|
|
|
|
mk.texture_mask |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < FLAG_MAX; i++) {
|
|
|
|
if (flags[i]) {
|
|
|
|
mk.flags |= (1 << i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mk.texture_color = color_ramp.is_valid() ? 1 : 0;
|
|
|
|
mk.emission_shape = emission_shape;
|
|
|
|
mk.trail_color_texture = trail_color_modifier.is_valid() ? 1 : 0;
|
|
|
|
mk.trail_size_texture = trail_size_modifier.is_valid() ? 1 : 0;
|
2017-06-21 19:25:45 +00:00
|
|
|
mk.has_emission_color = emission_shape >= EMISSION_SHAPE_POINTS && emission_color_texture.is_valid();
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
return mk;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Mutex *material_mutex;
|
|
|
|
static SelfList<ParticlesMaterial>::List dirty_materials;
|
|
|
|
|
|
|
|
struct ShaderNames {
|
|
|
|
StringName spread;
|
|
|
|
StringName flatness;
|
|
|
|
StringName initial_linear_velocity;
|
|
|
|
StringName initial_angle;
|
|
|
|
StringName angular_velocity;
|
|
|
|
StringName orbit_velocity;
|
|
|
|
StringName linear_accel;
|
|
|
|
StringName radial_accel;
|
|
|
|
StringName tangent_accel;
|
|
|
|
StringName damping;
|
|
|
|
StringName scale;
|
|
|
|
StringName hue_variation;
|
|
|
|
StringName anim_speed;
|
|
|
|
StringName anim_offset;
|
|
|
|
|
|
|
|
StringName initial_linear_velocity_random;
|
|
|
|
StringName initial_angle_random;
|
|
|
|
StringName angular_velocity_random;
|
|
|
|
StringName orbit_velocity_random;
|
|
|
|
StringName linear_accel_random;
|
|
|
|
StringName radial_accel_random;
|
|
|
|
StringName tangent_accel_random;
|
|
|
|
StringName damping_random;
|
|
|
|
StringName scale_random;
|
|
|
|
StringName hue_variation_random;
|
|
|
|
StringName anim_speed_random;
|
|
|
|
StringName anim_offset_random;
|
|
|
|
|
|
|
|
StringName angle_texture;
|
|
|
|
StringName angular_velocity_texture;
|
|
|
|
StringName orbit_velocity_texture;
|
|
|
|
StringName linear_accel_texture;
|
|
|
|
StringName radial_accel_texture;
|
|
|
|
StringName tangent_accel_texture;
|
|
|
|
StringName damping_texture;
|
|
|
|
StringName scale_texture;
|
|
|
|
StringName hue_variation_texture;
|
|
|
|
StringName anim_speed_texture;
|
|
|
|
StringName anim_offset_texture;
|
|
|
|
|
|
|
|
StringName color;
|
|
|
|
StringName color_ramp;
|
|
|
|
|
|
|
|
StringName emission_sphere_radius;
|
|
|
|
StringName emission_box_extents;
|
|
|
|
StringName emission_texture_point_count;
|
|
|
|
StringName emission_texture_points;
|
|
|
|
StringName emission_texture_normal;
|
2017-06-21 19:25:45 +00:00
|
|
|
StringName emission_texture_color;
|
2017-04-07 02:36:37 +00:00
|
|
|
|
|
|
|
StringName trail_divisor;
|
|
|
|
StringName trail_size_modifier;
|
|
|
|
StringName trail_color_modifier;
|
2017-04-09 01:38:11 +00:00
|
|
|
|
|
|
|
StringName gravity;
|
2017-04-07 02:36:37 +00:00
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
static ShaderNames *shader_names;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
SelfList<ParticlesMaterial> element;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
void _update_shader();
|
|
|
|
_FORCE_INLINE_ void _queue_shader_change();
|
|
|
|
_FORCE_INLINE_ bool _is_shader_dirty() const;
|
|
|
|
|
|
|
|
float spread;
|
|
|
|
float flatness;
|
|
|
|
|
|
|
|
float parameters[PARAM_MAX];
|
|
|
|
float randomness[PARAM_MAX];
|
|
|
|
|
|
|
|
Ref<Texture> tex_parameters[PARAM_MAX];
|
|
|
|
Color color;
|
|
|
|
Ref<Texture> color_ramp;
|
|
|
|
|
|
|
|
bool flags[FLAG_MAX];
|
|
|
|
|
|
|
|
EmissionShape emission_shape;
|
|
|
|
float emission_sphere_radius;
|
|
|
|
Vector3 emission_box_extents;
|
|
|
|
Ref<Texture> emission_point_texture;
|
|
|
|
Ref<Texture> emission_normal_texture;
|
2017-06-21 19:25:45 +00:00
|
|
|
Ref<Texture> emission_color_texture;
|
2017-04-07 02:36:37 +00:00
|
|
|
int emission_point_count;
|
|
|
|
|
2017-06-21 19:25:45 +00:00
|
|
|
bool anim_loop;
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
int trail_divisor;
|
|
|
|
|
|
|
|
Ref<CurveTexture> trail_size_modifier;
|
|
|
|
Ref<GradientTexture> trail_color_modifier;
|
|
|
|
|
2017-04-09 01:38:11 +00:00
|
|
|
Vector3 gravity;
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
//do not save emission points here
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
virtual void _validate_property(PropertyInfo &property) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_spread(float p_spread);
|
|
|
|
float get_spread() const;
|
|
|
|
|
|
|
|
void set_flatness(float p_flatness);
|
|
|
|
float get_flatness() const;
|
|
|
|
|
|
|
|
void set_param(Parameter p_param, float p_value);
|
|
|
|
float get_param(Parameter p_param) const;
|
|
|
|
|
|
|
|
void set_param_randomness(Parameter p_param, float p_value);
|
|
|
|
float get_param_randomness(Parameter p_param) const;
|
|
|
|
|
|
|
|
void set_param_texture(Parameter p_param, const Ref<Texture> &p_texture);
|
|
|
|
Ref<Texture> get_param_texture(Parameter p_param) const;
|
|
|
|
|
|
|
|
void set_color(const Color &p_color);
|
|
|
|
Color get_color() const;
|
|
|
|
|
|
|
|
void set_color_ramp(const Ref<Texture> &p_texture);
|
|
|
|
Ref<Texture> get_color_ramp() const;
|
|
|
|
|
|
|
|
void set_flag(Flags p_flag, bool p_enable);
|
|
|
|
bool get_flag(Flags p_flag) const;
|
|
|
|
|
|
|
|
void set_emission_shape(EmissionShape p_shape);
|
|
|
|
void set_emission_sphere_radius(float p_radius);
|
|
|
|
void set_emission_box_extents(Vector3 p_extents);
|
|
|
|
void set_emission_point_texture(const Ref<Texture> &p_points);
|
|
|
|
void set_emission_normal_texture(const Ref<Texture> &p_normals);
|
2017-06-21 19:25:45 +00:00
|
|
|
void set_emission_color_texture(const Ref<Texture> &p_colors);
|
2017-04-07 02:36:37 +00:00
|
|
|
void set_emission_point_count(int p_count);
|
|
|
|
|
|
|
|
EmissionShape get_emission_shape() const;
|
|
|
|
float get_emission_sphere_radius() const;
|
|
|
|
Vector3 get_emission_box_extents() const;
|
|
|
|
Ref<Texture> get_emission_point_texture() const;
|
|
|
|
Ref<Texture> get_emission_normal_texture() const;
|
2017-06-21 19:25:45 +00:00
|
|
|
Ref<Texture> get_emission_color_texture() const;
|
2017-04-07 02:36:37 +00:00
|
|
|
int get_emission_point_count() const;
|
|
|
|
|
|
|
|
void set_trail_divisor(int p_divisor);
|
|
|
|
int get_trail_divisor() const;
|
|
|
|
|
|
|
|
void set_trail_size_modifier(const Ref<CurveTexture> &p_trail_size_modifier);
|
|
|
|
Ref<CurveTexture> get_trail_size_modifier() const;
|
|
|
|
|
|
|
|
void set_trail_color_modifier(const Ref<GradientTexture> &p_trail_color_modifier);
|
|
|
|
Ref<GradientTexture> get_trail_color_modifier() const;
|
|
|
|
|
2017-04-09 01:38:11 +00:00
|
|
|
void set_gravity(const Vector3 &p_gravity);
|
|
|
|
Vector3 get_gravity() const;
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
static void init_shaders();
|
|
|
|
static void finish_shaders();
|
|
|
|
static void flush_changes();
|
|
|
|
|
|
|
|
ParticlesMaterial();
|
|
|
|
~ParticlesMaterial();
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
2017-04-07 02:36:37 +00:00
|
|
|
VARIANT_ENUM_CAST(ParticlesMaterial::Parameter)
|
|
|
|
VARIANT_ENUM_CAST(ParticlesMaterial::Flags)
|
|
|
|
VARIANT_ENUM_CAST(ParticlesMaterial::EmissionShape)
|
|
|
|
|
2016-10-03 19:33:42 +00:00
|
|
|
#endif
|