예제 #1
0
        protected override void OnApply(CommandEncoder commandEncoder)
        {
            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.TransformConstants))
            {
                _transformConstants.World = _world;
                _transformConstants.WorldViewProjection = _world * _view * _projection;

                _transformConstantBuffer.UpdateData(ref _transformConstants);

                commandEncoder.SetInlineConstantBuffer(0, _transformConstantBuffer);

                _dirtyFlags &= ~TerrainEffectDirtyFlags.TransformConstants;
            }

            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.LightingConstants))
            {
                Matrix4x4.Invert(_view, out var viewInverse);
                _lightingConstants.CameraPosition = viewInverse.Translation;

                _lightingConstantBuffer.UpdateData(ref _lightingConstants);

                commandEncoder.SetInlineConstantBuffer(1, _lightingConstantBuffer);

                _dirtyFlags &= ~TerrainEffectDirtyFlags.LightingConstants;
            }

            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.TileDataTexture))
            {
                commandEncoder.SetTexture(2, _tileDataTexture);
                _dirtyFlags &= ~TerrainEffectDirtyFlags.TileDataTexture;
            }

            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.CliffDetailsBuffer))
            {
                commandEncoder.SetStaticBuffer(3, _cliffDetailsBuffer);
                _dirtyFlags &= ~TerrainEffectDirtyFlags.CliffDetailsBuffer;
            }

            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.TextureDetailsBuffer))
            {
                commandEncoder.SetStaticBuffer(4, _textureDetailsBuffer);
                _dirtyFlags &= ~TerrainEffectDirtyFlags.TextureDetailsBuffer;
            }

            if (_dirtyFlags.HasFlag(TerrainEffectDirtyFlags.Textures))
            {
                commandEncoder.SetTextureSet(5, _textures);
                _dirtyFlags &= ~TerrainEffectDirtyFlags.Textures;
            }
        }
예제 #2
0
        protected override void OnApply(CommandEncoder commandEncoder)
        {
            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.SkinningConstants))
            {
                if (_skinningBuffer != null)
                {
                    commandEncoder.SetInlineStructuredBuffer(2, _skinningBuffer);
                }

                _dirtyFlags &= ~MeshEffectDirtyFlags.SkinningConstants;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.TransformConstants))
            {
                _transformConstants.ViewProjection = _view * _projection;

                _transformConstantBuffer.UpdateData(ref _transformConstants);

                commandEncoder.SetInlineConstantBuffer(1, _transformConstantBuffer);

                _dirtyFlags &= ~MeshEffectDirtyFlags.TransformConstants;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.LightingConstants))
            {
                Matrix4x4.Invert(_view, out var viewInverse);
                _lightingConstants.CameraPosition = viewInverse.Translation;

                _lightingConstantBuffer.UpdateData(ref _lightingConstants);

                commandEncoder.SetInlineConstantBuffer(3, _lightingConstantBuffer);

                _dirtyFlags &= ~MeshEffectDirtyFlags.LightingConstants;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.PerDrawConstants))
            {
                _perDrawConstantBuffer.UpdateData(ref _perDrawConstants);

                commandEncoder.SetInlineConstantBuffer(0, _perDrawConstantBuffer);

                _dirtyFlags &= ~MeshEffectDirtyFlags.PerDrawConstants;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.MaterialsBuffer))
            {
                commandEncoder.SetStaticBuffer(6, _materialsBuffer);
                _dirtyFlags &= ~MeshEffectDirtyFlags.MaterialsBuffer;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.Textures))
            {
                commandEncoder.SetTextureSet(7, _textures);
                _dirtyFlags &= ~MeshEffectDirtyFlags.Textures;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.TextureIndicesBuffer))
            {
                commandEncoder.SetStaticBuffer(5, _textureIndicesBuffer);
                _dirtyFlags &= ~MeshEffectDirtyFlags.TextureIndicesBuffer;
            }

            if (_dirtyFlags.HasFlag(MeshEffectDirtyFlags.MaterialIndicesBuffer))
            {
                commandEncoder.SetStaticBuffer(4, _materialIndicesBuffer);
                _dirtyFlags &= ~MeshEffectDirtyFlags.MaterialIndicesBuffer;
            }
        }