View Issue Details

IDProjectCategoryView StatusLast Update
0002615NoesisGUIUnity3Dpublic2023-08-23 19:07
Reporterstonstad Assigned Tosfernandez  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.2.1 
Target Version3.2.2Fixed in Version3.2.2 
Summary0002615: BackgroundEffect behavior being invalidated per frame
DescriptionFrom forum post: https://www.noesisengine.com/forums/viewtopic.php?t=2957

The Adorner used by the BackgroundEffect is being invalidated per frame and unnecessary calculations are made, even if the Source hasn't changed.
TagsNo tags attached.
PlatformAny

Relationships

related to 0002578 resolvedsfernandez Unwanted Blur Effect Margin Behavior 

Activities

sfernandez

sfernandez

2023-06-01 12:39

manager   ~0008520

Could you please try the following patch:

Index: BackgroundEffectBehavior.cs
===================================================================
--- BackgroundEffectBehavior.cs	(revision 12541)
+++ BackgroundEffectBehavior.cs	(working copy)
@@ -119,10 +119,17 @@
 
         private void OnElementUpdated(object sender, EventArgs e)
         {
-            if (_adorner != null)
+            FrameworkElement element = AssociatedObject;
+            if (_adorner != null && Source != null && element.IsVisible && element.Opacity > 0.0f)
             {
-                AdornerLayer adorners = AdornerLayer.GetAdornerLayer(AssociatedObject);
-                adorners.Update(AssociatedObject);
+                Matrix4 mtx = element.TransformToVisual(Source);
+                if (_adorner.TransformToSource != mtx)
+                {
+                    _adorner.TransformToSource = mtx;
+
+                    AdornerLayer adorners = AdornerLayer.GetAdornerLayer(element);
+                    adorners.Update(element);
+                }
             }
         }
 
@@ -155,6 +162,13 @@
                 IsHitTestVisible = false;
             }
 
+            private Matrix4 _mtx = Matrix4.Identity;
+            public Matrix4 TransformToSource
+            {
+                get => _mtx;
+                set { _mtx = value; }
+            }
+
 #if UNITY_5_3_OR_NEWER
             internal
 #endif
@@ -180,20 +194,15 @@
                 Size adornedSize = adornedElement.RenderSize;
                 Size finalSize = adornedSize;
 
+                Point offset = _mtx[3].XY + new Point(0.0f, 0.0f);
+                Rect bounds = _mtx.TransformBounds(new Rect(adornedSize));
+                finalSize.Width = bounds.Width;
+                finalSize.Height = bounds.Height;
+
                 VisualBrush sourceBrush = (VisualBrush)_child.Background;
-                Visual source = sourceBrush.Visual;
-                if (source != null)
-                {
-                    Matrix4 mtx = adornedElement.TransformToVisual(source);
-                    Point offset = mtx[3].XY + new Point(-1.5f, 1.5f);
-                    Rect bounds = mtx.TransformBounds(new Rect(adornedSize));
-                    finalSize.Width = bounds.Width;
-                    finalSize.Height = bounds.Height;
+                sourceBrush.Viewbox = new Rect(offset, finalSize);
+                _targetBrush.Viewbox = new Rect(finalSize);
 
-                    sourceBrush.Viewbox = new Rect(offset, finalSize);
-                    _targetBrush.Viewbox = new Rect(finalSize);
-                }
-
                 _child.Measure(finalSize);
                 return finalSize;
             }

stonstad

stonstad

2023-06-01 13:23

reporter   ~0008521

That was it. It totally fixed it. Thank you, thank you, thank you!

I have a demo with a game publisher next week and I was sweating bullets. Thank you!
sfernandez

sfernandez

2023-06-01 13:52

manager   ~0008522

Glad to be helpful :)
stonstad

stonstad

2023-06-16 00:59

reporter   ~0008554

I'm seeing a strange issue w/ all instances of BackgoundEffect.

Here's a video of what I am seeing: https://stellarconquest.blob.core.windows.net/tmp/Movie_001.mp4

I have breakpoints on code that touches this UI, and nothing is firing -- meaning that I am not seeing resize, or loaded events. The content is static.

 Is it possible the fix with adorners might cause this behavior? The behavior seems to happen more on larger window sizes.
sfernandez

sfernandez

2023-06-16 10:29

manager   ~0008555

What I'm supposed to see in the video? Could you please elaborate a bit more what the problem is?
stonstad

stonstad

2023-06-16 16:29

