public override void UpdatePreIntegrate(int nx) { if (cpuSources.Count == 0) { return; } int ns = Mathf.CeilToInt((float)gpuSourceNumber / ShaderConstants.SPAWN_BLOCKSIZE_X); spawnShader.Dispatch(spawnHandle, ns, 1, 1); //for profiling (forces GPU-CPU sync) //sources.GetData(cpuSources.ToArray()); //Check to see if the GPU souces are spewing too many/too few particles bool dirty = false; for (int i = 0; i < sourceInfo.Count; i++) { if (sourceInfo[i].availableParticles < 0 && cpuSources[i].spawnPeriod > 0 || sourceInfo[i].availableParticles > 0 && cpuSources[i].spawnPeriod < 0) { ShaderConstants.Source s = cpuSources[i]; s.spawnPeriod *= -1; cpuSources[i] = s; dirty = true; } } if (dirty) { syncBuffers(); } }
/* * Need to extend soucres so that it's a multiple of the blocksize */ private static ShaderConstants.Source[] extendSources(List <ShaderConstants.Source> list) { int length = ShaderConstants.SPAWN_BLOCKSIZE_X * Mathf.CeilToInt((float)list.Count / ShaderConstants.SPAWN_BLOCKSIZE_X); ShaderConstants.Source[] sload = new ShaderConstants.Source[length]; for (int i = 0; i < list.Count; i++) { sload[i] = list[i]; } for (int i = list.Count; i < length; i++) { sload[i].spawnPeriod = 0x7FFFFFFF; } return(sload); }
public int AddSource(ShaderConstants.Source s, int availableParticles = 250000) { //Add the new source to cpu int location = cpuSources.Count; cpuSources.Add(s); //Start info sourceInfo.Add(new SourceInfo(availableParticles, Mathf.CeilToInt(pm.ParticleLifeEnd / pm.TimeStep))); //keep track of statistics for updating available/unavailable particles //we use update in SourceInfo to get an estimate, but that only accounts for particle death from their lifetime. ps.ComputeModifierStatistics(ShaderConstants.PARTICLE_MODIFIER_SPAWN, location, (_, e) => { sourceInfo[location].instancedParticles = ((ParticleStatisticsModifierEventArgs)e).sum[1]; sourceInfo[location].availableParticles = sourceInfo[location].totalParticles - ((ParticleStatisticsModifierEventArgs)e).sum[1]; }); syncBuffers(); return(location); }
public void updateSource(int i, ShaderConstants.Source s) { cpuSources[i] = s; syncBuffers(); }