Esempio n. 1
0
        private void ApplyBuoyancy(ComputeBuffer currentVelocity, ComputeBuffer densityTemp, ComputeBuffer pastVelocity, float timeStep)
        {
            BuoyancyShader.SetFloat("TimeStep", timeStep);
            AdventShader.SetInts("MapSize", _mapSize.x, _mapSize.y);
            // DEBUG VALUES!
            BuoyancyShader.SetFloat("AmbientTemperature", 0f);
            BuoyancyShader.SetFloat("Sigma", 1f);    // Smoke buoyancy.
            BuoyancyShader.SetFloat("Kappa", 0.05f); // Smoke mass.

            BuoyancyShader.SetBuffer(_buoyancyMain, "CurrentVelocity", currentVelocity);
            BuoyancyShader.SetBuffer(_buoyancyMain, "PastVelocity", pastVelocity);
            BuoyancyShader.SetBuffer(_buoyancyMain, "DensityTemp", densityTemp);

            BuoyancyShader.Dispatch(_buoyancyMain, (int)math.ceil(_linearMapSize / 64f),
                                    1, 1);
        }
Esempio 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);
        }