void Start()
    {
        psystem = MiscPSystemControls.inst;
        Application.targetFrameRate = -1;
        BufferHandlerPS1.inst       = this;

        ParticleCountItterator.Init(this);


        int sqrtCount = (int)Mathf.Sqrt(count);

        PosBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        PosBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);

        IdAgeBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default);
        IdAgeBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default);

        DeadBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Append);
        LiveBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Counter);

        Vector3[] points     = new Vector3[count];
        Vector3[] velocities = new Vector3[count];
        Vector2[] idAges     = new Vector2[count];
        int[]     indecies   = new int[count];

        argBuffer       = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);
        deadBuffArgBuff = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);

        Random.InitState(0);
        for (int i = 0; i < count; i++)
        {
            indecies[i]   = i;
            points[i]     = new Vector3(-3f + (float)((int)(i / 1000)) * 0.3f, (i % 1000) / 100f, -5);
            velocities[i] = Vector3.one * 0.01f;

            idAges[i] = new Vector2(0, -1.0f);
        }
        PosBuffer[READ].SetData(points);
        PosBuffer[WRITE].SetData(points);

        VelBuffer[READ].SetData(velocities);
        VelBuffer[WRITE].SetData(velocities);

        IdAgeBuffer[READ].SetData(idAges);
        IdAgeBuffer[WRITE].SetData(idAges);

        DeadBuffer.SetData(indecies);
        DeadBuffer.SetCounterValue((uint)(count));
        lastVelMod = IsPlaying;
    }
Ejemplo n.º 2
0
    //TODO: DO THE TWIST!!! FLIP A READ AND WRITE BUFFER
    void Start()
    {
        //Application.targetFrameRate = 60;
        BufferHandlerPS1.inst = this;

        ParticleCountItterator.Init(this);
        particleCountDisplayerTextObj.GetComponent <Text>().text = this.count + "";

        int sqrtCount = (int)Mathf.Sqrt(count);

        PosBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        PosBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);

        Vector3[] points     = new Vector3[count];
        Vector3[] velocities = new Vector3[count];

        Random.seed = 0;
        for (int i = 0; i < count; i++)
        {
            points[i]     = new Vector3();
            points[i].x   = Random.Range(-size, size);
            points[i].y   = Random.Range(-size, size);
            points[i].z   = Random.Range(-zSize, zSize);;
            velocities[i] = Vector3.zero;

            /*points[i].color = new Vector3();
             * points[i].color.x = Random.value > 0.5f ? 0.0f : 1.0f;
             * points[i].color.y = Random.value > 0.5f ? 0.0f : 1.0f;
             * points[i].color.z = Random.value > 0.5f ? 0.0f : 1.0f;
             */
        }
        PosBuffer[READ].SetData(points);
        PosBuffer[WRITE].SetData(points);
        VelBuffer[READ].SetData(velocities);
        VelBuffer[WRITE].SetData(velocities);

        /*cShade.SetBuffer(cShade.FindKernel("CSMain"), "RvertPos", PosBuffer[READ]);
         * cShade.SetBuffer(cShade.FindKernel("CSMain"), "RvertVel", VelBuffer[READ]);
         * cShade.SetBuffer(cShade.FindKernel("CSMain"), "WvertPos", PosBuffer[WRITE]);
         * cShade.SetBuffer(cShade.FindKernel("CSMain"), "WvertVel", VelBuffer[WRITE]);
         *
         * cShade.SetVector("_GravDampSphereDown", new Vector4(gravity, upDampening,sphereRadius, 0f ));
         *
         * cShade.Dispatch(cShade.FindKernel("CSMain"), sqrCount/8, sqrCount/8, 1);
         */
        lastVelMod = velModBase;
    }
Ejemplo n.º 3
0
    void Start()
    {
        psystem = MiscPSystemControls.inst;
        Application.targetFrameRate = -1;
        BufferHandlerPS1.inst       = this;

        ParticleCountItterator.Init(this);


        int sqrtCount = (int)Mathf.Sqrt(count);

        ColBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 4, ComputeBufferType.Default);
        ColBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 4, ComputeBufferType.Default);


        PosBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        PosBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);
        VelBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default);

        IdAgeBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default);
        IdAgeBuffer[READ]  = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default);


        DeadBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Append);
        LiveBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Counter);

        Vector3[] points     = new Vector3[count];
        Vector3[] velocities = new Vector3[count];
        Vector2[] idAges     = new Vector2[count];
        int[]     indecies   = new int[count];

        Vector4[] colorz = new Vector4[count];

        argBuffer       = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);
        deadBuffArgBuff = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments);

        Random.InitState(0);
        for (int i = 0; i < count; i++)
        {
            indecies[i]   = i;
            points[i]     = new Vector3(-3f + (float)((int)(i / 1000)) * 0.3f, (i % 1000) / 100f, -5);
            velocities[i] = Vector3.one * 0.01f;

            idAges[i] = new Vector2(0, -1.0f);

            colorz[i] = new Vector4(0, 0, 0, 0);
        }

        PosBuffer[READ].SetData(points);
        PosBuffer[WRITE].SetData(points);

        VelBuffer[READ].SetData(velocities);
        VelBuffer[WRITE].SetData(velocities);

        IdAgeBuffer[READ].SetData(idAges);
        IdAgeBuffer[WRITE].SetData(idAges);

        ColBuffer[READ].SetData(colorz);
        ColBuffer[WRITE].SetData(colorz);

        DeadBuffer.SetData(indecies);
        DeadBuffer.SetCounterValue((uint)(count));
        lastVelMod = IsPlaying;



        cubeCountSide  = Mathf.ClosestPowerOfTwo(Mathf.Abs(cubeCountSide));
        cubeCountTotal = (int)Mathf.Pow(cubeCountSide, 2);

        CubeDimBuffer[WRITE] = new ComputeBuffer(cubeCountTotal, sizeof(float) * 4, ComputeBufferType.Default);
        CubeDimBuffer[READ]  = new ComputeBuffer(cubeCountTotal, sizeof(float) * 4, ComputeBufferType.Default);
        cShade.SetInt("_CubeCount", cubeCountTotal);

        CubeDats[] cubdat = new CubeDats[cubeCountTotal];
        Vector2    WLdims = new Vector2(1.5f, 1.5f);

        for (int i = 0; i < cubeCountTotal; i++)
        {
            int xcoord = (int)(i / cubeCountSide);
            int ycoord = (int)(i % cubeCountSide);

            float truheight = Mathf.Abs((float)xcoord - cubeCountSide * 0.5f) + Mathf.Abs((float)ycoord - cubeCountSide * 0.5f);

            CubeDats newdat = new CubeDats(new Vector2(xcoord, ycoord), WLdims, truheight * 0.2f, 0f, new Vector3(-cubeCountSide * 0.5f * WLdims.x, 0f, -cubeCountSide * 0.5f * WLdims.y));

            newdat.dims *= 0.5f;
            cubdat[i]    = newdat;
        }

        GameObject papa = new GameObject();

        for (int i = 0; i < cubeCountTotal; i++)
        {
            GameObject newcub = GameObject.CreatePrimitive(PrimitiveType.Cube);

            newcub.GetComponent <MeshRenderer>().material = this.cubeMat;
            newcub.transform.position   = cubdat[i].center;
            newcub.transform.localScale = cubdat[i].dims * 2f;
            newcub.transform.SetParent(papa.transform);
        }

        CubeDimBuffer[READ].SetData(cubdat);
        CubeDimBuffer[WRITE].SetData(cubdat);
    }