Beispiel #1
0
    // m_applyBuoyancy
    static public void ApplyBuoyancy(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeVectorParam(shader, UpID, new Vector4(0, 1, 0, 0));
        cmd.SetComputeFloatParam(shader, BuoyancyID, data.systemData.m_densityBuoyancy);
        cmd.SetComputeFloatParam(shader, AmbientTemperatureID, data.systemData.m_ambientTemperature);
        cmd.SetComputeFloatParam(shader, WeightID, data.systemData.m_densityWeight);
        cmd.SetComputeFloatParam(shader, DeltaTimeID, dt);


        cmd.SetComputeBufferParam(shader, kernel, WriteID, data.m_velocity[WRITE]);
        cmd.SetComputeBufferParam(shader, kernel, VelocityID, data.m_velocity[READ]);
        cmd.SetComputeBufferParam(shader, kernel, DensityID, data.m_density[READ]);
        cmd.SetComputeBufferParam(shader, kernel, TemperatureID, data.m_temperature[READ]);

        cmd.DispatchCompute(shader,
                            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));

        Swap(data.m_velocity);
    }
Beispiel #2
0
    //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 });
    }
Beispiel #3
0
    // m_computeObstacles
    static public void ComputeObstacles(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeBufferParam(shader, kernel, WriteID, data.m_obstacles);

        cmd.DispatchCompute(shader,
                            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));
    }
Beispiel #4
0
    public bool CheckWindData(WindDataRuntime data)
    {
        if (data.basicData == null)
        {
            return(false);
        }

        var width  = Mathf.CeilToInt(data.basicData.WindAreaSize.x / data.basicData.WindResolution);
        var height = Mathf.CeilToInt(data.basicData.WindAreaSize.y / data.basicData.WindResolution);
        var depth  = Mathf.CeilToInt(data.basicData.WindAreaSize.z / data.basicData.WindResolution);

        return(data.width != width || data.height != height || data.depth != depth);
    }
Beispiel #5
0
 void ReleaseRT(WindDataRuntime data)
 {
     if (data.WindDataTex != null)
     {
         for (int j = 0; j < data.WindDataTex.Length; ++j)
         {
             if (data.WindDataTex[j] != null)
             {
                 data.WindDataTex[j].Release();
             }
             data.WindDataTex[j] = null;
         }
     }
 }
Beispiel #6
0
    // m_computeVorticity
    static public void ComputeVorticity(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);

        cmd.SetComputeBufferParam(shader, kernel, WriteID, data.m_temp3f);
        cmd.SetComputeBufferParam(shader, kernel, VelocityID, data.m_velocity[READ]);

        cmd.DispatchCompute(shader,
                            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));
    }
Beispiel #7
0
    // m_computeConfinement
    static public void ComputeConfinement(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeFloatParam(shader, DeltaTimeID, dt);
        cmd.SetComputeFloatParam(shader, EpsilonID, data.systemData.m_vorticityStrength);


        cmd.SetComputeBufferParam(shader, kernel, WriteID, data.m_velocity[WRITE]);
        cmd.SetComputeBufferParam(shader, kernel, ReadID, data.m_velocity[READ]);
        cmd.SetComputeBufferParam(shader, kernel, VorticityID, data.m_temp3f);

        cmd.DispatchCompute(shader,
                            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));

        Swap(data.m_velocity);
    }
Beispiel #8
0
    // m_applyImpulse
    static public void ApplyImpulse(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt, float amount, ComputeBuffer[] buffer)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeFloatParam(shader, RadiusID, data.systemData.m_inputRadius);
        cmd.SetComputeFloatParam(shader, AmountID, amount);
        cmd.SetComputeFloatParam(shader, DeltaTimeID, dt);
        cmd.SetComputeVectorParam(shader, PosID, data.systemData.m_inputPos);

        cmd.SetComputeBufferParam(shader, kernel, ReadID, buffer[READ]);
        cmd.SetComputeBufferParam(shader, kernel, WriteID, buffer[WRITE]);

        cmd.DispatchCompute(shader,
                            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));

        Swap(buffer);
    }
Beispiel #9
0
    // m_applyAdvect
    static public void ApplyAdvection(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt, float dissipation, float decay, ComputeBuffer read, ComputeBuffer write, float forward = 1.0f)
    {
        int kernel = (int)WindSystemData.ADVECTION.NORMAL;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeFloatParam(shader, DeltaTimeID, dt);
        cmd.SetComputeFloatParam(shader, DissipateID, dissipation);
        cmd.SetComputeFloatParam(shader, ForwardID, forward);
        cmd.SetComputeFloatParam(shader, DecayID, decay);


        cmd.SetComputeBufferParam(shader, kernel, Read1fID, read);
        cmd.SetComputeBufferParam(shader, kernel, Write1fID, write);
        cmd.SetComputeBufferParam(shader, kernel, VelocityID, data.m_velocity[READ]);
        cmd.SetComputeBufferParam(shader, kernel, ObstaclesID, data.m_obstacles);

        cmd.DispatchCompute(shader,
                            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));
    }
