void FluidStep(MikeAsh_Fluid fluid) { int N = fluid.N; float visc = fluid.visc; float diff = fluid.diff; //float dt = fluid.dt; float dt = Time.deltaTime; float[] Vx = fluid.Vx; float[] Vy = fluid.Vy; float[] Vx0 = fluid.Vx0; float[] Vy0 = fluid.Vy0; float[] s = fluid.s; float[] density = fluid.density; // Diffuse velocites diffuse(1, Vx0, Vx, visc, dt, iter, N); diffuse(2, Vy0, Vy, visc, dt, iter, N); //Clean up to make sure density is the same? project(Vx0, Vy0, Vx, Vy, iter, N); // Advect on the velocityes advect(1, Vx, Vx0, Vx0, Vy0, dt, N); advect(2, Vy, Vy0, Vx0, Vy0, dt, N); //Clean upp again project(Vx, Vy, Vx0, Vy0, iter, N); // Diffuse density(dye) and advect it //diffuse(0, s, density, diff, dt, 4, N); //advect(0, density, s, Vx, Vy, dt, N); }
void Start() { vBuffer = new ComputeBuffer(N * N, 4); v0Buffer = new ComputeBuffer(N * N, 4); kernel = shader.FindKernel("LinearSolve"); shader.SetBuffer(kernel, "v", vBuffer); shader.SetBuffer(kernel, "v0", v0Buffer); shader.SetInt("size", N); tex = new Texture2D(N, N, TextureFormat.RGB24, false); tex.wrapMode = TextureWrapMode.Clamp; tex.filterMode = filtermode; fluid = new MikeAsh_Fluid(0.1f, 0.0001f, 0.0001f, N); RenderFluid(); fluid.AddDensity(2, 3, 100); fluid.AddVelocity(2, 3, 2, 4); }