diff options
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/dummy/storage/particles_storage.h | 3 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/shaders/particles.glsl | 4 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/particles_storage.cpp | 30 | ||||
-rw-r--r-- | servers/rendering/renderer_rd/storage_rd/particles_storage.h | 11 | ||||
-rw-r--r-- | servers/rendering/rendering_server_default.h | 3 | ||||
-rw-r--r-- | servers/rendering/shader_types.cpp | 6 | ||||
-rw-r--r-- | servers/rendering/storage/particles_storage.h | 3 | ||||
-rw-r--r-- | servers/rendering_server.cpp | 3 | ||||
-rw-r--r-- | servers/rendering_server.h | 3 |
9 files changed, 63 insertions, 3 deletions
diff --git a/servers/rendering/dummy/storage/particles_storage.h b/servers/rendering/dummy/storage/particles_storage.h index a40c96a8f5..33dad3f2f4 100644 --- a/servers/rendering/dummy/storage/particles_storage.h +++ b/servers/rendering/dummy/storage/particles_storage.h @@ -47,6 +47,7 @@ public: virtual void particles_emit(RID p_particles, const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags) override {} virtual void particles_set_emitting(RID p_particles, bool p_emitting) override {} virtual void particles_set_amount(RID p_particles, int p_amount) override {} + virtual void particles_set_amount_ratio(RID p_particles, float p_amount_ratio) override {} virtual void particles_set_lifetime(RID p_particles, double p_lifetime) override {} virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) override {} virtual void particles_set_pre_process_time(RID p_particles, double p_time) override {} @@ -81,6 +82,8 @@ public: virtual AABB particles_get_aabb(RID p_particles) const override { return AABB(); } virtual void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) override {} + virtual void particles_set_emitter_velocity(RID p_particles, const Vector3 &p_velocity) override {} + virtual void particles_set_interp_to_end(RID p_particles, float p_interp) override {} virtual bool particles_get_emitting(RID p_particles) override { return false; } virtual int particles_get_draw_passes(RID p_particles) const override { return 0; } diff --git a/servers/rendering/renderer_rd/shaders/particles.glsl b/servers/rendering/renderer_rd/shaders/particles.glsl index 7ba03a27f7..5fa4154727 100644 --- a/servers/rendering/renderer_rd/shaders/particles.glsl +++ b/servers/rendering/renderer_rd/shaders/particles.glsl @@ -67,7 +67,7 @@ struct FrameParams { float delta; uint frame; - uint pad0; + float amount_ratio; uint pad1; uint pad2; @@ -77,6 +77,8 @@ struct FrameParams { float particle_size; mat4 emission_transform; + vec3 emitter_velocity; + float interp_to_end; Attractor attractors[MAX_ATTRACTORS]; Collider colliders[MAX_COLLIDERS]; diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp index bf5a597bb9..3065da4d05 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.cpp @@ -72,6 +72,7 @@ ParticlesStorage::ParticlesStorage() { actions.renames["ACTIVE"] = "particle_active"; actions.renames["RESTART"] = "restart"; actions.renames["CUSTOM"] = "PARTICLE.custom"; + actions.renames["AMOUNT_RATIO"] = "FRAME.amount_ratio"; for (int i = 0; i < ParticlesShader::MAX_USERDATAS; i++) { String udname = "USERDATA" + itos(i + 1); actions.renames[udname] = "PARTICLE.userdata" + itos(i + 1); @@ -88,6 +89,8 @@ ParticlesStorage::ParticlesStorage() { actions.renames["INDEX"] = "index"; //actions.renames["GRAVITY"] = "current_gravity"; actions.renames["EMISSION_TRANSFORM"] = "FRAME.emission_transform"; + actions.renames["EMITTER_VELOCITY"] = "FRAME.emitter_velocity"; + actions.renames["INTERPOLATE_TO_END"] = "FRAME.interp_to_end"; actions.renames["RANDOM_SEED"] = "FRAME.random_seed"; actions.renames["FLAG_EMIT_POSITION"] = "EMISSION_FLAG_HAS_POSITION"; actions.renames["FLAG_EMIT_ROT_SCALE"] = "EMISSION_FLAG_HAS_ROTATION_SCALE"; @@ -329,6 +332,13 @@ void ParticlesStorage::particles_set_amount(RID p_particles, int p_amount) { particles->dependency.changed_notify(Dependency::DEPENDENCY_CHANGED_PARTICLES); } +void ParticlesStorage::particles_set_amount_ratio(RID p_particles, float p_amount_ratio) { + Particles *particles = particles_owner.get_or_null(p_particles); + ERR_FAIL_NULL(particles); + + particles->amount_ratio = p_amount_ratio; +} + void ParticlesStorage::particles_set_lifetime(RID p_particles, double p_lifetime) { Particles *particles = particles_owner.get_or_null(p_particles); ERR_FAIL_NULL(particles); @@ -651,6 +661,20 @@ void ParticlesStorage::particles_set_emission_transform(RID p_particles, const T particles->emission_transform = p_transform; } +void ParticlesStorage::particles_set_emitter_velocity(RID p_particles, const Vector3 &p_velocity) { + Particles *particles = particles_owner.get_or_null(p_particles); + ERR_FAIL_NULL(particles); + + particles->emitter_velocity = p_velocity; +} + +void ParticlesStorage::particles_set_interp_to_end(RID p_particles, float p_interp) { + Particles *particles = particles_owner.get_or_null(p_particles); + ERR_FAIL_NULL(particles); + + particles->interp_to_end = p_interp; +} + int ParticlesStorage::particles_get_draw_passes(RID p_particles) const { const Particles *particles = particles_owner.get_or_null(p_particles); ERR_FAIL_NULL_V(particles, 0); @@ -791,9 +815,13 @@ void ParticlesStorage::_particles_process(Particles *p_particles, double p_delta frame_params.cycle = p_particles->cycle_number; frame_params.frame = p_particles->frame_counter++; - frame_params.pad0 = 0; + frame_params.amount_ratio = p_particles->amount_ratio; frame_params.pad1 = 0; frame_params.pad2 = 0; + frame_params.emitter_velocity[0] = p_particles->emitter_velocity.x; + frame_params.emitter_velocity[1] = p_particles->emitter_velocity.y; + frame_params.emitter_velocity[2] = p_particles->emitter_velocity.z; + frame_params.interp_to_end = p_particles->interp_to_end; { //collision and attractors diff --git a/servers/rendering/renderer_rd/storage_rd/particles_storage.h b/servers/rendering/renderer_rd/storage_rd/particles_storage.h index b93932f482..435ef14d75 100644 --- a/servers/rendering/renderer_rd/storage_rd/particles_storage.h +++ b/servers/rendering/renderer_rd/storage_rd/particles_storage.h @@ -123,7 +123,7 @@ private: float delta; uint32_t frame; - uint32_t pad0; + float amount_ratio; uint32_t pad1; uint32_t pad2; @@ -134,6 +134,9 @@ private: float emission_transform[16]; + float emitter_velocity[3]; + float interp_to_end; + Attractor attractors[MAX_ATTRACTORS]; Collider colliders[MAX_COLLIDERS]; }; @@ -235,6 +238,9 @@ private: bool force_sub_emit = false; Transform3D emission_transform; + Vector3 emitter_velocity; + float interp_to_end = 0.0; + float amount_ratio = 1.0; Vector<uint8_t> emission_buffer_data; @@ -425,6 +431,7 @@ public: virtual void particles_set_mode(RID p_particles, RS::ParticlesMode p_mode) override; virtual void particles_set_emitting(RID p_particles, bool p_emitting) override; virtual void particles_set_amount(RID p_particles, int p_amount) override; + virtual void particles_set_amount_ratio(RID p_particles, float p_amount_ratio) override; virtual void particles_set_lifetime(RID p_particles, double p_lifetime) override; virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) override; virtual void particles_set_pre_process_time(RID p_particles, double p_time) override; @@ -460,6 +467,8 @@ public: virtual AABB particles_get_aabb(RID p_particles) const override; virtual void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) override; + virtual void particles_set_emitter_velocity(RID p_particles, const Vector3 &p_velocity) override; + virtual void particles_set_interp_to_end(RID p_particles, float p_interp_to_end) override; virtual bool particles_get_emitting(RID p_particles) override; virtual int particles_get_draw_passes(RID p_particles) const override; diff --git a/servers/rendering/rendering_server_default.h b/servers/rendering/rendering_server_default.h index 9ad2175332..955d83c093 100644 --- a/servers/rendering/rendering_server_default.h +++ b/servers/rendering/rendering_server_default.h @@ -490,6 +490,7 @@ public: FUNC2(particles_set_emitting, RID, bool) FUNC1R(bool, particles_get_emitting, RID) FUNC2(particles_set_amount, RID, int) + FUNC2(particles_set_amount_ratio, RID, float) FUNC2(particles_set_lifetime, RID, double) FUNC2(particles_set_one_shot, RID, bool) FUNC2(particles_set_pre_process_time, RID, double) @@ -521,6 +522,8 @@ public: FUNC1R(AABB, particles_get_current_aabb, RID) FUNC2(particles_set_emission_transform, RID, const Transform3D &) + FUNC2(particles_set_emitter_velocity, RID, const Vector3 &) + FUNC2(particles_set_interp_to_end, RID, float) /* PARTICLES COLLISION */ diff --git a/servers/rendering/shader_types.cpp b/servers/rendering/shader_types.cpp index 38574b0597..a6b4646f43 100644 --- a/servers/rendering/shader_types.cpp +++ b/servers/rendering/shader_types.cpp @@ -348,6 +348,8 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["NUMBER"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["INDEX"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["EMISSION_TRANSFORM"] = constt(ShaderLanguage::TYPE_MAT4); + shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["EMITTER_VELOCITY"] = constt(ShaderLanguage::TYPE_VEC3); + shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["INTERPOLATE_TO_END"] = constt(ShaderLanguage::TYPE_FLOAT); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["RANDOM_SEED"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["FLAG_EMIT_POSITION"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["FLAG_EMIT_ROT_SCALE"] = constt(ShaderLanguage::TYPE_UINT); @@ -359,6 +361,7 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["RESTART_VELOCITY"] = constt(ShaderLanguage::TYPE_BOOL); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["RESTART_COLOR"] = constt(ShaderLanguage::TYPE_BOOL); shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["RESTART_CUSTOM"] = constt(ShaderLanguage::TYPE_BOOL); + shader_modes[RS::SHADER_PARTICLES].functions["start"].built_ins["AMOUNT_RATIO"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_PARTICLES].functions["start"].main_function = true; shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["COLOR"] = ShaderLanguage::TYPE_VEC4; @@ -379,6 +382,8 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["NUMBER"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["INDEX"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["EMISSION_TRANSFORM"] = constt(ShaderLanguage::TYPE_MAT4); + shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["EMITTER_VELOCITY"] = constt(ShaderLanguage::TYPE_VEC3); + shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["INTERPOLATE_TO_END"] = constt(ShaderLanguage::TYPE_FLOAT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["RANDOM_SEED"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["FLAG_EMIT_POSITION"] = constt(ShaderLanguage::TYPE_UINT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["FLAG_EMIT_ROT_SCALE"] = constt(ShaderLanguage::TYPE_UINT); @@ -389,6 +394,7 @@ ShaderTypes::ShaderTypes() { shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["COLLISION_NORMAL"] = constt(ShaderLanguage::TYPE_VEC3); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["COLLISION_DEPTH"] = constt(ShaderLanguage::TYPE_FLOAT); shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["ATTRACTOR_FORCE"] = constt(ShaderLanguage::TYPE_VEC3); + shader_modes[RS::SHADER_PARTICLES].functions["process"].built_ins["AMOUNT_RATIO"] = ShaderLanguage::TYPE_FLOAT; shader_modes[RS::SHADER_PARTICLES].functions["process"].main_function = true; { diff --git a/servers/rendering/storage/particles_storage.h b/servers/rendering/storage/particles_storage.h index 78c616f6d5..4f33de912c 100644 --- a/servers/rendering/storage/particles_storage.h +++ b/servers/rendering/storage/particles_storage.h @@ -49,6 +49,7 @@ public: virtual bool particles_get_emitting(RID p_particles) = 0; virtual void particles_set_amount(RID p_particles, int p_amount) = 0; + virtual void particles_set_amount_ratio(RID p_particles, float p_amount_ratio) = 0; virtual void particles_set_lifetime(RID p_particles, double p_lifetime) = 0; virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) = 0; virtual void particles_set_pre_process_time(RID p_particles, double p_time) = 0; @@ -85,6 +86,8 @@ public: virtual AABB particles_get_aabb(RID p_particles) const = 0; virtual void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) = 0; + virtual void particles_set_emitter_velocity(RID p_particles, const Vector3 &p_velocity) = 0; + virtual void particles_set_interp_to_end(RID p_particles, float p_interp_to_end) = 0; virtual int particles_get_draw_passes(RID p_particles) const = 0; virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const = 0; diff --git a/servers/rendering_server.cpp b/servers/rendering_server.cpp index 94ff59f7e1..4f173ce4cb 100644 --- a/servers/rendering_server.cpp +++ b/servers/rendering_server.cpp @@ -2497,11 +2497,14 @@ void RenderingServer::_bind_methods() { ClassDB::bind_method(D_METHOD("particles_set_emitting", "particles", "emitting"), &RenderingServer::particles_set_emitting); ClassDB::bind_method(D_METHOD("particles_get_emitting", "particles"), &RenderingServer::particles_get_emitting); ClassDB::bind_method(D_METHOD("particles_set_amount", "particles", "amount"), &RenderingServer::particles_set_amount); + ClassDB::bind_method(D_METHOD("particles_set_amount_ratio", "particles", "ratio"), &RenderingServer::particles_set_amount_ratio); ClassDB::bind_method(D_METHOD("particles_set_lifetime", "particles", "lifetime"), &RenderingServer::particles_set_lifetime); ClassDB::bind_method(D_METHOD("particles_set_one_shot", "particles", "one_shot"), &RenderingServer::particles_set_one_shot); ClassDB::bind_method(D_METHOD("particles_set_pre_process_time", "particles", "time"), &RenderingServer::particles_set_pre_process_time); ClassDB::bind_method(D_METHOD("particles_set_explosiveness_ratio", "particles", "ratio"), &RenderingServer::particles_set_explosiveness_ratio); ClassDB::bind_method(D_METHOD("particles_set_randomness_ratio", "particles", "ratio"), &RenderingServer::particles_set_randomness_ratio); + ClassDB::bind_method(D_METHOD("particles_set_interp_to_end", "particles", "factor"), &RenderingServer::particles_set_interp_to_end); + ClassDB::bind_method(D_METHOD("particles_set_emitter_velocity", "particles", "velocity"), &RenderingServer::particles_set_emitter_velocity); ClassDB::bind_method(D_METHOD("particles_set_custom_aabb", "particles", "aabb"), &RenderingServer::particles_set_custom_aabb); ClassDB::bind_method(D_METHOD("particles_set_speed_scale", "particles", "scale"), &RenderingServer::particles_set_speed_scale); ClassDB::bind_method(D_METHOD("particles_set_use_local_coordinates", "particles", "enable"), &RenderingServer::particles_set_use_local_coordinates); diff --git a/servers/rendering_server.h b/servers/rendering_server.h index 9d186f086c..fe7c039e91 100644 --- a/servers/rendering_server.h +++ b/servers/rendering_server.h @@ -660,6 +660,7 @@ public: virtual void particles_set_emitting(RID p_particles, bool p_enable) = 0; virtual bool particles_get_emitting(RID p_particles) = 0; virtual void particles_set_amount(RID p_particles, int p_amount) = 0; + virtual void particles_set_amount_ratio(RID p_particles, float p_amount_ratio) = 0; virtual void particles_set_lifetime(RID p_particles, double p_lifetime) = 0; virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) = 0; virtual void particles_set_pre_process_time(RID p_particles, double p_time) = 0; @@ -717,6 +718,8 @@ public: virtual AABB particles_get_current_aabb(RID p_particles) = 0; virtual void particles_set_emission_transform(RID p_particles, const Transform3D &p_transform) = 0; // This is only used for 2D, in 3D it's automatic. + virtual void particles_set_emitter_velocity(RID p_particles, const Vector3 &p_velocity) = 0; + virtual void particles_set_interp_to_end(RID p_particles, float p_interp) = 0; /* PARTICLES COLLISION API */ |