public void Construct(ComputeBuffer <Particle> sortedParticles, ComputeBuffer <Vector3f> matterParticles, ComputeBuffer <Vector3f> boundaryParticles)
        {
            int numAllParticles    = sortedParticles.Count;
            int numMatterParticles = matterParticles.Count;

            NeighboursMapShader.SetFloat("CellSize", (float)cellSize);
            NeighboursMapShader.SetFloat("InvCellSize", 1f / cellSize);

            NeighboursMapShader.SetFloat("AcceptenceRadius", cellSize);
            NeighboursMapShader.SetInt("NumAllParticles", (int)numAllParticles);
            NeighboursMapShader.SetInt("NumMatterParticles", (int)numMatterParticles);

            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "NeighbourShifts", NeighbourShifts);

            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "MatterParticlesCoords", matterParticles);
            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "BoundaryParticlesCoords", boundaryParticles);
            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "SortedParticles", sortedParticles);

            if (NeighboursMap == null)
            {
                NeighboursMap = new ComputeBuffer <uint>((int)MAX_NEIGHBOURS * numMatterParticles);
                NumNeighbours = new ComputeBuffer <uint>(numMatterParticles);
            }

            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "NeighboursMap", NeighboursMap);
            NeighboursMapShader.SetBuffer(KERNEL_ID_CONSTRUCT, "NumNeighbours", NumNeighbours);

            NeighboursMapShader.Dispatch(KERNEL_ID_CONSTRUCT, ShaderHelper.GetNumberOfDispatchGroups(numMatterParticles, (int)BLOCK_SIZE), 1, 1);;
        }
        internal void ComputeViscosity()
        {
            //calc grad
            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "NeighboursMap", NeighboursSearcher.NeighboursMap);
            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "NumNeighbours", NeighboursSearcher.NumNeighbours);

            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "Predicted", GPUPredicted);

            if (GPUVelocitiesDelta == null)
            {
                GPUVelocitiesDelta = new ComputeBuffer(GPUVelocities.Count, GPUVelocities.ItemSize);
            }

            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "Velocities", GPUVelocities);
            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "VelocitiesDelta", GPUVelocitiesDelta);

            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityVelocityGradStep, "Densities", GPUDensities);

            CurrentShader.Dispatch(KERNEL_ID_ComputeViscosityVelocityGradStep, ShaderHelper.GetNumberOfDispatchGroups(NumParticles, BLOCK_SIZE), 1, 1);

            //upd velocities using calculated grad
            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityUpdateVelocityStep, "Velocities", GPUVelocities);
            CurrentShader.SetBuffer(KERNEL_ID_ComputeViscosityUpdateVelocityStep, "VelocitiesDelta", GPUVelocitiesDelta);

            CurrentShader.Dispatch(KERNEL_ID_ComputeViscosityUpdateVelocityStep, ShaderHelper.GetNumberOfDispatchGroups(NumParticles, BLOCK_SIZE), 1, 1);
        }
Exemple #3
0
        private void EstimatePositions(float dt)
        {
            int _kernel = CurrentShader.FindKernel("EstimatePositions");

            CurrentShader.SetBuffer(_kernel, "Velocities", Body.GPUVelocities);
            CurrentShader.SetBuffer(_kernel, "Positions", Body.GPUPositions);
            CurrentShader.SetBuffer(_kernel, "Predicted", Body.GPUPredicted);

            CurrentShader.Dispatch(_kernel, ShaderHelper.GetNumberOfDispatchGroups(Body.NumParticles, BLOCK_SIZE), 1, 1);
        }
        public override void ApplyForce(double dt, Body3d body)
        {
            string BufferName = "Velocities";

            CurrentShader.SetBuffer(_kernel, BufferName, body.GPUVelocities);
            CurrentShader.SetFloat("Gravity", (float)Gravity.y);
            CurrentShader.SetFloat("dt", (float)dt);
            CurrentShader.SetInt("MatterParticles", body.NumParticles);

            CurrentShader.Dispatch(_kernel, ShaderHelper.GetNumberOfDispatchGroups(body.NumParticles, BLOCK_SIZE), 1, 1);
        }
