public void Release()
 {
     ComputeShaderUtil.Destroy(gridBuffer);
     ComputeShaderUtil.Destroy(gridIndicesBuffer);
     ComputeShaderUtil.Destroy(gridPingPongBuffer);
     ComputeShaderUtil.Destroy(sortedObjectsBufferOutput);
 }
Exemplo n.º 2
0
        void SetComputeData()
        {
            int kernelId       = _ComputeFlock.FindKernel("CSMain");
            int numThreadGroup = BoidsCount / NUM_THREAD_X;

            _ComputeFlock.SetFloat("_GridH", sorter.GetGridH());
            _ComputeFlock.SetVector("_GridDim", gridDim);
            _ComputeFlock.SetFloat("DeltaTime", Time.deltaTime);
            _ComputeFlock.SetFloat("RotationSpeed", RotationSpeed);
            _ComputeFlock.SetFloat("BoidSpeed", BoidSpeed);
            _ComputeFlock.SetFloat("BoidSpeedVariation", BoidSpeedVariation);
            _ComputeFlock.SetVector("FlockPosition", Target.transform.position);
            _ComputeFlock.SetVector("PlaneNormal", _planeNormal);
            _ComputeFlock.SetVector("PlanePoint", _planePoint);
            _ComputeFlock.SetVector("SpherePos", Target.transform.position);
            _ComputeFlock.SetFloat("NeighbourDistance", NeighbourDistance);
            _ComputeFlock.SetInt("BoidsCount", BoidsCount);
            _ComputeFlock.SetInt("AffectorCount", AffectorCounts);
            _ComputeFlock.SetFloat("AffectorForce", AffectorForce);
            _ComputeFlock.SetFloat("AffectorDistance", AffectorDistance);
            _ComputeFlock.SetInt("useAffector", useAffector);
            _ComputeFlock.SetBuffer(kernelId, "_GridIndicesBufferRead", sorter.GetGridIndicesBuffer());
            _ComputeFlock.SetBuffer(kernelId, "boidBuffer_read", ParticleBoidBufferRead);
            _ComputeFlock.SetBuffer(kernelId, "boidBuffer_write", ParticleBoidBufferWrite);
            _ComputeFlock.SetBuffer(kernelId, "position_debug", ParticleGridPositionCheck);
            _ComputeFlock.SetBuffer(kernelId, "affector_write", BoidAffectorBuffer);
            _ComputeFlock.Dispatch(kernelId, numThreadGroup, 1, 1);
            //ComputeShaderUtil.Swap(ref ParticleBoidBufferWrite, ref ParticleBoidBufferRead);
            ComputeShaderUtil.Swap(ref ParticleBoidBufferRead, ref ParticleBoidBufferWrite);
        }
Exemplo n.º 3
0
 private void SetupShader()
 {
     _Shader = ComputeShaderUtil.FindComputeOrWarn(SHADERPATH, out _IsReady);
     if (_IsReady)
     {
         _Kernel = _Shader.FindKernelOrWarn(SHADERKERNEL, ref _IsReady);
     }
 }
 void ReleaseBuffer()
 {
     ComputeShaderUtil.Destroy(particleRO);
     ComputeShaderUtil.Destroy(particleRW);
     ComputeShaderUtil.Destroy(densityRO);
     ComputeShaderUtil.Destroy(densityRW);
     ComputeShaderUtil.Destroy(forceRO);
     ComputeShaderUtil.Destroy(forceRW);
 }
Exemplo n.º 5
0
    void Update()
    {
        var k = cs.FindKernel("CalcCurvature");

        cs.SetBuffer(k, "_Vrts", vrtBuff);
        cs.SetBuffer(k, "_Idxs", idxBuff);
        cs.SetBuffer(k, "_Table", tblBuff);
        cs.SetBuffer(k, "_Curvatures", colBuff);
        ComputeShaderUtil.Dispatch1D(cs, k, len);
    }
Exemplo n.º 6
0
        public void PigmentAdvection()
        {
            var k = moxi.FindKernel("Advection");

            moxi.SetTexture(k, "ForceV_R", lbe.ForceV);
            moxi.SetTexture(k, "ForceD_R", lbe.ForceD);
            moxi.SetTexture(k, "VelPhi_R", lbe.VelPhi_R);
            moxi.SetTexture(k, "Flow_R", flow.Read);
            moxi.SetTexture(k, "Flow_W", flow.Write);
            ComputeShaderUtil.Dispatch2D(moxi, k, w, h);
            flow.Swap();
        }
