forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiHairParticle.h
115 lines (97 loc) · 3.08 KB
/
wiHairParticle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include "CommonInclude.h"
#include "wiGraphicsDevice.h"
#include "wiEnums.h"
#include "wiMath.h"
#include "wiECS.h"
#include "wiPrimitive.h"
#include "wiVector.h"
#include "wiScene_Decl.h"
#include "wiScene_Components.h"
namespace wi
{
class Archive;
}
namespace wi
{
class HairParticleSystem
{
public:
wi::graphics::GPUBuffer constantBuffer;
wi::graphics::GPUBuffer generalBuffer;
wi::scene::MeshComponent::BufferView simulation_view;
wi::scene::MeshComponent::BufferView vb_pos[2];
wi::scene::MeshComponent::BufferView vb_nor;
wi::scene::MeshComponent::BufferView vb_pos_raytracing;
wi::scene::MeshComponent::BufferView vb_uvs;
wi::scene::MeshComponent::BufferView ib_culled;
wi::scene::MeshComponent::BufferView indirect_view;
wi::graphics::GPUBuffer primitiveBuffer;
wi::graphics::GPUBuffer indexBuffer;
wi::graphics::GPUBuffer vertexBuffer_length;
wi::graphics::RaytracingAccelerationStructure BLAS;
void CreateFromMesh(const wi::scene::MeshComponent& mesh);
void CreateRenderData();
void CreateRaytracingRenderData();
void UpdateCPU(
const wi::scene::TransformComponent& transform,
const wi::scene::MeshComponent& mesh,
float dt
);
struct UpdateGPUItem
{
const HairParticleSystem* hair = nullptr;
uint32_t instanceIndex = 0;
const wi::scene::MeshComponent* mesh = nullptr;
const wi::scene::MaterialComponent* material = nullptr;
};
// Update a batch of hair particles by GPU
static void UpdateGPU(
const UpdateGPUItem* items,
uint32_t itemCount,
wi::graphics::CommandList cmd
);
mutable bool gpu_initialized = false;
void InitializeGPUDataIfNeeded(wi::graphics::CommandList cmd);
void Draw(
const wi::scene::MaterialComponent& material,
wi::enums::RENDERPASS renderPass,
wi::graphics::CommandList cmd
) const;
enum FLAGS
{
EMPTY = 0,
_DEPRECATED_REGENERATE_FRAME = 1 << 0,
REBUILD_BUFFERS = 1 << 1,
DIRTY = 1 << 2,
};
uint32_t _flags = EMPTY;
wi::ecs::Entity meshID = wi::ecs::INVALID_ENTITY;
uint32_t strandCount = 0;
uint32_t segmentCount = 1;
uint32_t randomSeed = 1;
float length = 1.0f;
float stiffness = 10.0f;
float randomness = 0.2f;
float viewDistance = 200;
wi::vector<float> vertex_lengths;
// Sprite sheet properties:
uint32_t framesX = 1;
uint32_t framesY = 1;
uint32_t frameCount = 1;
uint32_t frameStart = 0;
// Non-serialized attributes:
XMFLOAT4X4 world;
wi::primitive::AABB aabb;
wi::vector<uint32_t> indices; // it is dependent on vertex_lengths and contains triangles with non-zero lengths
uint32_t layerMask = ~0u;
mutable bool regenerate_frame = true;
wi::graphics::Format position_format = wi::graphics::Format::R16G16B16A16_UNORM;
void Serialize(wi::Archive& archive, wi::ecs::EntitySerializer& seri);
static void Initialize();
constexpr uint32_t GetParticleCount() const { return strandCount * segmentCount; }
uint64_t GetMemorySizeInBytes() const;
constexpr bool IsDirty() const { return _flags & DIRTY; }
constexpr void SetDirty(bool value = true) { if (value) { _flags |= DIRTY; } else { _flags &= ~DIRTY; } }
};
}