reporter   ~0008556

Last edited: 2023-06-16 16:32

At t=12s and t=18s the visual content of the backgroundeffect shifts up and then down. I am not seeing any resize or layout events in my code, however. This happens to all instances of BackgroundEffect.
sfernandez

sfernandez

2023-07-10 20:35

manager   ~0008601

Last edited: 2023-07-10 20:36

From what I see in the video, the blurred background is displaced when a green hexagon appears at the bottom of the screen. How is that rendered, using a visual brush?
If that is the case we fixed an issue related to visual brushes, could you please try the following patched library: https://drive.google.com/file/d/1SIvl6vhJcoZgBAPsxUbGztJGWLahfYbA/view?usp=sharing
stonstad

stonstad

2023-07-11 15:50

reporter   ~0008603

There are brushes involved:

  <Grid Grid.Row="1">
                            <Path x:Name="_BottomPanelBlur">
                                <b:Interaction.Behaviors>
                                    <noesis:BackgroundEffectBehavior Source="{Binding ElementName=_BackgroundBlurSource}">
                                        <BlurEffect Radius="{Binding Radius, Source={StaticResource BottomBlurRadius}}"/>
                                    </noesis:BackgroundEffectBehavior>
                                </b:Interaction.Behaviors>
                            </Path>
                            <Path x:Name="_BottomPanelColor" Fill="{StaticResource DefaultUI.Brush.Bottom.Gradient}" Stroke="{StaticResource DefaultUI.Brush.Border}" Margin="0,-1,0,0" Opacity="0.5">
                                <Path.Effect>
                                    <DropShadowEffect Direction="270" Opacity="0.365" BlurRadius="20" ShadowDepth="18"/>
                                </Path.Effect>
                            </Path>
                        </Grid>

Not sure if that satisfies the condition. I am trying the library now. Thank you!
stonstad

stonstad

2023-07-11 15:57

reporter   ~0008604

I'm not seeing the behavior. I did rewrite my targeting UI -- which relates to the behavior you observed. Perhaps having the UI element go outside the bounds of its containers contributed to the behavior? I no longer see it with this DLL. Thank you!
sfernandez

sfernandez

2023-08-23 19:06

manager   ~0008662

Resolved in changeset 12542

Issue History

Date Modified Username Field Change
2023-06-01 12:30 sfernandez New Issue
2023-06-01 12:31 sfernandez Reporter sfernandez => stonstad
2023-06-01 12:31 sfernandez Assigned To => sfernandez
2023-06-01 12:31 sfernandez Status new => assigned
2023-06-01 12:31 sfernandez Target Version => 3.2.2
2023-06-01 12:39 sfernandez Status assigned => feedback
2023-06-01 12:39 sfernandez Note Added: 0008520
2023-06-01 13:23 stonstad Note Added: 0008521
2023-06-01 13:23 stonstad Status feedback => assigned
2023-06-01 13:49 sfernandez Summary BackgroundEffect behavior being invalidating per frame => BackgroundEffect behavior being invalidated per frame
2023-06-01 13:52 sfernandez Status assigned => resolved
2023-06-01 13:52 sfernandez Resolution open => fixed
2023-06-01 13:52 sfernandez Fixed in Version => 3.2.2
2023-06-01 13:52 sfernandez Note Added: 0008522
2023-06-16 00:59 stonstad Status resolved => feedback
2023-06-16 00:59 stonstad Resolution fixed => reopened
2023-06-16 00:59 stonstad Note Added: 0008554
2023-06-16 10:29 sfernandez Note Added: 0008555
2023-06-16 16:29 stonstad Note Added: 0008556
2023-06-16 16:29 stonstad Status feedback => assigned
2023-06-16 16:31 stonstad Note Edited: 0008556
2023-06-16 16:32 stonstad Note Edited: 0008556
2023-07-10 20:35 sfernandez Status assigned => feedback
2023-07-10 20:35 sfernandez Note Added: 0008601
2023-07-10 20:36 sfernandez Note Edited: 0008601
2023-07-11 15:50 stonstad Note Added: 0008603
2023-07-11 15:50 stonstad Status feedback => assigned
2023-07-11 15:57 stonstad Note Added: 0008604
2023-08-23 19:06 sfernandez Status assigned => resolved
2023-08-23 19:06 sfernandez Resolution reopened => fixed
2023-08-23 19:06 sfernandez Note Added: 0008662
2023-08-23 19:07 sfernandez Relationship added related to 0002578