Exemplo n.º 7
0
        public void PigmentSupply()
        {
            var k = moxi.FindKernel("Supply");

            moxi.SetTexture(k, "Surf_R", surf.Read);
            moxi.SetTexture(k, "Surf_W", surf.Write);
            moxi.SetTexture(k, "Flow_R", flow.Read);
            moxi.SetTexture(k, "Flow_W", flow.Write);
            ComputeShaderUtil.Dispatch2D(moxi, k, w, h);
            flow.Swap();
            surf.Swap();
        }
Exemplo n.º 8
0
        public void PigmentFixture()
        {
            var k = moxi.FindKernel("Fixture");

            moxi.SetTexture(k, "Flow_R", flow.Read);
            moxi.SetTexture(k, "Flow_W", flow.Write);
            moxi.SetTexture(k, "Fixt_R", fixt.Read);
            moxi.SetTexture(k, "Fixt_W", fixt.Write);
            ComputeShaderUtil.Dispatch2D(moxi, k, w, h);
            flow.Swap();
            fixt.Swap();
        }
Exemplo n.º 9
0
        public void Simulation()
        {
            var k = cs.FindKernel("Simulation");

            cs.SetTexture(k, "Pinning", pinning);
            cs.SetTexture(k, "ForceV_R", forces[0].Read);
            cs.SetTexture(k, "ForceD_R", forces[1].Read);
            cs.SetTexture(k, "ForceR_R", forces[2].Read);
            cs.SetTexture(k, "VelPhi_R", velphi.Read);
            cs.SetTexture(k, "VelPhi_W", velphi.Write);
            ComputeShaderUtil.Dispatch2D(cs, k, w, h);
            velphi.Swap();
        }
Exemplo n.º 10
0
        public void Deposition(Vector2 mousePos, float brushWidth, float wtrSupply, float inkSupply)
        {
            var k = moxi.FindKernel("Deposition");

            moxi.SetVectorArray("_BrushHeads", CalcBrushHeads(mousePos, brushWidth));
            moxi.SetFloat("_WtrSupply", wtrSupply);
            moxi.SetFloat("_InkSupply", inkSupply);
            moxi.SetTexture(k, "Surf_R", surf.Read);
            moxi.SetTexture(k, "Flow_R", flow.Read);
            moxi.SetTexture(k, "Surf_W", surf.Write);
            moxi.SetTexture(k, "Flow_W", flow.Write);
            ComputeShaderUtil.Dispatch2D(moxi, k, w, h);
            surf.Swap();
            flow.Swap();
        }
    void Simulate()
    {
        // set params
        sphSimulator.SetInt("_NumParticles", numParticles);
        sphSimulator.SetFloat("_GridH", sorter.GetGridH());
        sphSimulator.SetVector("_GridDim", gridDim);
        sphSimulator.SetFloat("_TimeStep", Mathf.Min(MAX_TIMESTEP, Time.deltaTime));
        sphSimulator.SetFloat("_Smoothlen", smoothLen);
        sphSimulator.SetFloat("_PressureStiffness", pressureStiffness);
        sphSimulator.SetFloat("_RestDensity", restDensity);
        sphSimulator.SetFloat("_DensityCoef", particleMass * 315.0f / (64.0f * Mathf.PI * Mathf.Pow(smoothLen, 9.0f)));
        sphSimulator.SetFloat("_GradPressureCoef", particleMass * -45.0f / (Mathf.PI * Mathf.Pow(smoothLen, 6.0f)));
        sphSimulator.SetFloat("_LapViscosityCoef", particleMass * viscosity * 45.0f / (Mathf.PI * Mathf.Pow(smoothLen, 6.0f)));
        sphSimulator.SetFloat("_Restitution", restitution);
        sphSimulator.SetFloat("_MaxVelocity", maxVelocity);
        sphSimulator.SetFloat("_Time", Time.time);
        sphSimulator.SetFloat("_SphereRad", sphere.transform.localScale.x / 2);
        sphSimulator.SetVector("_SpherePos", sphere.transform.position);

        int knl = 0;

        //calc density
        knl = sphSimulator.FindKernel("SimDensity");
        sphSimulator.SetBuffer(knl, "_ParticlesBufferRO", particleRO);
        sphSimulator.SetBuffer(knl, "_DensityBufferRW", densityRW);
        sphSimulator.SetBuffer(knl, "_GridIndicesBufferRead", sorter.GetGridIndicesBuffer());
        sphSimulator.Dispatch(knl, numParticles / SIM_BLOCK_SIZE, 1, 1);
        ComputeShaderUtil.Swap(ref densityRO, ref densityRW);

        //calc force
        knl = sphSimulator.FindKernel("SimForce");
        sphSimulator.SetBuffer(knl, "_ParticlesBufferRO", particleRO);
        sphSimulator.SetBuffer(knl, "_DensityBufferRO", densityRO);
        sphSimulator.SetBuffer(knl, "_ForceBufferRW", forceRW);
        sphSimulator.SetBuffer(knl, "_GridIndicesBufferRead", sorter.GetGridIndicesBuffer());
        sphSimulator.Dispatch(knl, numParticles / SIM_BLOCK_SIZE, 1, 1);
        ComputeShaderUtil.Swap(ref forceRO, ref forceRW);

        //calc integration
        knl = sphSimulator.FindKernel("SimIntegrate");
        sphSimulator.SetBuffer(knl, "_ParticlesBufferRO", particleRO);
        sphSimulator.SetBuffer(knl, "_ParticlesBufferRW", particleRW);
        sphSimulator.SetBuffer(knl, "_ForceBufferRO", forceRO);
        sphSimulator.SetBuffer(knl, "_GridIndicesBufferRead", sorter.GetGridIndicesBuffer());
        sphSimulator.Dispatch(knl, numParticles / SIM_BLOCK_SIZE, 1, 1);
        ComputeShaderUtil.Swap(ref particleRO, ref particleRW);
    }
