public void UpdateBorder(Material material, bool useOffset) { Swap(); GraphicUtil.BlitBorderWithInnerCopy(src, dst, material, useOffset); }
void UpdateSimulation(float dt) { var dx = settings.dx; // advect if (settings.enableVelocityAdvection || settings.enableInkAdvection) { advectionMat.SetFloat("_ReciprocalDx", 1.0f / dx); advectionMat.SetFloat("_DeltaTime", dt); // advect velocity if (settings.enableVelocityAdvection) { boundaryMat.SetFloat("_Scale", -1); velocityBuf.UpdateBorder(boundaryMat, true); advectionMat.SetTexture("_VelocityTex", velocityBuf.current); advectionMat.SetFloat("_OneMinusDissipation", 1.0f); velocityBuf.UpdateExceptBorder(advectionMat); } // advect ink if (settings.enableInkAdvection) { boundaryMat.SetFloat("_Scale", 0); inkBuf.UpdateBorder(boundaryMat, true); advectionMat.SetTexture("_VelocityTex", velocityBuf.current); advectionMat.SetFloat("_OneMinusDissipation", 1.0f - settings.inkDissipation); inkBuf.UpdateExceptBorder(advectionMat); } } // impulse if (source.output > 0) { impulseMat.SetFloat("_Radius", settings.sourceRadius); impulseMat.SetVector("_Position", source.position); if (settings.enableVelocityImpulse) { var strength = new Vector4( Mathf.Clamp(source.force.x, -1, 1), Mathf.Clamp(source.force.y, -1, 1), 0, 0) * settings.strengthMul; impulseMat.SetVector("_Color", strength); Debug.Log(strength); velocityBuf.UpdateExceptBorder(impulseMat); } if (settings.enableInkImpulse) { impulseMat.SetColor("_Color", source.color); inkBuf.UpdateExceptBorder(impulseMat); } } if (settings.viscosity > 0) { var alpha = dx * dx / (settings.viscosity * dt); var beta = 4.0f + alpha; solver.SolvePoisson(velocityBuf.current, velocityBuf.current, settings.solverIterations, alpha, beta); } if (settings.enablePressureUpdate) { divergenceMat.SetFloat("_HalfReciprocalDx", 0.5f / dx); Graphics.Blit(velocityBuf.current, divergenceBuf, divergenceMat); var alpha = -dx * dx; var beta = 4.0f; boundaryMat.SetFloat("_Scale", 1); solver.SolvePoisson(pressureBuf, divergenceBuf, settings.solverIterations, alpha, beta, (arg1, arg2) => GraphicUtil.BlitBorderWithInnerCopy(arg1, arg2, boundaryMat, true)); } boundaryMat.SetFloat("_Scale", -1); velocityBuf.UpdateBorder(boundaryMat, true); if (settings.enableSubstractPressureGradient) { substractGradientMat.SetFloat("_HalfReciprocalDx", 0.5f / dx); substractGradientMat.SetTexture("_SecondTex", pressureBuf); velocityBuf.UpdateExceptBorder(substractGradientMat); } }