Ejemplo n.º 1
0
        private void ApplyImpulseToDensityTemp(Vector2 position, float radius)
        {
            ImpulseShader.SetFloat("Radius", radius);
            ImpulseShader.SetFloats("Point", position.x, position.y);
            ImpulseShader.SetInts("MapSize", _mapSize.x, _mapSize.y);
            // DEBUG VALUES!
            ImpulseShader.SetFloats("Fill", 1f, 10f); // Density and Temp fill respectively.

            ImpulseShader.SetBuffer(_impulseMain, "Current", _densityTemp.Current);
            ImpulseShader.SetBuffer(_impulseMain, "Past", _densityTemp.Past);

            ImpulseShader.Dispatch(_impulseMain, (int)math.ceil(_linearMapSize / 64f),
                                   1, 1);
        }
Ejemplo n.º 2
0
        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);
        }