Exemplo n.º 12
0
        public void Collision(float omega)
        {
            var k = cs.FindKernel("Collision");

            cs.SetFloat("_Omega", omega);
            cs.SetTexture(k, "VelPhi_R", velphi.Read);
            cs.SetTexture(k, "ForceV_R", forces[0].Read);
            cs.SetTexture(k, "ForceD_R", forces[1].Read);
            cs.SetTexture(k, "ForceR_R", forces[2].Read);
            cs.SetTexture(k, "ForceV_W", forces[0].Write);
            cs.SetTexture(k, "ForceD_W", forces[1].Write);
            cs.SetTexture(k, "ForceR_W", forces[2].Write);
            ComputeShaderUtil.Dispatch2D(cs, k, w, h);
            foreach (var f in forces)
            {
                f.Swap();
            }
        }
Exemplo n.º 13
0
        public void Percolation(float omega)
        {
            var k1 = trsf.FindKernel("InterfaceF2L");
            var k2 = trsf.FindKernel("InterfaceL2F");

            trsf.SetTexture(k1, "Flow_R", flow.Read);
            trsf.SetTexture(k1, "VelPhi_R", lbe.VelPhi_R);
            trsf.SetTexture(k1, "VelPhi_W", lbe.VelPhi_W);
            ComputeShaderUtil.Dispatch2D(trsf, k1, w, h);
            lbe.SwapVelphi();
            lbe.Collision(omega);
            lbe.Streaming();
            lbe.Simulation();
            trsf.SetTexture(k2, "VelPhi_R", lbe.VelPhi_R);
            trsf.SetTexture(k2, "Flow_R", flow.Read);
            trsf.SetTexture(k2, "Flow_W", flow.Write);
            ComputeShaderUtil.Dispatch2D(trsf, k2, w, h);
            flow.Swap();
        }
Exemplo n.º 14
0
        public void Streaming()
        {
            var k = cs.FindKernel("Streaming");

            cs.SetTexture(k, "Grain", grain);
            cs.SetTexture(k, "Pinning", pinning);
            cs.SetTexture(k, "VelPhi_R", velphi.Read);
            cs.SetTexture(k, "ForceV_R", forces[0].Read);
            cs.SetTexture(k, "ForceD_R", forces[1].Read);
            cs.SetTexture(k, "ForceR_R", forces[2].Read);
            cs.SetTexture(k, "ForceV_W", forces[0].Write);
            cs.SetTexture(k, "ForceD_W", forces[1].Write);
            cs.SetTexture(k, "ForceR_W", forces[2].Write);
            ComputeShaderUtil.Dispatch2D(cs, k, w, h);
            foreach (var f in forces)
            {
                f.Swap();
            }
        }
Exemplo n.º 15
0
 private void SetupShader()
 {
     _Shader    = ComputeShaderUtil.FindComputeOrWarn(SHADER_PATH, out _IsReady);
     _SumKernel = _Shader.FindKernelOrWarn(KERNEL_NAME, ref _IsReady);
 }
Exemplo n.º 16
0
 private void SetupShader()
 {
     _ReadWriteShader = ComputeShaderUtil.FindComputeOrWarn(SHADERPATH, out _IsReady);
 }
Exemplo n.º 17
0
 public void Release()
 {
     ComputeShaderUtil.Destroy(ParticleBoidBufferRead);
     ComputeShaderUtil.Destroy(ParticleBoidBufferWrite);
     ComputeShaderUtil.Destroy(ParticleGridPositionCheck);
 }