Esempio n. 1
0
        void Start()
        {
            _trailNum = _boidScript.GetMaxObjectNum();

            CreateBuffer(ref _positionBuffer);
            CreateBuffer(ref _normalBuffer);
            CreateBuffer(ref _binormalBuffer);

            _mrt = new RenderBuffer[2];
        }
        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
            );
        }