Beispiel #10
0
    public void InitalizeWindDataLOD(WindDataRuntime data)
    {
        if (data.basicData == null)
        {
            return;
        }

        var width  = Mathf.CeilToInt(data.basicData.WindAreaSize.x / data.basicData.WindResolution);
        var height = Mathf.CeilToInt(data.basicData.WindAreaSize.y / data.basicData.WindResolution);
        var depth  = Mathf.CeilToInt(data.basicData.WindAreaSize.z / data.basicData.WindResolution);

        data.width  = width;
        data.height = height;
        data.depth  = depth;

        CreateRT(ref data.WindDataTex, width, height, depth);

        int totalSize = width * height * depth;

        CreateComputeBufferFloat(ref data.m_density, totalSize);
        CreateComputeBufferFloat(ref data.m_temperature, totalSize);
        CreateComputeBufferFloat(ref data.m_phi, totalSize);
        CreateComputeBufferFloat(ref data.m_velocity, totalSize, true);
        CreateComputeBufferFloat(ref data.m_pressure, totalSize);

        if (data.m_obstacles != null)
        {
            data.m_obstacles.Release();
        }
        data.m_obstacles = new ComputeBuffer(totalSize, sizeof(float));
        if (data.m_temp3f != null)
        {
            data.m_temp3f.Release();
        }
        data.m_temp3f = new ComputeBuffer(totalSize, sizeof(float) * 3);

        //ComputeObstacles();
    }
Beispiel #11
0
    // m_applyAdvect
    static public void ApplyAdvectionVelocity(CommandBuffer cmd, ComputeShader shader, WindDataRuntime data, float dt)
    {
        int kernel = 0;

        cmd.SetComputeVectorParam(shader, SizeID, data.size);
        cmd.SetComputeFloatParam(shader, DeltaTimeID, dt);
        cmd.SetComputeFloatParam(shader, DissipateID, data.systemData.m_velocityDissipation);
        cmd.SetComputeFloatParam(shader, ForwardID, 1.0f);
        cmd.SetComputeFloatParam(shader, DecayID, 0.0f);


        cmd.SetComputeBufferParam(shader, kernel, Read3fID, data.m_velocity[READ]);
        cmd.SetComputeBufferParam(shader, kernel, Write3fID, data.m_velocity[WRITE]);
        cmd.SetComputeBufferParam(shader, kernel, VelocityID, data.m_velocity[READ]);
        cmd.SetComputeBufferParam(shader, kernel, ObstaclesID, data.m_obstacles);

        cmd.DispatchCompute(shader,
                            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));

        Swap(data.m_velocity);
    }
Beispiel #12
0
 void ReleaseComputeBuffer(WindDataRuntime data)
 {
     if (data.m_density != null)
     {
         for (int i = 0; i < data.m_density.Length; ++i)
         {
             if (data.m_density[i] != null)
             {
                 data.m_density[i].Release();
             }
             data.m_density[i] = null;
         }
     }
     if (data.m_velocity != null)
     {
         for (int i = 0; i < data.m_velocity.Length; ++i)
         {
             if (data.m_velocity[i] != null)
             {
                 data.m_velocity[i].Release();
             }
             data.m_velocity[i] = null;
         }
     }
     if (data.m_pressure != null)
     {
         for (int i = 0; i < data.m_pressure.Length; ++i)
         {
             if (data.m_pressure[i] != null)
             {
                 data.m_pressure[i].Release();
             }
             data.m_pressure[i] = null;
         }
     }
     if (data.m_temperature != null)
     {
         for (int i = 0; i < data.m_temperature.Length; ++i)
         {
             if (data.m_temperature[i] != null)
             {
                 data.m_temperature[i].Release();
             }
             data.m_temperature[i] = null;
         }
     }
     if (data.m_temperature != null)
     {
         for (int i = 0; i < data.m_phi.Length; ++i)
         {
             if (data.m_phi[i] != null)
             {
                 data.m_phi[i].Release();
             }
             data.m_phi[i] = null;
         }
     }
     if (data.m_temp3f != null)
     {
         data.m_temp3f.Release();
         data.m_temp3f = null;
     }
     if (data.m_obstacles != null)
     {
         data.m_obstacles.Release();
         data.m_obstacles = null;
     }
 }