コード例 #1
0
ファイル: Frame.cs プロジェクト: klenin/Citrus
        internal protected override bool PartialHitTest(ref HitTestArgs args)
        {
            switch (ClipChildren)
            {
            case ClipMethod.None:
                return(base.PartialHitTest(ref args));

            case ClipMethod.ScissorTest:
            case ClipMethod.StencilTest:
                if (!(ClipByWidget ?? this).BoundingRectHitTest(args.Point))
                {
                    return(false);
                }
                EnsureRenderChain();
                try {
                    for (var node = FirstChild; node != null; node = node.NextSibling)
                    {
                        node.RenderChainBuilder?.AddToRenderChain(renderChain);
                    }
                    if (renderChain.HitTest(ref args))
                    {
                        return(true);
                    }
                    return(base.PartialHitTest(ref args));
                } finally {
                    renderChain.Clear();
                }

            case ClipMethod.NoRender:
                return(false);

            default:
                throw new InvalidOperationException();
            }
        }
コード例 #2
0
ファイル: Model3DAttachment.cs プロジェクト: klenin/Citrus
        public override void Render(Node node)
        {
            if (!Animation.IsRunning && !WasSnapshotDeprecated)
            {
                return;
            }

            Scene.RenderToTexture(Snapshot, renderChain);
            renderChain.Clear();
            WasSnapshotDeprecated = false;
        }
コード例 #3
0
ファイル: WindowWidget.cs プロジェクト: aologos/Citrus
        public override void Update(float delta)
        {
            if (ContinuousRendering())
            {
                Window.Invalidate();
            }
            var context = WidgetContext.Current;

            // Find the node under mouse, using the render chain built on one frame before.
            context.NodeUnderMouse = LookForNodeUnderMouse(renderChain);

            // Assign NodeCapturedByMouse if any mouse button was pressed.
            var anyCaptureKeyPressed = IsAnyCaptureKeyPressed();

            if (!prevAnyCaptureKeyPressed && anyCaptureKeyPressed)
            {
                context.NodeCapturedByMouse = context.NodeUnderMouse;
            }

            // Process mouse/touch screen input.
            context.GestureManager.Process();

            // Update the widget hierarchy.
            context.MouseCursor = MouseCursor.Default;
            base.Update(delta);
            Window.Cursor = context.MouseCursor;

            // Set NodeCapturedByMouse to null if all mouse buttons were released.
            if (prevAnyCaptureKeyPressed && !anyCaptureKeyPressed)
            {
                context.NodeCapturedByMouse = null;
            }
            prevAnyCaptureKeyPressed = anyCaptureKeyPressed;

            if (Window.Input.WasKeyPressed(Key.DismissSoftKeyboard))
            {
                SetFocus(null);
            }

            // Refresh widgets layout.
            LayoutManager.Layout();

            RaiseUpdating(delta);

            ManageFocusOnWindowActivation();

            // Rebuild the render chain.
            renderChain.Clear();
            renderChain.ClipRegion = new Rectangle(Vector2.Zero, Size);
            RenderChainBuilder?.AddToRenderChain(renderChain);
        }
コード例 #4
0
        public virtual void Update(float delta)
        {
            if (ContinuousRendering())
            {
                Window.Invalidate();
            }
            var context = WidgetContext.Current;

            // Find the node under mouse, using the render chain built on one frame before.
            context.NodeUnderMouse = LookForNodeUnderMouse(renderChain);

            // Assign NodeCapturedByMouse if any mouse button was pressed or files were dropped.
            var anyCaptureKeyPressed = IsAnyCaptureKeyPressed();

            if (!prevAnyCaptureKeyPressed && anyCaptureKeyPressed || Window.Input.DroppedFiles.Count > 0)
            {
                context.NodeCapturedByMouse = context.NodeUnderMouse;
            }
            else if (
                !anyCaptureKeyPressed ||
                (!(context.NodeCapturedByMouse as Widget)?.GloballyVisible ?? false) ||
                (!(context.NodeCapturedByMouse as Node3D)?.GloballyVisible ?? false)
                )
            {
                // Set NodeCapturedByMouse to null if all mouse buttons are released or widget became invisible.
                context.NodeCapturedByMouse = null;
            }
            prevAnyCaptureKeyPressed = anyCaptureKeyPressed;

            // Update the widget hierarchy.
            context.MouseCursor = MouseCursor.Default;
            Manager.Update(delta);
            Window.Cursor = context.MouseCursor;

            if (Window.Input.WasKeyPressed(Key.DismissSoftKeyboard))
            {
                SetFocus(null);
            }

            ManageFocusOnWindowActivation();

            // Rebuild the render chain.
            renderChain.Clear();
            renderChain.ClipRegion = new Rectangle(Vector2.Zero, Size);
            RenderChainBuilder?.AddToRenderChain(renderChain);
        }
