2020-10-08 00:29:49 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* gpu_particles_collision_3d.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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 GPU_PARTICLES_COLLISION_3D_H
|
|
|
|
#define GPU_PARTICLES_COLLISION_3D_H
|
|
|
|
|
2020-11-07 22:33:38 +00:00
|
|
|
#include "core/templates/local_vector.h"
|
2020-10-08 00:29:49 +00:00
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
|
|
|
|
|
|
|
class GPUParticlesCollision3D : public VisualInstance3D {
|
|
|
|
GDCLASS(GPUParticlesCollision3D, VisualInstance3D);
|
|
|
|
|
|
|
|
uint32_t cull_mask = 0xFFFFFFFF;
|
|
|
|
RID collision;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
_FORCE_INLINE_ RID _get_collision() { return collision; }
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
GPUParticlesCollision3D(RS::ParticlesCollisionType p_type);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_cull_mask(uint32_t p_cull_mask);
|
|
|
|
uint32_t get_cull_mask() const;
|
|
|
|
|
|
|
|
~GPUParticlesCollision3D();
|
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesCollisionSphere3D : public GPUParticlesCollision3D {
|
|
|
|
GDCLASS(GPUParticlesCollisionSphere3D, GPUParticlesCollision3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2021-08-12 14:07:47 +00:00
|
|
|
real_t radius = 1.0;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2021-08-12 14:07:47 +00:00
|
|
|
void set_radius(real_t p_radius);
|
|
|
|
real_t get_radius() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesCollisionSphere3D();
|
|
|
|
~GPUParticlesCollisionSphere3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesCollisionBox3D : public GPUParticlesCollision3D {
|
|
|
|
GDCLASS(GPUParticlesCollisionBox3D, GPUParticlesCollision3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2022-07-12 07:43:01 +00:00
|
|
|
Vector3 size = Vector3(2, 2, 2);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-07-12 07:43:01 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_property) const;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
2022-07-12 07:43:01 +00:00
|
|
|
void set_size(const Vector3 &p_size);
|
|
|
|
Vector3 get_size() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesCollisionBox3D();
|
|
|
|
~GPUParticlesCollisionBox3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesCollisionSDF3D : public GPUParticlesCollision3D {
|
|
|
|
GDCLASS(GPUParticlesCollisionSDF3D, GPUParticlesCollision3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Resolution {
|
|
|
|
RESOLUTION_16,
|
|
|
|
RESOLUTION_32,
|
|
|
|
RESOLUTION_64,
|
|
|
|
RESOLUTION_128,
|
|
|
|
RESOLUTION_256,
|
|
|
|
RESOLUTION_512,
|
|
|
|
RESOLUTION_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef void (*BakeBeginFunc)(int);
|
|
|
|
typedef void (*BakeStepFunc)(int, const String &);
|
|
|
|
typedef void (*BakeEndFunc)();
|
|
|
|
|
|
|
|
private:
|
2022-07-12 07:43:01 +00:00
|
|
|
Vector3 size = Vector3(2, 2, 2);
|
2020-10-08 00:29:49 +00:00
|
|
|
Resolution resolution = RESOLUTION_64;
|
2022-06-30 21:11:32 +00:00
|
|
|
uint32_t bake_mask = 0xFFFFFFFF;
|
2020-10-08 00:29:49 +00:00
|
|
|
Ref<Texture3D> texture;
|
|
|
|
float thickness = 1.0;
|
|
|
|
|
|
|
|
struct PlotMesh {
|
|
|
|
Ref<Mesh> mesh;
|
2020-10-17 05:08:21 +00:00
|
|
|
Transform3D local_xform;
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void _find_meshes(const AABB &p_aabb, Node *p_at_node, List<PlotMesh> &plot_meshes);
|
|
|
|
|
|
|
|
struct BVH {
|
|
|
|
enum {
|
|
|
|
LEAF_BIT = 1 << 30,
|
|
|
|
LEAF_MASK = LEAF_BIT - 1
|
|
|
|
};
|
|
|
|
AABB bounds;
|
2021-02-07 21:29:31 +00:00
|
|
|
uint32_t children[2] = {};
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FacePos {
|
|
|
|
Vector3 center;
|
2021-02-07 21:29:31 +00:00
|
|
|
uint32_t index = 0;
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FaceSort {
|
2021-02-07 21:29:31 +00:00
|
|
|
uint32_t axis = 0;
|
2020-10-08 00:29:49 +00:00
|
|
|
bool operator()(const FacePos &p_left, const FacePos &p_right) const {
|
|
|
|
return p_left.center[axis] < p_right.center[axis];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t _create_bvh(LocalVector<BVH> &bvh_tree, FacePos *p_faces, uint32_t p_face_count, const Face3 *p_triangles, float p_thickness);
|
|
|
|
|
|
|
|
struct ComputeSDFParams {
|
2021-02-07 21:29:31 +00:00
|
|
|
float *cells = nullptr;
|
2020-10-08 00:29:49 +00:00
|
|
|
Vector3i size;
|
2021-02-07 21:29:31 +00:00
|
|
|
float cell_size = 0.0;
|
2020-10-08 00:29:49 +00:00
|
|
|
Vector3 cell_offset;
|
2021-02-07 21:29:31 +00:00
|
|
|
const BVH *bvh = nullptr;
|
|
|
|
const Face3 *triangles = nullptr;
|
|
|
|
float thickness = 0.0;
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2022-09-29 09:53:28 +00:00
|
|
|
void _find_closest_distance(const Vector3 &p_pos, const BVH *p_bvh, uint32_t p_bvh_cell, const Face3 *p_triangles, float p_thickness, float &r_closest_distance);
|
2020-10-08 00:29:49 +00:00
|
|
|
void _compute_sdf_z(uint32_t p_z, ComputeSDFParams *params);
|
|
|
|
void _compute_sdf(ComputeSDFParams *params);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-07-12 07:43:01 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_property) const;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
2023-07-05 13:41:44 +00:00
|
|
|
virtual Array get_configuration_warnings() const override;
|
2022-06-30 21:11:32 +00:00
|
|
|
|
2020-10-08 00:29:49 +00:00
|
|
|
void set_thickness(float p_thickness);
|
|
|
|
float get_thickness() const;
|
|
|
|
|
2022-07-12 07:43:01 +00:00
|
|
|
void set_size(const Vector3 &p_size);
|
|
|
|
Vector3 get_size() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
void set_resolution(Resolution p_resolution);
|
|
|
|
Resolution get_resolution() const;
|
|
|
|
|
2022-06-30 21:11:32 +00:00
|
|
|
void set_bake_mask(uint32_t p_mask);
|
|
|
|
uint32_t get_bake_mask() const;
|
|
|
|
|
|
|
|
void set_bake_mask_value(int p_layer_number, bool p_enable);
|
|
|
|
bool get_bake_mask_value(int p_layer_number) const;
|
|
|
|
|
2020-10-08 00:29:49 +00:00
|
|
|
void set_texture(const Ref<Texture3D> &p_texture);
|
|
|
|
Ref<Texture3D> get_texture() const;
|
|
|
|
|
|
|
|
Vector3i get_estimated_cell_size() const;
|
|
|
|
Ref<Image> bake();
|
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
|
|
|
static BakeBeginFunc bake_begin_function;
|
|
|
|
static BakeStepFunc bake_step_function;
|
|
|
|
static BakeEndFunc bake_end_function;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesCollisionSDF3D();
|
|
|
|
~GPUParticlesCollisionSDF3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
VARIANT_ENUM_CAST(GPUParticlesCollisionSDF3D::Resolution)
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesCollisionHeightField3D : public GPUParticlesCollision3D {
|
|
|
|
GDCLASS(GPUParticlesCollisionHeightField3D, GPUParticlesCollision3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Resolution {
|
|
|
|
RESOLUTION_256,
|
|
|
|
RESOLUTION_512,
|
|
|
|
RESOLUTION_1024,
|
|
|
|
RESOLUTION_2048,
|
|
|
|
RESOLUTION_4096,
|
|
|
|
RESOLUTION_8192,
|
|
|
|
RESOLUTION_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum UpdateMode {
|
|
|
|
UPDATE_MODE_WHEN_MOVED,
|
|
|
|
UPDATE_MODE_ALWAYS,
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
2022-07-12 07:43:01 +00:00
|
|
|
Vector3 size = Vector3(2, 2, 2);
|
2020-10-08 00:29:49 +00:00
|
|
|
Resolution resolution = RESOLUTION_1024;
|
|
|
|
bool follow_camera_mode = false;
|
|
|
|
|
|
|
|
UpdateMode update_mode = UPDATE_MODE_WHEN_MOVED;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
2022-07-12 07:43:01 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_property) const;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
2022-07-12 07:43:01 +00:00
|
|
|
void set_size(const Vector3 &p_size);
|
|
|
|
Vector3 get_size() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
void set_resolution(Resolution p_resolution);
|
|
|
|
Resolution get_resolution() const;
|
|
|
|
|
|
|
|
void set_update_mode(UpdateMode p_update_mode);
|
|
|
|
UpdateMode get_update_mode() const;
|
|
|
|
|
2022-05-13 02:18:06 +00:00
|
|
|
void set_follow_camera_enabled(bool p_enabled);
|
|
|
|
bool is_follow_camera_enabled() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesCollisionHeightField3D();
|
|
|
|
~GPUParticlesCollisionHeightField3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField3D::Resolution)
|
|
|
|
VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField3D::UpdateMode)
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
class GPUParticlesAttractor3D : public VisualInstance3D {
|
|
|
|
GDCLASS(GPUParticlesAttractor3D, VisualInstance3D);
|
|
|
|
|
|
|
|
uint32_t cull_mask = 0xFFFFFFFF;
|
|
|
|
RID collision;
|
2021-08-12 14:07:47 +00:00
|
|
|
real_t strength = 1.0;
|
|
|
|
real_t attenuation = 1.0;
|
|
|
|
real_t directionality = 0.0;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
_FORCE_INLINE_ RID _get_collision() { return collision; }
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
GPUParticlesAttractor3D(RS::ParticlesCollisionType p_type);
|
|
|
|
|
|
|
|
public:
|
|
|
|
void set_cull_mask(uint32_t p_cull_mask);
|
|
|
|
uint32_t get_cull_mask() const;
|
|
|
|
|
2021-08-12 14:07:47 +00:00
|
|
|
void set_strength(real_t p_strength);
|
|
|
|
real_t get_strength() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2021-08-12 14:07:47 +00:00
|
|
|
void set_attenuation(real_t p_attenuation);
|
|
|
|
real_t get_attenuation() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2021-08-12 14:07:47 +00:00
|
|
|
void set_directionality(real_t p_directionality);
|
|
|
|
real_t get_directionality() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
~GPUParticlesAttractor3D();
|
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesAttractorSphere3D : public GPUParticlesAttractor3D {
|
|
|
|
GDCLASS(GPUParticlesAttractorSphere3D, GPUParticlesAttractor3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2021-08-12 14:07:47 +00:00
|
|
|
real_t radius = 1.0;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
2021-08-12 14:07:47 +00:00
|
|
|
void set_radius(real_t p_radius);
|
|
|
|
real_t get_radius() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesAttractorSphere3D();
|
|
|
|
~GPUParticlesAttractorSphere3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesAttractorBox3D : public GPUParticlesAttractor3D {
|
|
|
|
GDCLASS(GPUParticlesAttractorBox3D, GPUParticlesAttractor3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2022-07-12 07:43:01 +00:00
|
|
|
Vector3 size = Vector3(2, 2, 2);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-07-12 07:43:01 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_property) const;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
2022-07-12 07:43:01 +00:00
|
|
|
void set_size(const Vector3 &p_size);
|
|
|
|
Vector3 get_size() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesAttractorBox3D();
|
|
|
|
~GPUParticlesAttractorBox3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
class GPUParticlesAttractorVectorField3D : public GPUParticlesAttractor3D {
|
|
|
|
GDCLASS(GPUParticlesAttractorVectorField3D, GPUParticlesAttractor3D);
|
2020-10-08 00:29:49 +00:00
|
|
|
|
2022-07-12 07:43:01 +00:00
|
|
|
Vector3 size = Vector3(2, 2, 2);
|
2020-10-08 00:29:49 +00:00
|
|
|
Ref<Texture3D> texture;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2022-07-12 07:43:01 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
bool _set(const StringName &p_name, const Variant &p_value);
|
|
|
|
bool _get(const StringName &p_name, Variant &r_property) const;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
public:
|
2022-07-12 07:43:01 +00:00
|
|
|
void set_size(const Vector3 &p_size);
|
|
|
|
Vector3 get_size() const;
|
2020-10-08 00:29:49 +00:00
|
|
|
|
|
|
|
void set_texture(const Ref<Texture3D> &p_texture);
|
|
|
|
Ref<Texture3D> get_texture() const;
|
|
|
|
|
|
|
|
virtual AABB get_aabb() const override;
|
|
|
|
|
2021-12-06 18:13:12 +00:00
|
|
|
GPUParticlesAttractorVectorField3D();
|
|
|
|
~GPUParticlesAttractorVectorField3D();
|
2020-10-08 00:29:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GPU_PARTICLES_COLLISION_3D_H
|