MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Sim

Method Sim

Source/Engine/Particles/Graph/GPU/GPUParticles.cpp:169–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167}
168
169void GPUParticles::Sim(GPUContext* context, ParticleEmitter* emitter, ParticleEffect* effect, int32 emitterIndex, ParticleEmitterInstance& data)
170{
171 PROFILE_CPU_ASSET(emitter);
172 const bool hasCB = _cbData.HasItems();
173 const int32 threads = data.Buffer->GPU.ParticlesCountMax + data.GPU.SpawnCount;
174 const uint32 counterOffset = data.Buffer->GPU.ParticleCounterOffset;
175 SceneRenderTask* viewTask = effect->GetRenderTask();
176
177 // Setup parameters
178 MaterialParameter::BindMeta bindMeta;
179 bindMeta.Context = context;
180 bindMeta.Constants = hasCB ? ToSpan(_cbData).Slice(sizeof(GPUParticlesData)) : Span<byte>(nullptr, 0);
181 bindMeta.Input = nullptr;
182 if (viewTask)
183 {
184 bindMeta.Buffers = viewTask->Buffers;
185 bindMeta.CanSampleDepth = bindMeta.CanSampleGBuffer = bindMeta.Buffers && bindMeta.Buffers->GetWidth() != 0;
186 }
187 else
188 {
189 bindMeta.Buffers = nullptr;
190 bindMeta.CanSampleDepth = bindMeta.CanSampleGBuffer = false;
191 }
192 ASSERT(data.Parameters.Count() <= _params.Count());
193 for (int32 i = 0; i < data.Parameters.Count(); i++)
194 {
195 // Copy instance parameters values
196 _params[i].SetValue(data.Parameters.Get()[i]);
197 }
198 MaterialParamsLink link;
199 link.This = &_params;
200 link.Up = link.Down = nullptr;
201 MaterialParams::Bind(&link, bindMeta);
202
203 // Setup constant buffer
204 if (hasCB)
205 {
206 auto cbData = (GPUParticlesData*)_cbData.Get();
207 if (viewTask)
208 {
209 auto& view = viewTask->View;
210
211 Matrix::Transpose(view.PrevViewProjection, cbData->ViewProjectionMatrix);
212
213 Matrix tmp;
214 Matrix::Invert(view.PrevViewProjection, tmp);
215 Matrix::Transpose(tmp, cbData->InvViewProjectionMatrix);
216
217 Matrix::Invert(view.PrevView, tmp);
218 Matrix::Transpose(tmp, cbData->InvViewMatrix);
219
220 Matrix::Transpose(view.PrevView, cbData->ViewMatrix);
221
222 cbData->ViewPos = view.Position;
223 cbData->ViewFar = view.Far;
224 cbData->ViewDir = view.Direction;
225 cbData->ViewInfo = view.ViewInfo;
226 cbData->ScreenSize = view.ScreenSize;

Callers 1

UpdateGPUFunction · 0.80

Calls 15

BindFunction · 0.85
DivideAndRoundUpFunction · 0.85
GetRenderTaskMethod · 0.80
SliceMethod · 0.80
GetWidthMethod · 0.80
GetLocalToWorldMatrixMethod · 0.80
ToSpanFunction · 0.50
TransposeFunction · 0.50
InvertFunction · 0.50
MinFunction · 0.50
HasItemsMethod · 0.45
CountMethod · 0.45

Tested by

no test coverage detected