private void ComputeDivergence(ComputeBuffer divergence, ComputeBuffer pastVelocity) { DivergenceShader.SetInts("MapSize", _mapSize.x, _mapSize.y); DivergenceShader.SetBuffer(_divergenceMain, "CurrentDivergence", divergence); DivergenceShader.SetBuffer(_divergenceMain, "PastVelocity", pastVelocity); DivergenceShader.SetBuffer(_divergenceMain, "Walls", _walls); DivergenceShader.Dispatch(_divergenceMain, (int)math.ceil(_linearMapSize / 64f), 1, 1); }
private void Start() { _adventMain = AdventShader.FindKernel("Advent"); _buoyancyMain = BuoyancyShader.FindKernel("Buoyancy"); _impulseMain = ImpulseShader.FindKernel("Impulse"); _divergenceMain = DivergenceShader.FindKernel("Divergence"); _jacobiMain = JacobiShader.FindKernel("Jacobi"); _subtractMain = SubtractGradientShader.FindKernel("Subtract"); _clearMain = ClearShader.FindKernel("ClearBuffer"); _tilemap = TileMapObject.GetComponent <Tilemap>(); _mapBounds = _tilemap.cellBounds; _mapSize = new Vector2Int(_mapBounds.size.x, _mapBounds.size.y); // Calculate obstacle locations var walls = new float4[_mapSize.x, _mapSize.y]; foreach (var position in _mapBounds.allPositionsWithin) { walls[position.x - _mapBounds.xMin, position.y - _mapBounds.yMin] = new float4(100); if (position.x == _mapBounds.xMin || position.x == _mapBounds.xMax || position.y == _mapBounds.yMin || position.y == _mapBounds.yMax) { continue; // Even if border tile is a simulate atmo tile, it will be defined as a wall. } if (SimulateAtmoTiles.Contains(_tilemap.GetTile(position))) { walls[position.x - _mapBounds.xMin, position.y - _mapBounds.yMin] = new float4(-100); } } _linearMapSize = _mapSize.x * _mapSize.y; _velocity = new RenderTextureRotating(_linearMapSize, ComputeBufferMode.Dynamic); _densityTemp = new RenderTextureRotating(_linearMapSize); _pressure = new RenderTextureRotating(_linearMapSize); _walls = new ComputeBuffer(_linearMapSize, 4 * sizeof(float), ComputeBufferType.Structured, ComputeBufferMode.SubUpdates); _walls.SetData(walls); _divergence = new ComputeBuffer(_linearMapSize, 4 * sizeof(float), ComputeBufferType.Structured, ComputeBufferMode.SubUpdates); }