示例#1
0
    void OnEnable()
    {
        GetInstances().Add(this);
        SettingSimulationParameters();

        int roundUpPowerOf2 = (int)Mathf.Pow(2, Mathf.Ceil(Mathf.Log(simulationParameters[0].maxParticles) / Mathf.Log(2.0f)));

        bufSimulationParameters = new ComputeBuffer(1, Marshal.SizeOf(typeof(SimulationParameters)));
        for (int i = 0; i < 2; i++)
        {
            bufPosPress[i] = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
            bufVelRho[i]   = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
            bufForceVol[i] = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
            bufTGRM[i]     = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));

            bufSortData[i] = new ComputeBuffer(roundUpPowerOf2, Marshal.SizeOf(typeof(SortData)));
        }

        bufVelVerlet        = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
        bufSphereColliders  = new ComputeBuffer(maxSphereColliders, Marshal.SizeOf(typeof(GPUSphereCollider)));
        bufCapsuleColliders = new ComputeBuffer(maxCapsuleColliders, Marshal.SizeOf(typeof(GPUCapsuleCollider)));
        bufBoxColliders     = new ComputeBuffer(maxBoxColliders, Marshal.SizeOf(typeof(GPUBoxCollider)));

        bufAddPosPress = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
        bufAddVelRho   = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
        bufAddForceVol = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
        bufAddTGRM     = new ComputeBuffer(maxParticles, Marshal.SizeOf(typeof(Vector4)));
        bufCells       = new ComputeBuffer((int)simulationParameters[0].numCells, Marshal.SizeOf(typeof(Cell)));

        bitonicSort = new GPUSort();
        bitonicSort.Initialize(bitonicSortShader);

        bufSimulationParameters.SetData(simulationParameters);
    }
示例#2
0
    void OnEnable()
    {
        GetInstances().Add(this);

        m_world_data[0].SetDefaultValues();
        m_world_data[0].num_max_particles = m_max_particles;
        m_world_data[0].SetWorldSize(transform.position, transform.localScale * 0.5f,
                                     new UVector3 {
            x = (uint)m_world_div_x, y = (uint)m_world_div_y, z = (uint)m_world_div_z
        });
        m_sph_params[0].SetDefaultValues(m_world_data[0].particle_size);

        m_particles = new CSParticle[m_max_particles];
        for (int i = 0; i < m_particles.Length; ++i)
        {
            m_particles[i].hit_objid = -1;
            //particles[i].owner_objid = -1;
            m_particles[i].lifetime = 0.0f;
        }


        IVector3 world_div = m_world_data[0].world_div;
        int      num_cells = world_div.x * world_div.y * world_div.z;

        m_buf_world_data  = new ComputeBuffer(1, CSWorldData.size);
        m_buf_world_idata = new ComputeBuffer(1, CSWorldIData.size);
        m_buf_world_idata.SetData(m_world_idata);
        m_buf_sph_params   = new ComputeBuffer(1, CSSPHParams.size);
        m_buf_cells        = new ComputeBuffer(num_cells, CSCell.size);
        m_buf_particles[0] = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_particles[1] = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_particles[0].SetData(m_particles);
        m_buf_particles_to_add = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_imd          = new ComputeBuffer(m_max_particles, CSParticleIData.size);
        m_buf_sort_data[0] = new ComputeBuffer(m_max_particles, CSSortData.size);
        m_buf_sort_data[1] = new ComputeBuffer(m_max_particles, CSSortData.size);

        m_bitonic_sort = new GPUSort();
        m_bitonic_sort.Initialize(m_cs_sort);

        m_buf_sphere_colliders  = new ComputeBuffer(m_max_sphere_colliders, CSSphereCollider.size);
        m_buf_capsule_colliders = new ComputeBuffer(m_max_capsule_colliders, CSCapsuleCollider.size);
        m_buf_box_colliders     = new ComputeBuffer(m_max_box_colliders, CSBoxCollider.size);
        m_buf_forces            = new ComputeBuffer(m_max_forces, CSForce.size);
    }
    void OnEnable()
    {
        GetInstances().Add(this);

        m_world_data[0].SetDefaultValues();
        m_world_data[0].num_max_particles = m_max_particles;
        m_world_data[0].SetWorldSize(transform.position, transform.localScale * 0.5f,
            new UVector3 { x = (uint)m_world_div_x, y = (uint)m_world_div_y, z = (uint)m_world_div_z });
        m_sph_params[0].SetDefaultValues(m_world_data[0].particle_size);

        m_particles = new CSParticle[m_max_particles];
        for (int i = 0; i < m_particles.Length; ++i)
        {
            m_particles[i].hit_objid = -1;
            //particles[i].owner_objid = -1;
            m_particles[i].lifetime = 0.0f;
        }

        IVector3 world_div = m_world_data[0].world_div;
        int num_cells = world_div.x * world_div.y * world_div.z;

        m_buf_world_data = new ComputeBuffer(1, CSWorldData.size);
        m_buf_world_idata = new ComputeBuffer(1, CSWorldIData.size);
        m_buf_world_idata.SetData(m_world_idata);
        m_buf_sph_params = new ComputeBuffer(1, CSSPHParams.size);
        m_buf_cells = new ComputeBuffer(num_cells, CSCell.size);
        m_buf_particles[0] = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_particles[1] = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_particles[0].SetData(m_particles);
        m_buf_particles_to_add = new ComputeBuffer(m_max_particles, CSParticle.size);
        m_buf_imd = new ComputeBuffer(m_max_particles, CSParticleIData.size);
        m_buf_sort_data[0] = new ComputeBuffer(m_max_particles, CSSortData.size);
        m_buf_sort_data[1] = new ComputeBuffer(m_max_particles, CSSortData.size);

        m_bitonic_sort = new GPUSort();
        m_bitonic_sort.Initialize(m_cs_sort);

        m_buf_sphere_colliders = new ComputeBuffer(m_max_sphere_colliders, CSSphereCollider.size);
        m_buf_capsule_colliders = new ComputeBuffer(m_max_capsule_colliders, CSCapsuleCollider.size);
        m_buf_box_colliders = new ComputeBuffer(m_max_box_colliders, CSBoxCollider.size);
        m_buf_forces = new ComputeBuffer(m_max_forces, CSForce.size);
    }