Esempio n. 1
0
        public void SetRenderTargetsDepth(IRenderTarget2D depth)
        {
            if (depth == null)
            {
                if (currentDepthTarget != null)
                {
                    currentDepthTarget = null;
                    renderTargetsDirty = true;
                }
                return;
            }
            var dxDepth = graphicsDevice.Cast <Texture2D>(depth, "depth");

            if (dxDepth.DepthView == null)
            {
                throw new ArgumentException("Texture is not a depth render target.", "depth");
            }

            if (dxDepth.DepthView == currentDepthTarget)
            {
                return;
            }

            currentDepthTarget = dxDepth.DepthView;
            renderTargetsDirty = true;
        }
Esempio n. 2
0
        public ViewModelInventorySkeletonViewData(
            ICharacter character,
            IClientSceneObject sceneObjectCamera,
            IClientSceneObject sceneObjectSkeleton,
            ICamera2D camera,
            IRenderTarget2D renderTarget2D,
            string renderingTag,
            float textureWidth,
            float textureHeight)
        {
            this.character = character;

            this.equipmentContainer = (IClientItemsContainer)character
                                      .GetPublicState <ICharacterPublicStateWithEquipment>()
                                      .ContainerEquipment;

            this.equipmentContainer.StateHashChanged += this.EquipmentContainerStateHashChangedHandler;

            this.sceneObjectCamera   = sceneObjectCamera;
            this.sceneObjectSkeleton = sceneObjectSkeleton;
            this.camera = camera;

            this.renderTarget2D = renderTarget2D;
            this.renderingTag   = renderingTag;
            this.textureWidth   = textureWidth;
            this.textureHeight  = textureHeight;
            this.ImageBrush     = InventorySkeletonViewHelper.Client.UI.CreateImageBrushForRenderTarget(
                renderTarget2D);

            this.ImageBrush.Stretch = Stretch.Uniform;

            // subscribe on change of the face
            // commented out - no need, the skeleton will be rebuilt completely
            //var publicState = PlayerCharacter.GetPublicState(character);
            //publicState.ClientSubscribe(
            //    _ => _.FaceStyle,
            //    _ => this.OnNeedRefreshEquipment(),
            //    this);

            // subscribe on change of the equipment
            var clientState = PlayerCharacter.GetClientState(character);

            clientState.ClientSubscribe(
                _ => _.LastEquipmentContainerHash,
                _ => this.OnNeedRefreshEquipment(),
                this);

            var publicState = PlayerCharacter.GetPublicState(character);

            publicState.ClientSubscribe(
                _ => _.IsHeadEquipmentHiddenForSelfAndPartyMembers,
                _ => this.OnNeedRefreshEquipment(),
                this);

            //this.RefreshEquipment();
            this.OnNeedRefreshEquipment();
        }
Esempio n. 3
0
 public void SetRenderTargetsDepth(IRenderTarget2D depth)
 {
     if (depth != null)
     {
         Texture2D texture = graphicsDevice.Cast <Texture2D>(depth, "depth");
         currentDepthRenderTarget = texture.TextureID;
         currentDepthFormat       = texture.Format;
     }
     else
     {
         currentDepthRenderTarget = -1;
     }
 }
        private void DrawFullscreenQuad(
            IRenderTarget2D textureToDraw,
            int width,
            int height,
            EffectInstance effect,
            IntermediateBuffer currentBuffer,
            BlendMode blendState = BlendMode.AlphaBlendPremultiplied)
        {
            if (DisplayedBuffer < currentBuffer)
            {
                // The user has selected one of the show intermediate buffer options,
                // we still draw the quad to make sure the image will end up on the screen,
                // but might need to skip applying the custom pixel shader.
                effect = null;
            }

            // Clear with transparent black. Must do this for each target if using transparent target.
            this.device.Clear(Color.FromArgb(255, 0, 0, 0));
            this.device.DrawTexture(textureToDraw, width, height, effect, blendState);
        }
        public override void Render(IRenderTarget2D source, IRenderTarget2D destination)
        {
            // The render targets will be half the size of the viewport in order to minimize fillrate.
            // It doesn't affect the quality as we will apply blur.
            // TODO: it seems we can decrease it further more.
            var size = Rendering.ViewportSize;

            size = new Vector2Ushort((ushort)(size.X / 2),
                                     (ushort)(size.Y / 2));

            if (this.lastTextureSize != size)
            {
                this.lastTextureSize = size;
                // this must be reset in order to reassign source texture to effect
                this.lastBloomCombineSource = null;
                this.isBlurParametersDirty  = true;
            }

            using (var renderTarget1 = Rendering.GetTempRenderTexture(size.X, size.Y))
                using (var renderTarget2 = Rendering.GetTempRenderTexture(size.X, size.Y))
                {
                    if (this.isBlurParametersDirty)
                    {
                        this.SetBlurParameters(size);
                    }

                    // clear render target 1
                    this.device.SetRenderTarget(renderTarget1);
                    this.device.Clear(Color.FromArgb(0, 0, 0, 0));

                    // Pass 1: draw the scene into rendertarget 1,
                    // using a shader that extracts only the brightest parts of the image.
                    this.DrawFullscreenQuad(
                        source,
                        renderTarget1.Width,
                        renderTarget1.Height,
                        this.effectBloomExtract,
                        IntermediateBuffer.PreBloom,
                        blendState: BlendMode.Opaque);

                    // Pass 2: draw from rendertarget 1 into rendertarget 2,
                    // using a shader to apply a horizontal gaussian blur filter.
                    this.device.SetRenderTarget(renderTarget2);
                    this.DrawFullscreenQuad(
                        renderTarget1,
                        renderTarget2.Width,
                        renderTarget2.Height,
                        this.effectBlurHorizontal,
                        IntermediateBuffer.BlurredHorizontally);

                    // Pass 3: draw from rendertarget 2 back into rendertarget 1,
                    // using a shader to apply a vertical gaussian blur filter.
                    this.device.SetRenderTarget(renderTarget1);
                    this.DrawFullscreenQuad(
                        renderTarget2,
                        renderTarget1.Width,
                        renderTarget1.Height,
                        this.effectBlurVertical,
                        IntermediateBuffer.BlurredBothWays);

                    // Pass 4: draw both rendertarget 1 and the original scene image into the destination,
                    // using a shader that combines them to produce the final bloomed result.
                    this.device.SetRenderTarget(destination);

                    if (this.lastBloomCombineSource != source)
                    {
                        this.lastBloomCombineSource = source;
                        this.effectBloomCombine.Parameters.Set("BaseTexture", source);
                    }

                    var viewport = Rendering.ViewportSize;
                    this.DrawFullscreenQuad(
                        renderTarget1,
                        viewport.X,
                        viewport.Y,
                        this.effectBloomCombine,
                        IntermediateBuffer.FinalResult,
                        blendState: BlendMode.Opaque);
                }
        }
