void CreateTexture() { System.Diagnostics.Stopwatch timer = System.Diagnostics.Stopwatch.StartNew(); texture = new Texture3D(data.size, data.size, data.size, format, false); texture.filterMode = filter; texture.wrapMode = wrap; int totalPixels = data.size * data.size * data.size; //float[] pixels = new float[totalPixels]; Color[] pixels = new Color[totalPixels]; ComputeBuffer cb = new ComputeBuffer(totalPixels, sizeof(float) * 4); cs.SetBuffer(0, "Result", cb); cs.SetInt("Size", data.size); cs.SetInts("Octaves", data.octaves); cs.SetInts("Inverts", data.inverts); cs.SetFloats("Freqs", data.freqs); cs.Dispatch(0, data.size / 8, data.size / 8, data.size / 8); cb.GetData(pixels); cb.Release(); //texture.SetPixelData<float>(pixels, 0); texture.SetPixels(pixels); texture.Apply(); pixels = null; status = "Completed in: " + timer.Elapsed.ToString(); timer.Stop(); CloudPreviewer.ShowTexture(texture); }
private void updateParams() { config.Apply(computeShader); computeShader.SetInts("TransmittanceSize", transmittanceSize.x, transmittanceSize.y); computeShader.SetInts("ScatteringSize", scatteringSize.x, scatteringSize.y, scatteringSize.z); computeShader.SetInts("IrradianceSize", irradianceSize.x, irradianceSize.y); }
private void OnEnable() { _camera.AddCommandBuffer(_cameraEvent, _commandBuffer); _positionHistoryBuffer = new ComputeBuffer[_historySize]; for (int i = 0; i < _historySize; i++) { _positionHistoryBuffer[i] = new ComputeBuffer(BUFFER_SIZE, sizeof(float) * 4); } _currentHistoryIndex = 0; _particlePositionBuffer = new ComputeBuffer(BUFFER_SIZE, sizeof(float) * 4); _scratchPositionBuffer = new ComputeBuffer(BUFFER_SIZE, sizeof(float) * 4); { // init particle buffer _kernelShader.SetBuffer(_kernelInitParticleBuffer, _idParticlePositionBuffer, _particlePositionBuffer); _kernelShader.SetInt(_idBufferSize, BUFFER_SIZE); _kernelShader.SetInts(_idResolution, INPUT_WIDTH, INPUT_HEIGHT); const int threadsPerGroup = 512; int groupsX = BUFFER_SIZE / threadsPerGroup; _kernelShader.Dispatch(_kernelInitParticleBuffer, groupsX, 1, 1); } { // init mesh indices buffer _meshIndicesBuffer = new ComputeBuffer(_meshIndices.Length, sizeof(uint)); _meshIndicesBuffer.SetData(_meshIndices); } }
internal void InjectObject(Matrix4x4 viewProj, int kernel, VaporObject obj) { if (kernel == -1) { return; } m_worldBounds.Clear(); obj.GetBounds(transform, m_worldBounds); Bounds uvBounds = new Bounds(GetUvFromWorld(obj.transform.position, viewProj), Vector3.one * 0.05f); for (int i = 0; i < m_worldBounds.Count; i++) { Vector3 uv = GetUvFromWorld(m_worldBounds[i], viewProj); uvBounds.Encapsulate(uv); } Vector3 min = uvBounds.min; Vector3 max = uvBounds.max; m_offset[0] = Mathf.FloorToInt(min.x * m_densityTex.width); m_offset[1] = Mathf.FloorToInt(min.y * m_densityTex.height); m_offset[2] = Mathf.FloorToInt(min.z * m_densityTex.volumeDepth); m_vaporCompute.SetInts("_LightWriteLower", m_offset); int maxX = Mathf.CeilToInt(max.x * m_densityTex.width); int maxY = Mathf.CeilToInt(max.y * m_densityTex.height); int maxZ = Mathf.CeilToInt(max.z * m_densityTex.volumeDepth); Profiler.BeginSample("Object pass"); m_vaporCompute.DispatchScaled(kernel, maxX - m_offset[0], maxY - m_offset[1], maxZ - m_offset[2]); Profiler.EndSample(); }
void Start() { Shader.SetGlobalVector(_idPhysicsGridSize, _size); Shader.SetGlobalVector(_idPhysicsGridSizeInv, invSize); Shader.SetGlobalTexture(_idPhysicsGridPositionTex, _positionTexture); Shader.SetGlobalTexture(_idPhysicsGridVelocityTex, _velocityTexture); // // move this stuff to command buffer _computeShader.SetInts(_idPhysicsGridResolution, _resolution.x, _resolution.y, _resolution.z); _computeShader.SetVector(_idPhysicsGridSize, _size); _computeShader.SetVector(_idPhysicsGridSizeInv, invSize); _computeShader.SetTexture(_kernelInit, _idPhysicsGridPositionTex, _positionTexture); _computeShader.SetTexture(_kernelInit, _idPhysicsGridVelocityTex, _velocityTexture); const int groupSizeDim = 8; _groupsX = (_resolution.x + groupSizeDim - 1) / groupSizeDim; _groupsY = (_resolution.y + groupSizeDim - 1) / groupSizeDim; _groupsZ = (_resolution.z + groupSizeDim - 1) / groupSizeDim; _computeShader.Dispatch(_kernelInit, _groupsX, _groupsY, _groupsZ); _computeShader.SetTexture(_kernelStartGrab, _idPhysicsGridPositionTex, _positionTexture); _computeShader.SetTexture(_kernelStartGrab, _idPhysicsGridVelocityTex, _velocityTexture); _computeShader.SetTexture(_kernelEndGrab, _idPhysicsGridPositionTex, _positionTexture); _computeShader.SetTexture(_kernelEndGrab, _idPhysicsGridVelocityTex, _velocityTexture); _computeShader.SetTexture(_kernelUpdatePosition, _idPhysicsGridPositionTex, _positionTexture); _computeShader.SetTexture(_kernelUpdatePosition, _idPhysicsGridVelocityTex, _velocityTexture); _computeShader.SetTexture(_kernelUpdateVelocity, _idPhysicsGridPositionTex, _positionTexture); _computeShader.SetTexture(_kernelUpdateVelocity, _idPhysicsGridVelocityTex, _velocityTexture); _computeShader.SetTexture(_kernelSetRandomVelocity, _idPhysicsGridVelocityTex, _velocityTexture); }
void CreateRenderTexture(int width, int height) { texture = new RenderTexture(width, height, 1); texture.enableRandomWrite = true; texture.Create(); shader.SetInts("TextureResolution", new int[] { texture.width, texture.height }); }
public PackedUniformVolume ReduceOnce(PackedUniformVolume srcPackedUniformVolume) { var srcPackedVolumeElementCount = srcPackedUniformVolume.Voxels.Length; var srcPackedVolume = new ComputeBuffer(srcPackedVolumeElementCount, sizeof(uint)); srcPackedVolume.SetData(srcPackedUniformVolume.Voxels); _reduceOneComputeShader.SetBuffer(_reduceOneKernelId, "src_packed_volume", srcPackedVolume); var srcPackedVolumeDimensions = srcPackedUniformVolume.GetVolumeBitDimensions(); _reduceOneComputeShader.SetInts("src_packed_volume_bit_dimensions", srcPackedVolumeDimensions.x, srcPackedVolumeDimensions.y, srcPackedVolumeDimensions.z); var dstPackedVolumeElementCount = math.max(1, srcPackedVolumeElementCount / 2); var dstPackedVolume = new ComputeBuffer(dstPackedVolumeElementCount, sizeof(uint)); _reduceOneComputeShader.SetBuffer(_reduceOneKernelId, "dst_packed_volume", dstPackedVolume); var dstPackedVolumeDimensions = srcPackedVolumeDimensions / 2; _reduceOneComputeShader.SetInts("dst_packed_volume_bit_dimensions", dstPackedVolumeDimensions.x, dstPackedVolumeDimensions.y, dstPackedVolumeDimensions.z); var dispatchVolumeDimensions = math.max(new int3(1), dstPackedVolumeDimensions / 8); _reduceOneComputeShader.Dispatch( _reduceOneKernelId, dispatchVolumeDimensions.x, dispatchVolumeDimensions.y, dispatchVolumeDimensions.z ); var dstPackedVolumeData = new uint[srcPackedVolumeElementCount / 2]; dstPackedVolume.GetData(dstPackedVolumeData); srcPackedVolume.Release(); dstPackedVolume.Release(); return(new PackedUniformVolume( srcPackedUniformVolume.VoxelWorldScaleInMeters * 2, srcPackedUniformVolume.Depth - 1) { Voxels = dstPackedVolumeData }); }
private void LinkToFluidSimulation() { float fResolutionRatio = Resolution / (float)m_nParticlesResolution; SetSize((int)(m_nParticlesWidth * fResolutionRatio), (int)(m_nParticlesHeight * fResolutionRatio)); InitShaders(); m_particleAreaShader.SetInts("_VelocitySize", new int[] { GetWidth(), GetHeight() }); }
private void LinkToFluidSimulation() { float fResolutionRatio = m_simulation.Resolution / (float)m_nResolution; m_simulation.SetSize((int)(m_nWidth * fResolutionRatio), (int)(m_nHeight * fResolutionRatio)); m_simulation.InitShaders(); m_advectParticles.SetInts("_VelocitySize", new int[] { m_simulation.GetWidth(), m_simulation.GetHeight() }); }
void InitComputeShader() { kernelCreateCylinderPsi = CS.FindKernel("CreateCylinderPsi"); kernelInitPsi = CS.FindKernel("InitPsi"); ParticleMan.InitMultiKindKernels(CS, "InitParticles", out kernelInitParticles); CS.SetVector("size", isf.size); int[] res = isf.GetGrids(); CS.SetInts("res", res); CS.SetInts("grids", res); }
void SetSurfaceReconstructionParameters() { surfaceReconstruction = Resources.Load <ComputeShader>("Shaders/SurfaceReconstruction"); surfaceReconstruction.SetFloat("timestep", timeStep); surfaceReconstruction.SetFloat("particle_radius", particleRadius); surfaceReconstruction.SetFloat("cell_size", cellSize); surfaceReconstruction.SetInts("grid_dimensions", new int[] { gridDimensions.x, gridDimensions.y, gridDimensions.z }); surfaceReconstruction.SetFloat("mc_cell_size", marchingCubesCellSize); surfaceReconstruction.SetInts("mc_grid_dimensions", new int[] { marchingCubesGridDimensions.x, marchingCubesGridDimensions.y, marchingCubesGridDimensions.z }); surfaceReconstruction.SetInt("mc_num_grid_points", marchingCubeGridPointCount); }
void Start() { var nrrd = new NRRD(ct); kernel = slicer.FindKernel("CSMain"); var buf = new ComputeBuffer(nrrd.data.Length, sizeof(float)); buf.SetData(nrrd.data); slicer.SetBuffer(kernel, "data", buf); slicer.SetInts("dims", nrrd.dims); }
void InitDraw() { if (m_DeviceShader != null) { #if UNITY_5_3_7 || UNITY_5_3_8 || UNITY_5_3_6 m_DeviceShader.SetInts(_ciScreenSize, BackSurfaceWidth, BackSurfaceHeight); #else m_DeviceShader.SetInts(m_ScreenSizeId, BackSurfaceWidth, BackSurfaceHeight); #endif } }
public void SetTensor(string name, TensorShape shape, ComputeBuffer buffer, Int64 dataOffset = 0) { var shapeId = Shader.PropertyToID(name + "declShape"); var infoId = Shader.PropertyToID(name + "declInfo"); var dataId = Shader.PropertyToID(name + "data"); int[] tensorShape = { shape.batch, shape.height, shape.width, shape.channels }; int[] tensorInfo = { (int)dataOffset, shape.length }; shader.SetInts(shapeId, tensorShape); shader.SetInts(infoId, tensorInfo); shader.SetBuffer(kernelIndex, dataId, buffer); }
override protected void InitializeComputeShader() { cs = Resources.Load <ComputeShader>("ComputeShader/ScreenSpaceFluidRendering/ScreenSpaceFluidRendering"); cs.SetInts("size", new int[] { dimensions.x * 16, dimensions.y * 16, dimensions.z * 16 }); cs2Mesh = cs.FindKernel("CA2Mesh"); blur = cs.FindKernel("HorizontalBlur"); cs.SetInts("blurDir", new int[] { 1, 0 }); cs.SetBuffer(cs2Mesh, "mesh", mesh); }
public void ReInit(VoxelBlock <Voxel> block) { int overlap = block.Overlap; int blockHeight = block.Height + 2 * overlap; int blockWidth = block.Width + 2 * overlap; int blockLength = block.Length + 2 * overlap; if (initHeight == blockHeight && initWidth == blockWidth && initLength == blockLength) { // we are already set up to process blocks of this size return; } Debug.LogFormat("reinit block ({0}, {1}, {2}) => ({3}, {4}, {5})", initWidth, initHeight, initLength, blockWidth, blockHeight, blockLength); initWidth = blockWidth; initHeight = blockHeight; initLength = blockLength; float[] dummyVoxels = new float[blockHeight * blockWidth * blockLength]; addPadding(ref dummyVoxels, ref blockWidth, ref blockHeight, ref blockLength); numBlocks = new Vector3Int((blockWidth - 1) / blockSize.x, (blockHeight - 1) / blockSize.y, (blockLength - 1) / blockSize.z); if (voxelBuffer != null) { voxelBuffer.Dispose(); } voxelBuffer = new ComputeBuffer(dummyVoxels.Length, sizeof(float)); if (minMaxBuffer != null) { minMaxBuffer.Dispose(); } minMaxBuffer = new ComputeBuffer(numBlocks.x * numBlocks.y * numBlocks.z, 2 * sizeof(float)); if (compactedBlkArray != null) { compactedBlkArray.Dispose(); } compactedBlkArray = new ComputeBuffer(numBlocks.x * numBlocks.y * numBlocks.z, sizeof(int)); PMBShader.SetBuffer(minMaxKernelIndex, "voxelBuffer", voxelBuffer); PMBShader.SetBuffer(minMaxKernelIndex, "minMaxBuffer", minMaxBuffer); PMBShader.SetInts("size", new int[] { blockWidth, blockHeight, blockLength }); PMBShader.SetInts("numBlocks", new int[] { numBlocks.x, numBlocks.y, numBlocks.z }); PMBShader.SetBuffer(compactActiveBlocksKernelIndex, "activeBlkNum", activeBlkNum); PMBShader.SetBuffer(compactActiveBlocksKernelIndex, "minMaxBuffer", minMaxBuffer); PMBShader.SetBuffer(compactActiveBlocksKernelIndex, "compactedBlkArray", compactedBlkArray); PMBShader.SetBuffer(generateTrianglesKernelIndex, "marchingCubesEdgeTable", marchingCubesEdgeTableBuffer); PMBShader.SetBuffer(generateTrianglesKernelIndex, "globalVertexOffset", globalVertexOffset); PMBShader.SetBuffer(generateTrianglesKernelIndex, "voxelBuffer", voxelBuffer); PMBShader.SetBuffer(generateTrianglesKernelIndex, "compactedBlkArray", compactedBlkArray); }
public void Init(int cubesPerAxis, float cubeSize) { //Kernal Kernel = FaceShader.FindKernel("FaceGenerator"); //Sets FaceShader.SetInts("VoxelDimensions", new int[3] { cubesPerAxis, cubesPerAxis, cubesPerAxis }); FaceShader.SetFloat("CubeSize", cubeSize); FaceShader.SetInt("CubesPerAxis", cubesPerAxis); }
// position in normalised local space // fRadius in world space public void AddObstacleCircle(Vector2 position, float fRadius, bool bStatic = false) { if (m_addObstacleCircle != null) { float[] pos = { position.x, position.y }; m_addObstacleCircle.SetFloats("_Position", pos); m_addObstacleCircle.SetFloat("_Radius", fRadius); m_addObstacleCircle.SetInt("_Static", bStatic ? 1 : 0); m_addObstacleCircle.SetInts("_Size", new int[] { m_nWidth, m_nHeight }); m_addObstacleCircle.SetBuffer(0, "_Buffer", m_obstaclesBuffer); m_addObstacleCircle.Dispatch(0, m_nNumGroupsX, m_nNumGroupsY, 1); } }
void UpdateClusterCBuffer(ComputeShader cs) { int[] gridDims = { m_DimData.clusterDimX, m_DimData.clusterDimY, m_DimData.clusterDimZ }; int[] sizes = { m_ClusterGridBlockSize, m_ClusterGridBlockSize }; Vector4 screenDim = new Vector4((float)Screen.width, (float)Screen.height, 1.0f / Screen.width, 1.0f / Screen.height); float viewNear = m_DimData.zNear; cs.SetInts(ShaderIDs.ClusterCB_GridDim, gridDims); cs.SetInts(ShaderIDs.ClusterCB_Size, sizes); cs.SetFloat(ShaderIDs.ClusterCB_ViewNear, viewNear); cs.SetFloat(ShaderIDs.ClusterCB_NearK, 1.0f + m_DimData.sD); cs.SetFloat(ShaderIDs.ClusterCB_LogGridDimY, m_DimData.logDimY); cs.SetVector(ShaderIDs.ClusterCB_ScreenDimensions, screenDim); }
void DirectionalCopyGV(int orientation) { /* orientation is 0 for X (right), 1 for Y (up), 2 for Z (forward) of the shadow camera */ Vector3 DX = Vector3.zero; Vector3 DY = Vector3.zero; Vector3 DZ = Vector3.zero; DZ[orientation] = 1f; DX[(orientation + 1) % 3] = 1f; DY[(orientation + 2) % 3] = 1f; _light_forward = (_light_local_to_world_matrix * DZ).normalized; int directional_copy_kernel = gvCompute.FindKernel("DirectionalCopy"); gvCompute.SetInts("DX", (int)DX.x, (int)DX.y, (int)DX.z); gvCompute.SetInts("DY", (int)DY.x, (int)DY.y, (int)DY.z); gvCompute.SetInts("DZ", (int)DZ.x, (int)DZ.y, (int)DZ.z); for (int i = 1; i < numCascades; i++) { gvCompute.SetTexture(directional_copy_kernel, "Input_gv", _tex3d_gvs[i - 1]); gvCompute.SetTexture(directional_copy_kernel, "LPV_gv", _tex3d_gvs[i]); int thread_groups = (gridResolution + 7) / 8; //gvCompute.Dispatch(directional_copy_kernel, thread_groups, thread_groups, thread_groups); } }
void Start() { var nrrd = new NRRD(ct); //GetComponent<Transform>().localPosition = nrrd.origin; //GetComponent<Transform>().localScale = Vector3.Scale(nrrd.scale, new Vector3(nrrd.dims[0], nrrd.dims[1], nrrd.dims[2])); kernel = slicer.FindKernel("CSMain"); var buf = new ComputeBuffer(nrrd.data.Length, sizeof(float)); buf.SetData(nrrd.data); slicer.SetBuffer(kernel, "data", buf); slicer.SetInts("dims", nrrd.dims); }
public void Accumulate4(ComputeBuffer grid4, int width, int height, ComputeBuffer outputBuf) { using (var lineoutBuf = new DisposableBuffer(height, STRIDE_OF_VECTOR4)) { cs.SetInts(PROP_INPUT_SIZE, width, height); cs.SetBuffer(kernelAccumX4, PROP_INPUT4, grid4); cs.SetBuffer(kernelAccumX4, PROP_OUTPUT4, lineoutBuf); cs.Dispatch(kernelAccumX4, 1, Mathf.CeilToInt(height / (float)NUM_THREADS), 1); cs.SetInts(PROP_INPUT_SIZE, 1, height); cs.SetBuffer(kernelAccumY4, PROP_INPUT4, lineoutBuf); cs.SetBuffer(kernelAccumY4, PROP_OUTPUT4, outputBuf); cs.Dispatch(kernelAccumY4, 1, 1, 1); } }
void SetCSData() { CS.SetVector("nozzle_ralative_center", nozzle_relative_center); CS.SetVector("nozzle_center", nozzle_center_in_shader); CS.SetFloat("nozzle_radius", nozzle_radius); CS.SetVector("nozzle_dir", nozzle_dir); CS.SetVector("nozzle_topleft", topleft); CS.SetFloat("nozzle_length", nozzle_length); CS.SetVector("nozzle_velocity", nozzle_velocity / isf.hbar); CS.SetVector("nozzle_right", nozzle_right); CS.SetVector("nozzle_up", nozzle_up); CS.SetVector("size", isf.size); CS.SetInts("res", isf.GetGrids()); CS.SetInts("grids", isf.GetGrids()); }
private void Advent(ComputeBuffer current, ComputeBuffer past, float timeStep) { AdventShader.SetFloat("TimeStep", timeStep); // DEBUG FRICTION! AdventShader.SetFloat("Dissipation", 0.99f); AdventShader.SetInts("MapSize", _mapSize.x, _mapSize.y); AdventShader.SetBuffer(_adventMain, "Current", current); AdventShader.SetBuffer(_adventMain, "Past", past); AdventShader.SetBuffer(_adventMain, "Velocity", _velocity.Past); AdventShader.SetBuffer(_adventMain, "Walls", _walls); AdventShader.Dispatch(_adventMain, _linearMapSize,//(int) math.ceil(_linearMapSize / 64f), 1, 1); }
// ******* 4.Befülle den GlobalCounterTree mit den Daten, wie viele Überschneidungstets es pro Zelle gibt ******* void _4_GlobalCounterTree() { m_CurComputeShader = m_ComputeShaderList[3]; int kernelID = m_CurComputeShader.FindKernel("main"); m_CurComputeShader.SetBuffer(kernelID, "counterTrees", m_CounterTrees_Buffer); m_CurComputeShader.SetBuffer(kernelID, "globalCounterTree", m_GlobalCounterTree_Buffer); m_CurComputeShader.SetInts("objectCount", m_FillCounterTreesData.objectCount); m_CurComputeShader.SetInts("treeSizeInLevel", Int4ArrayTo1DArray(m_FillCounterTreesData.treeSizeInLevel)); int xThreadGroups = (int)Mathf.Ceil(m_TreeSize / 1024.0f); m_CurComputeShader.Dispatch(kernelID, xThreadGroups, 1, 1); }
public static void SetInts (this ComputeShader shader, string name, Vector2Int args) { _intArgs2[0] = args.x; _intArgs2[1] = args.y; shader.SetInts(name, _intArgs2); }
// Adds a velocity splat to the simulation at /position with a specific /fRadius and /velocity. // /position: Centre of the splat as a normalised value [0-1] of the simulation space. // /fRadius: Radius of the splat in simulation space. // /velocity: Velocity at the centre of the splat. The value is linearly diffused towards the edges of the splat. public void AddVelocity(Vector2 position, Vector2 velocity, float fRadius) { if (m_simulationShader != null && m_velocityBuffer != null && m_velocityBuffer.Length >= 2) { float[] pos = { position.x, position.y }; m_simulationShader.SetFloats("_Position", pos); float[] val = { velocity.x, velocity.y }; m_simulationShader.SetFloats("_Value", val); m_simulationShader.SetFloat("_Radius", fRadius); m_simulationShader.SetInts("_Size", new int[] { m_nWidth, m_nHeight }); m_simulationShader.SetBuffer(m_addVelocityKernel, "_VelocityIn", m_velocityBuffer[VELOCITY_READ]); m_simulationShader.SetBuffer(m_addVelocityKernel, "_VelocityOut", m_velocityBuffer[VELOCITY_WRITE]); m_simulationShader.Dispatch(m_addVelocityKernel, m_nNumGroupsX, m_nNumGroupsY, 1); FlipVelocityBuffers(); } }
//void ComputeObstacles() //{ // if (m_computeObstacles != null) // { // for (int i = 0; i < windDataLODs.Count; ++i) // { // var data = windDataLODs[i]; // int kernel = 0; // m_computeObstacles.SetVector("_Size", data.size); // m_computeObstacles.SetBuffer(0, "_Write", data.m_obstacles); // m_computeObstacles.Dispatch( // kernel, // Mathf.CeilToInt(1.0f * data.width / NUM_THREADS), // Mathf.CeilToInt(1.0f * data.height / NUM_THREADS), // Mathf.CeilToInt(1.0f * data.depth / NUM_THREADS)); // } // } //} // ======================================================================================== // ================================ Compute Wind Data ===================================== #region ASSIGN_MATERAIAL static public void AssignBasicMaterial(ComputeShader shader, WindDataRuntime data) { shader.SetVector(WindAreaSizeID, data.basicData.WindAreaSize); shader.SetVector(WindAreaSizeInvID, data.basicData.WindAreaSizeInv); shader.SetFloat(WindResolutionID, data.basicData.WindResolution); shader.SetInts(WindDataTexSizeID, new int[] { data.width, data.height, data.depth }); }
public override IEnumerator SlowUpdate(int nx, float waitTime) { if (totalStatsNumber > 0) { ModifierHandlers m; for (int i = 0; i < modifiers.Count; i++) { m = modifiers[i]; //run mask over all particles to prepare input sum //see the shader for details on this PSShader.SetInts("modifier", new int[] { m.modifierType, m.modifierIndex }); PSShader.Dispatch(prepareModifierSumHandle, Mathf.CeilToInt((float)particleNumber / ShaderConstants.PARTICLE_BLOCK_SIZE), 1, 1); adder.Compute(); //Now sum over all particles //we wait to give time for computation yield return(new WaitForSeconds(waitTime)); //fetch the result int[] resultArray = new int[3]; result.GetData(resultArray); //no need to do a null check since we will have called computemodifierstatistics m.call(this, new ParticleStatisticsModifierEventArgs(m.modifierType, m.modifierIndex, resultArray)); //wait the rest of the time yield return(new WaitForSeconds(waitTime)); } } }
void SetSortParameters() { sortParticles = Resources.Load <ComputeShader>("Shaders/SortParticles"); sortParticles.SetInt("bin_count", binCount); sortParticles.SetFloat("cell_size", cellSize); sortParticles.SetInts("grid_dimensions", new int[] { gridDimensions.x, gridDimensions.y, gridDimensions.z }); }