Пример #1
0
        private void Draw2D(RenderDrawContext context, RenderBackground renderBackground)
        {
            var target         = context.CommandList.RenderTarget;
            var graphicsDevice = context.GraphicsDevice;
            var destination    = new RectangleF(0, 0, 1, 1);

            var texture             = renderBackground.Texture;
            var textureIsLoading    = texture.ViewType == ViewType.Full && texture.FullQualitySize.Width != texture.ViewWidth;
            var textureSize         = textureIsLoading ? texture.FullQualitySize: new Size3(texture.ViewWidth, texture.ViewHeight, texture.ViewDepth);
            var imageBufferMinRatio = Math.Min(textureSize.Width / (float)target.ViewWidth, textureSize.Height / (float)target.ViewHeight);
            var sourceSize          = new Vector2(target.ViewWidth * imageBufferMinRatio, target.ViewHeight * imageBufferMinRatio);
            var source = new RectangleF((textureSize.Width - sourceSize.X) / 2, (textureSize.Height - sourceSize.Y) / 2, sourceSize.X, sourceSize.Y);

            if (textureIsLoading)
            {
                var verticalRatio   = texture.ViewHeight / (float)textureSize.Height;
                var horizontalRatio = texture.ViewWidth / (float)textureSize.Width;
                source.X      *= horizontalRatio;
                source.Width  *= horizontalRatio;
                source.Y      *= verticalRatio;
                source.Height *= verticalRatio;
            }

            backgroundEffect.UpdateEffect(graphicsDevice);
            spriteBatch.Begin(context.GraphicsContext, SpriteSortMode.FrontToBack, BlendStates.Opaque, graphicsDevice.SamplerStates.LinearClamp, DepthStencilStates.DepthRead, null, backgroundEffect);
            spriteBatch.Parameters.Set(BackgroundShaderKeys.Intensity, renderBackground.Intensity);
            spriteBatch.Draw(texture, destination, source, Color.White, 0, Vector2.Zero, layerDepth: -0.5f);
            spriteBatch.End();
        }
Пример #2
0
        private void DrawCube(RenderDrawContext context, RenderView renderView, RenderBackground renderBackground)
        {
            var graphicsDevice = context.GraphicsDevice;
            var destination    = new RectangleF(0, 0, 1, 1);

            var texture = renderBackground.Texture;

            skyboxBackgroundEffect.UpdateEffect(graphicsDevice);
            spriteBatch.Begin(context.GraphicsContext, SpriteSortMode.FrontToBack, BlendStates.Opaque, graphicsDevice.SamplerStates.LinearClamp, DepthStencilStates.DepthRead, null, skyboxBackgroundEffect);
            spriteBatch.Parameters.Set(SkyboxShaderKeys.Intensity, renderBackground.Intensity);
            spriteBatch.Parameters.Set(SkyboxShaderKeys.ViewInverse, Matrix.Invert(renderView.View));
            spriteBatch.Parameters.Set(SkyboxShaderKeys.ProjectionInverse, Matrix.Invert(renderView.Projection));
            spriteBatch.Parameters.Set(SkyboxShaderKeys.SkyMatrix, Matrix.Invert(Matrix.RotationQuaternion(renderBackground.Rotation)));
            spriteBatch.Parameters.Set(SkyboxShaderKeys.CubeMap, renderBackground.Texture);
            spriteBatch.Draw(texture, destination, null, Color.White, 0, Vector2.Zero, layerDepth: -0.5f);
            spriteBatch.End();
        }