forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShaderInterop_EmittedParticle.h
164 lines (139 loc) · 4.76 KB
/
ShaderInterop_EmittedParticle.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef WI_SHADERINTEROP_EMITTEDPARTICLE_H
#define WI_SHADERINTEROP_EMITTEDPARTICLE_H
#include "ShaderInterop.h"
#include "ShaderInterop_Renderer.h"
struct Particle
{
float3 position;
float mass;
float3 force;
float rotationalVelocity;
float3 velocity;
float maxLife;
float2 sizeBeginEnd;
float life;
uint color;
};
struct ParticleCounters
{
uint aliveCount;
uint deadCount;
uint realEmitCount;
uint aliveCount_afterSimulation;
uint culledCount;
uint cellAllocator;
};
static const uint PARTICLECOUNTER_OFFSET_ALIVECOUNT = 0;
static const uint PARTICLECOUNTER_OFFSET_DEADCOUNT = PARTICLECOUNTER_OFFSET_ALIVECOUNT + 4;
static const uint PARTICLECOUNTER_OFFSET_REALEMITCOUNT = PARTICLECOUNTER_OFFSET_DEADCOUNT + 4;
static const uint PARTICLECOUNTER_OFFSET_ALIVECOUNT_AFTERSIMULATION = PARTICLECOUNTER_OFFSET_REALEMITCOUNT + 4;
static const uint PARTICLECOUNTER_OFFSET_CULLEDCOUNT = PARTICLECOUNTER_OFFSET_ALIVECOUNT_AFTERSIMULATION + 4;
static const uint PARTICLECOUNTER_OFFSET_CELLALLOCATOR = PARTICLECOUNTER_OFFSET_CULLEDCOUNT + 4;
static const uint EMITTER_OPTION_BIT_FRAME_BLENDING_ENABLED = 1 << 0;
static const uint EMITTER_OPTION_BIT_SPH_ENABLED = 1 << 1;
static const uint EMITTER_OPTION_BIT_MESH_SHADER_ENABLED = 1 << 2;
static const uint EMITTER_OPTION_BIT_COLLIDERS_DISABLED = 1 << 3;
static const uint EMITTER_OPTION_BIT_USE_RAIN_BLOCKER = 1 << 4;
static const uint EMITTER_OPTION_BIT_TAKE_COLOR_FROM_MESH = 1 << 5;
CBUFFER(EmittedParticleCB, CBSLOT_OTHER_EMITTEDPARTICLE)
{
ShaderTransform xEmitterTransform;
ShaderTransform xEmitterBaseMeshUnormRemap;
uint xEmitCount;
float xEmitterRandomness;
float xParticleRandomColorFactor;
float xParticleSize;
float xParticleScaling;
float xParticleRotation;
float xParticleRandomFactor;
float xParticleNormalFactor;
float xParticleLifeSpan;
float xParticleLifeSpanRandomness;
float xParticleMass;
float xParticleMotionBlurAmount;
uint xEmitterMaxParticleCount;
uint xEmitterInstanceIndex;
uint xEmitterMeshGeometryOffset;
uint xEmitterMeshGeometryCount;
uint2 xEmitterFramesXY;
uint xEmitterFrameCount;
uint xEmitterFrameStart;
float2 xEmitterTexMul;
float xEmitterFrameRate;
uint xEmitterLayerMask;
float xSPH_h; // smoothing radius
float xSPH_h_rcp; // 1.0f / smoothing radius
float xSPH_h2; // smoothing radius ^ 2
float xSPH_h3; // smoothing radius ^ 3
float xSPH_poly6_constant; // precomputed Poly6 kernel constant term
float xSPH_spiky_constant; // precomputed Spiky kernel function constant term
float xSPH_visc_constant; // precomputed viscosity kernel function constant term
float xSPH_K; // pressure constant
float xSPH_e; // viscosity constant
float xSPH_p0; // reference density
uint xEmitterOptions;
float xEmitterFixedTimestep; // we can force a fixed timestep (>0) onto the simulation to avoid blowing up
float3 xParticleGravity;
float xEmitterRestitution;
float3 xParticleVelocity;
float xParticleDrag;
};
static const uint THREADCOUNT_EMIT = 256;
static const uint THREADCOUNT_MESH_SHADER = 32;
static const uint ARGUMENTBUFFER_OFFSET_DISPATCHEMIT = 0;
static const uint ARGUMENTBUFFER_OFFSET_DISPATCHSIMULATION = wi::graphics::AlignTo(ARGUMENTBUFFER_OFFSET_DISPATCHEMIT + (3 * 4), IndirectDispatchArgsAlignment);
static const uint ARGUMENTBUFFER_OFFSET_DRAWPARTICLES = wi::graphics::AlignTo(ARGUMENTBUFFER_OFFSET_DISPATCHSIMULATION + (3 * 4), IndirectDrawArgsAlignment);
// If this is not defined, SPH will be resolved as N-body simulation (O(n^2) complexity)
// If this is defined, SPH will be sorted into a hashed grid structure and response lookup will be accelerated
#define SPH_USE_ACCELERATION_GRID
static const uint SPH_PARTITION_BUCKET_COUNT = 128 * 128 * 64;
#ifdef SPH_USE_ACCELERATION_GRID
static const uint THREADCOUNT_SIMULATION = 64;
#else
static const uint THREADCOUNT_SIMULATION = 256;
#endif // SPH_USE_ACCELERATION_GRID
inline uint SPH_GridHash(int3 cellIndex)
{
const uint p1 = 73856093; // some large primes
const uint p2 = 19349663;
const uint p3 = 83492791;
int n = p1 * cellIndex.x ^ p2*cellIndex.y ^ p3*cellIndex.z;
n %= SPH_PARTITION_BUCKET_COUNT;
return n;
}
struct SPHGridCell
{
uint count;
uint offset;
};
// 27 neighbor offsets in a 3D grid, including center cell:
static const int3 sph_neighbor_offsets[27] = {
int3(-1, -1, -1),
int3(-1, -1, 0),
int3(-1, -1, 1),
int3(-1, 0, -1),
int3(-1, 0, 0),
int3(-1, 0, 1),
int3(-1, 1, -1),
int3(-1, 1, 0),
int3(-1, 1, 1),
int3(0, -1, -1),
int3(0, -1, 0),
int3(0, -1, 1),
int3(0, 0, -1),
int3(0, 0, 0),
int3(0, 0, 1),
int3(0, 1, -1),
int3(0, 1, 0),
int3(0, 1, 1),
int3(1, -1, -1),
int3(1, -1, 0),
int3(1, -1, 1),
int3(1, 0, -1),
int3(1, 0, 0),
int3(1, 0, 1),
int3(1, 1, -1),
int3(1, 1, 0),
int3(1, 1, 1),
};
#endif // WI_SHADERINTEROP_EMITTEDPARTICLE_H