Exemple #5
0
        public void PrepareData(ComputeBuffer <Vector3f> elements)
        {
            int numAll = elements.Count;

            SortDataPrepearerShader.SetBuffer(KERNEL_ID_CONVERT, "Input", elements);

            if (Prepeared == null)
            {
                Prepeared = new ComputeBuffer <Particle>(numAll);
            }

            SortDataPrepearerShader.SetBuffer(KERNEL_ID_CONVERT, "Output", Prepeared);
            SortDataPrepearerShader.Dispatch(KERNEL_ID_CONVERT, ShaderHelper.GetNumberOfDispatchGroups(numAll, (int)BLOCK_SIZE), 1, 1);
        }
        internal override void ConstrainPositions(double di)
        {
            FluidBody3d fluid = Body as FluidBody3d;

            fluid.NeighboursSearcher.NeighbourhoodSearch(fluid.GPUPredicted, Boundary.GPUPositions);

            CurrentShader.SetInt("FluidNumParticles", fluid.NumParticles);
            //pre step(Calcuclate Density, Calculate Lambda Coeffs)
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "NeighboursMap", fluid.NeighboursSearcher.NeighboursMap);
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "NumNeighbours", fluid.NeighboursSearcher.NumNeighbours);

            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "FluidPositions", fluid.GPUPositions);
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "FluidPredicted", fluid.GPUPredicted);
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "FluidDensities", fluid.GPUDensities);
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "FluidLambda", fluid.GPULambda);

            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "BoundaryPositions", Boundary.GPUPositions);
            CurrentShader.SetBuffer(KERNEL_ID_PRESTEP, "BoundaryPsi", Boundary.GPUPsi);

            //constraint
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "NeighboursMap", fluid.NeighboursSearcher.NeighboursMap);
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "NumNeighbours", fluid.NeighboursSearcher.NumNeighbours);

            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "FluidPositions", fluid.GPUPositions);
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "FluidPredicted", fluid.GPUPredicted);
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "FluidDensities", fluid.GPUDensities);
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "FluidLambda", fluid.GPULambda);

            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "BoundaryPositions", Boundary.GPUPositions);
            CurrentShader.SetBuffer(KERNEL_DENSITYCONSTRAINT, "BoundaryPsi", Boundary.GPUPsi);

            int iter = 0;

            while (iter < Iterations)
            {
                //pre step(Calcuclate Density, Calculate Lambda Coeffs)
                CurrentShader.Dispatch(KERNEL_ID_PRESTEP, ShaderHelper.GetNumberOfDispatchGroups(fluid.NumParticles, BLOCK_SIZE), 1, 1);

                //constraint
                CurrentShader.Dispatch(KERNEL_DENSITYCONSTRAINT, ShaderHelper.GetNumberOfDispatchGroups(fluid.NumParticles, BLOCK_SIZE), 1, 1);

                iter++;
            }
        }
Exemple #7
0
        public void PrepareData(ComputeBuffer <Vector3f> matterParticles, ComputeBuffer <Vector3f> boundaryParticles)
        {
            int numAll = matterParticles.Count + boundaryParticles.Count;

            int numMatterParticles = matterParticles.Count;

            SortDataPrepearerShader.SetInt("NumMatterParticles", numMatterParticles);

            SortDataPrepearerShader.SetBuffer(KERNEL_ID_CONVERT, "InputMatterParticles", matterParticles);
            SortDataPrepearerShader.SetBuffer(KERNEL_ID_CONVERT, "InputBoundaryParticles", boundaryParticles);

            if (Prepeared == null)
            {
                Prepeared = new ComputeBuffer <Particle>(numAll);
            }

            SortDataPrepearerShader.SetBuffer(KERNEL_ID_CONVERT, "Output", Prepeared);
            SortDataPrepearerShader.Dispatch(KERNEL_ID_CONVERT, ShaderHelper.GetNumberOfDispatchGroups(numAll, (int)BLOCK_SIZE), 1, 1);
        }