Esempio n. 6
0
        public static async Task <IRenderTarget2D> ApplyMaskToRenderTargetAsync(
            ProceduralTextureRequest request,
            IRenderTarget2D sourceRenderTarget,
            TextureResource maskResource)
        {
            var textureWidth     = (ushort)sourceRenderTarget.Width;
            var textureHeight    = (ushort)sourceRenderTarget.Height;
            var maskSizeAbsolute = await Renderer.GetTextureSize(maskResource);

            var maskScale = new Vector2F((float)(textureWidth / (double)maskSizeAbsolute.X),
                                         (float)(textureHeight / (double)maskSizeAbsolute.Y));

            var maskOffset = new Vector2F((float)((maskSizeAbsolute.X - textureWidth) / (2.0 * textureWidth)),
                                          (float)((maskSizeAbsolute.Y - textureHeight) / (2.0 * textureHeight)));

            /*Api.Logger.Dev(
            *   string.Format("Texture size: X={0} Y={1}"
            + "{2}Mask size: X={3} Y={4}"
            + "{2}Mask scale: X={5:F2} Y={6:F2}"
            + "{2}Mask offset: X={7:F2} Y={8:F2}",
            +                 textureWidth,
            +                 textureHeight,
            +                 Environment.NewLine,
            +                 maskSizeAbsolute.X,
            +                 maskSizeAbsolute.Y,
            +                 maskScale.X,
            +                 maskScale.Y,
            +                 maskOffset.X,
            +                 maskOffset.Y));*/

            var renderingMaterial = RenderingMaterial.Create(new EffectResource("DrawWithMaskOffset"));

            renderingMaterial.EffectParameters
            .Set("MaskTextureArray", maskResource)
            .Set("MaskScale", maskScale)
            .Set("MaskOffset", maskOffset);

            var renderingTag = "Mask camera for procedural texture: " + request.TextureName;
            var cameraObject = Api.Client.Scene.CreateSceneObject(renderingTag);
            var camera       = Renderer.CreateCamera(cameraObject,
                                                     renderingTag: renderingTag,
                                                     drawOrder: -10,
                                                     drawMode: CameraDrawMode.Manual);

            var renderTarget = Renderer.CreateRenderTexture(renderingTag, textureWidth, textureHeight);

            camera.RenderTarget = renderTarget;
            camera.ClearColor   = Color.FromArgb(0, 0, 0, 0);
            camera.SetOrthographicProjection(textureWidth, textureHeight);

            Renderer.CreateSpriteRenderer(cameraObject,
                                          sourceRenderTarget,
                                          renderingTag: renderingTag,
                                          // draw down
                                          spritePivotPoint: (0, 1))
            .RenderingMaterial = renderingMaterial;

            await camera.DrawAsync();

            cameraObject.Destroy();
            request.ThrowIfCancelled();

            return(renderTarget);
        }
Esempio n. 7
0
 public void SetRenderTargets(IRenderTarget2D depth, params IRenderTarget2D[] colorTargets)
 {
     SetRenderTargetsColor(colorTargets);
     SetRenderTargetsDepth(depth);
 }