コード例 #5
0
        public RenderObject GetRenderObject(Node node)
        {
            var component = node.Components.Get <PostProcessingComponent>();

            if (component == null)
            {
                throw new InvalidOperationException();
            }

            var ro = RenderObjectPool <PostProcessingRenderObject> .Acquire();

            try {
                component.GetOwnerRenderObjects(renderChain, ro.Objects);
            } finally {
                renderChain.Clear();
            }

            var bufferSize           = component.TextureSizeLimit;
            var widget               = (Widget)node;
            var sourceTextureScaling = Mathf.Min(bufferSize.Width / widget.Width, bufferSize.Height / widget.Height);

            if (sourceTextureBuffer?.Size != bufferSize)
            {
                sourceTextureBuffer = new PostProcessingAction.Buffer(bufferSize);
            }
            if (component.HSLEnabled && colorCorrectionBuffer?.Size != bufferSize)
            {
                colorCorrectionBuffer = new PostProcessingActionColorCorrection.Buffer(bufferSize);
            }
            if (component.BlurEnabled && blurBuffer?.Size != bufferSize)
            {
                blurBuffer = new PostProcessingActionBlur.Buffer(bufferSize);
            }
            if (component.BloomEnabled && bloomBuffer?.Size != bufferSize)
            {
                bloomBuffer = new PostProcessingActionBloom.Buffer(bufferSize);
            }
            if (component.DistortionEnabled && distortionBuffer?.Size != bufferSize)
            {
                distortionBuffer = new PostProcessingActionDistortion.Buffer(bufferSize);
            }
            if (component.SharpenEnabled && sharpenBuffer?.Size != bufferSize)
            {
                sharpenBuffer = new PostProcessingActionSharpen.Buffer(bufferSize);
            }
            if (component.NoiseEnabled && noiseBuffer?.Size != bufferSize)
            {
                noiseBuffer = new PostProcessingActionNoise.Buffer(bufferSize);
            }
            if (component.FXAAEnabled && fxaaBuffer?.Size != bufferSize)
            {
                fxaaBuffer = new PostProcessingActionFXAA.Buffer(bufferSize);
            }
            if ((component.BlurEnabled || component.BloomEnabled) && firstTemporaryBuffer?.Size != bufferSize)
            {
                firstTemporaryBuffer  = new PostProcessingAction.Buffer(bufferSize);
                secondTemporaryBuffer = new PostProcessingAction.Buffer(bufferSize);
            }
            if (component.RequiredRefreshSource)
            {
                sourceTextureBuffer?.MarkAsDirty();
                component.RequiredRefreshSource = false;
            }

            ro.PostProcessingActions = postProcessingActions;
            ro.Material = GetMaterial(widget, component);
            ro.LocalToWorldTransform = widget.LocalToWorldTransform;
            ro.Position = widget.ContentPosition;
            ro.Size     = widget.ContentSize;
            ro.Color    = widget.GlobalColor;
            // TODO: Custom UV?
            ro.UV0                           = Vector2.Zero;
            ro.UV1                           = Vector2.One;
            ro.DebugViewMode                 = component.DebugViewMode;
            ro.MarkBuffersAsDirty            = false;
            ro.SourceTextureBuffer           = sourceTextureBuffer;
            ro.SourceTextureScaling          = sourceTextureScaling;
            ro.FirstTemporaryBuffer          = firstTemporaryBuffer;
            ro.SecondTemporaryBuffer         = secondTemporaryBuffer;
            ro.ColorCorrectionBuffer         = colorCorrectionBuffer;
            ro.ColorCorrectionMaterial       = component.ColorCorrectionMaterial;
            ro.HSLEnabled                    = component.HSLEnabled;
            ro.HSL                           = new Vector3(component.HSL.X * (1f / 360f), component.HSL.Y * 0.01f + 1f, component.HSL.Z * 0.01f + 1f);
            ro.Brightness                    = component.Brightness * 0.01f;
            ro.Contrast                      = component.Contrast * 0.01f + 1f;
            ro.BlurBuffer                    = blurBuffer;
            ro.BlurMaterial                  = component.BlurMaterial;
            ro.BlurEnabled                   = component.BlurEnabled;
            ro.BlurRadius                    = component.BlurRadius;
            ro.BlurShader                    = component.BlurShader;
            ro.BlurTextureScaling            = component.BlurTextureScaling * 0.01f;
            ro.BlurAlphaCorrection           = component.BlurAlphaCorrection;
            ro.BloomBuffer                   = bloomBuffer;
            ro.BloomMaterial                 = component.BloomMaterial;
            ro.BloomEnabled                  = component.BloomEnabled;
            ro.BloomStrength                 = component.BloomStrength;
            ro.BloomShaderId                 = component.BloomShaderId;
            ro.BloomBrightThreshold          = component.BloomBrightThreshold * 0.01f;
            ro.BloomGammaCorrection          = component.BloomGammaCorrection;
            ro.BloomTextureScaling           = component.BloomTextureScaling * 0.01f;
            ro.BloomColor                    = component.BloomColor;
            ro.DistortionBuffer              = distortionBuffer;
            ro.DistortionMaterial            = component.DistortionMaterial;
            ro.DistortionEnabled             = component.DistortionEnabled;
            ro.DistortionBarrelPincushion    = component.DistortionBarrelPincushion * 0.01f;
            ro.DistortionChromaticAberration = component.DistortionChromaticAberration * 0.01f;
            ro.DistortionRed                 = component.DistortionRed * 0.01f;
            ro.DistortionGreen               = component.DistortionGreen * 0.01f;
            ro.DistortionBlue                = component.DistortionBlue * 0.01f;
            ro.SharpenBuffer                 = sharpenBuffer;
            ro.SharpenMaterial               = component.SharpenMaterial;
            ro.SharpenEnabled                = component.SharpenEnabled;
            ro.SharpenStrength               = component.SharpenStrength;
            ro.SharpenLimit                  = component.SharpenLimit;
            ro.SharpenStep                   = component.SharpenStep;
            ro.NoiseBuffer                   = noiseBuffer;
            ro.NoiseMaterial                 = component.NoiseMaterial;
            ro.NoiseEnabled                  = component.NoiseEnabled && component.NoiseTexture != null && !component.NoiseTexture.IsStubTexture;
            ro.NoiseBrightThreshold          = component.NoiseBrightThreshold * 0.01f;
            ro.NoiseDarkThreshold            = component.NoiseDarkThreshold * 0.01f;
            ro.NoiseSoftLight                = component.NoiseSoftLight * 0.01f;
            ro.NoiseOffset                   = component.NoiseOffset;
            ro.NoiseScale                    = component.NoiseScale;
            ro.NoiseTexture                  = component.NoiseTexture;
            ro.FXAABuffer                    = fxaaBuffer;
            ro.FXAAMaterial                  = component.FXAAMaterial;
            ro.FXAAEnabled                   = component.FXAAEnabled;
            ro.FXAALumaTreshold              = component.FXAALumaTreshold;
            ro.FXAAMulReduce                 = component.FXAAMulReduce;
            ro.FXAAMinReduce                 = component.FXAAMinReduce;
            ro.FXAAMaxSpan                   = component.FXAAMaxSpan;
            ro.OverallImpactEnabled          = component.OverallImpactEnabled;
            ro.OverallImpactColor            = component.OverallImpactColor;
            ro.VignetteMaterial              = component.VignetteMaterial;
            ro.TransparentTexture            = transparentTexture;
            ro.VignetteEnabled               = component.VignetteEnabled;
            ro.VignetteRadius                = component.VignetteRadius * 0.01f;
            ro.VignetteSoftness              = component.VignetteSoftness * 0.01f;
            ro.VignetteScale                 = component.VignetteScale;
            ro.VignettePivot                 = component.VignettePivot;
            ro.VignetteColor                 = component.VignetteColor;
            ro.AlphaDiffuseMaterial          = alphaDiffuseMaterial;
            ro.AddDiffuseMaterial            = addDiffuseMaterial;
            ro.OpaqueDiffuseMaterial         = opaqueDiffuseMaterial;
            ro.TextureClearingColor          = component.TextureClearingColor;
            return(ro);
        }
