예제 #1
0
        void Update()
        {
            // Update Position
            trailKernelMat.SetTexture("_PositionBuffer", _positionBuffer[0]);
            trailKernelMat.SetBuffer("_BoidDataBuffer", _boidScript.GetBoidDataBuffer());
            trailKernelMat.SetInt("_TrailNum", _trailNum);
            Graphics.Blit(null, _positionBuffer[1], trailKernelMat, 0);


            // Reconstruct Vector
            _mrt[0] = _normalBuffer[1].colorBuffer;
            _mrt[1] = _binormalBuffer[1].colorBuffer;
            Graphics.SetRenderTarget(_mrt, _positionBuffer[1].depthBuffer);
            trailKernelMat.SetTexture("_PositionBuffer", _positionBuffer[1]);
            trailKernelMat.SetTexture("_NormalBuffer", _normalBuffer[0]);
            trailKernelMat.SetTexture("_BinormalBuffer", _binormalBuffer[0]);
            Graphics.Blit(null, trailKernelMat, 1);

            SwapBuffer(ref _positionBuffer[0], ref _positionBuffer[1]);
            SwapBuffer(ref _normalBuffer[0], ref _normalBuffer[1]);
            SwapBuffer(ref _binormalBuffer[0], ref _binormalBuffer[1]);
        }
예제 #2
0
        void RenderInstancedMesh()
        {
            if (_renderMat == null || _boidsScript == null || _boidsTrailScript == null || !SystemInfo.supportsInstancing)
            {
                return;
            }

            uint numIndices = (_instanceMesh != null) ? (uint)_instanceMesh.GetIndexCount(0) : 0;

            args[0] = numIndices;
            args[1] = (uint)_boidsScript.GetMaxObjectNum();
            _argsBuffer.SetData(args);

            _renderMat.SetBuffer("_BoidDataBuffer", _boidsScript.GetBoidDataBuffer());

            _renderMat.SetTexture("_PositionBuffer", _boidsTrailScript.GetPositionBuffer());
            _renderMat.SetTexture("_NormalBuffer", _boidsTrailScript.GetNormalBuffer());
            _renderMat.SetTexture("_BinormalBuffer", _boidsTrailScript.GetBinormalBuffer());

            _renderMat.SetFloat("_PathOffset", _pathOffset);
            _renderMat.SetFloat("_PathScale", _pathScale);
            _renderMat.SetFloat("_Thickness", _thickness);


            var bounds = new Bounds
                         (
                _boidsScript.GetSimulationAreaCenter(),
                _boidsScript.GetSimulationAreaSize()
                         );

            Graphics.DrawMeshInstancedIndirect
            (
                _instanceMesh,
                0,
                _renderMat,
                bounds,
                _argsBuffer
            );
        }