コード例 #6
0
        public void Render(Matrix44 lightView, Matrix44 lightViewProjection, WindowRect lightViewport)
        {
            depthmat.ViewProjection = lightViewProjection;
            map.SetAsRenderTarget();

            Renderer.Clear(1.0f, 1.0f, 1.0f, 1.0f);

            var oldViewport      = Renderer.Viewport;
            var oldWorld         = Renderer.World;
            var oldView          = Renderer.View;
            var oldProj          = Renderer.Projection;
            var oldZTestEnabled  = Renderer.ZTestEnabled;
            var oldZWriteEnabled = Renderer.ZWriteEnabled;
            var oldCullMode      = Renderer.CullMode;

            Renderer.Flush();
            Renderer.Viewport     = lightViewport;
            Renderer.ZTestEnabled = true;

            var list  = new List <RenderItem>();
            var chain = new RenderChain();

            foreach (var node in viewport.Nodes)
            {
                node.AddToRenderChain(chain);
            }

            for (var i = 0; i < RenderChain.LayerCount; i++)
            {
                var layer = chain.Layers[i];
                if (layer == null || layer.Count == 0)
                {
                    continue;
                }
                for (var j = 0; j < layer.Count; j++)
                {
                    var node = layer[j].Node.AsNode3D;
                    list.Add(new RenderItem {
                        Node     = node,
                        Distance = lightView.TransformVector(node.GlobalTransform.Translation).Z
                    });
                }

                list.Sort(RenderOrderComparers.FrontToBack);
                for (int j = 0; j < list.Count; ++j)
                {
                    RenderNode(list[j].Node);
                }
            }

            chain.Clear();

            Renderer.World         = oldWorld;
            Renderer.Viewport      = oldViewport;
            Renderer.View          = oldView;
            Renderer.Projection    = oldProj;
            Renderer.ZTestEnabled  = oldZTestEnabled;
            Renderer.ZWriteEnabled = oldZWriteEnabled;
            Renderer.CullMode      = oldCullMode;

            map.RestoreRenderTarget();
        }