-
- Mikael Gyth
- Posts: 33
- Joined:
Render Texture Does not update Alpha
Hello.
I realize that this might not be a Noesis specific question but I hope someone here knows the solution anyway.
I am rendering a XAML to a render texture and it is working as expected. But when I add an animation to the XAML, the Alpha of the Render Texture doesn't update and as a result the image rendered in the previous frame is still there when the new one is rendered. So if I have a dot moving in a square it ends looking like a square.
I am guessing that there is a shader out there that will resolve this issue but I have been unable to find one, and do not know them well enough to write my own.
I have also noticed that rendering semitransparent images does not work, atleast with the shaders I have tried. They keep adding to eachother untill they are opaque.
I realize that this might not be a Noesis specific question but I hope someone here knows the solution anyway.
I am rendering a XAML to a render texture and it is working as expected. But when I add an animation to the XAML, the Alpha of the Render Texture doesn't update and as a result the image rendered in the previous frame is still there when the new one is rendered. So if I have a dot moving in a square it ends looking like a square.
I am guessing that there is a shader out there that will resolve this issue but I have been unable to find one, and do not know them well enough to write my own.
I have also noticed that rendering semitransparent images does not work, atleast with the shaders I have tried. They keep adding to eachother untill they are opaque.
Re: Render Texture Does not update Alpha
Yes, it is happening because the background is not being cleared. You need a root element with a Background set to transparent, for example:
Seeing that this generate confusion we are going to include a toggle in the component to indicate this behaviour and the clear color also.
Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Transparent">
<!-- ... -->
</Grid>
-
- Mikael Gyth
- Posts: 33
- Joined:
Re: Render Texture Does not update Alpha
Thank you very much for this information 

Re: Render Texture Does not update Alpha
I'm having the same problem, but setting the Root element to Background="Transparent" doesn't work, it still overdraws.
I have the following xaml:
I have a 3D plane that has a RenderTexture (shader is Unlit/Transparent) and a Noesis GUIPanel set to the above xaml. A codebehind script updates the RotateTransform angles periodically:
I'm seeing the control, but as soon as the angles update, I see the rectangles at both the old angles and the new ones. Apparently it is not getting cleared. What am I doing wrong?
I have the following xaml:
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Background="Transparent"
Margin="0,0,0,12"
x:Class="TUDelftMap.Clock">
<Viewbox>
<Grid Background="Transparent" Height="512" Width="512">
<Image Source="Images/clockbg.png" />
<Grid Width="512" Height="512" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform>
<RotateTransform x:Name="MinuteHandTransform" Angle="360" />
</Grid.RenderTransform>
<Rectangle Width="10" Height="245" Fill="Black" Stroke="Black" VerticalAlignment="Top" Margin="0,10,0,0" />
</Grid>
<Grid Width="512" Height="512" RenderTransformOrigin="0.5,0.5" >
<Grid.RenderTransform>
<RotateTransform x:Name="HourHandTransform" Angle="120" />
</Grid.RenderTransform>
<Rectangle Width="10" Height="150" Fill="Black" Stroke="Black" VerticalAlignment="Top" Margin="0,100,0,0" />
</Grid>
</Grid>
</Viewbox>
</UserControl>
Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Noesis;
using System.Timers;
namespace TUDelftMap
{
[Noesis.Extended]
[Noesis.UserControlSource("Assets/GUI/Clock.xaml")]
public class Clock : Noesis.UserControl
{
Timer timer = new Timer(1000);
private RotateTransform minuteHandTransform = null;
private RotateTransform hourHandTransform = null;
public void OnPostInit()
{
this.minuteHandTransform = FindName<RotateTransform>("MinuteHandTransform");
this.hourHandTransform = FindName<RotateTransform>("HourHandTransform");
timer.Elapsed += timer_Elapsed;
timer.Start();
}
void timer_Elapsed(object sender, ElapsedEventArgs e)
{
UnityThreadHelper.Dispatcher.Dispatch(() =>
{
this.minuteHandTransform.SetAngle(DateTime.Now.Minute * 6);
this.hourHandTransform.SetAngle((DateTime.Now.Hour * 30) + (DateTime.Now.Minute * 0.5f));
});
}
}
}
-
-
sfernandez
Site Admin
- Posts: 3238
- Joined:
Re: Render Texture Does not update Alpha
In NoesisGUI 1.1 version we clear the surface when the root element (in fact the first element drawing a rectangular shape to the surface) is exactly the same size as the surface.
I see in the attached xaml that you are setting a margin in the root. You can move that margin to a inner element so root element keeps surface size and can be used to clear the surface:
I see in the attached xaml that you are setting a margin in the root. You can move that margin to a inner element so root element keeps surface size and can be used to clear the surface:
Code: Select all
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:System="clr-namespace:System;assembly=mscorlib"
mc:Ignorable="d"
Background="Transparent"
x:Class="TUDelftMap.Clock">
<Grid Margin="0,0,0,12">
<Viewbox .../>
</Grid>
</UserControl>
Re: Render Texture Does not update Alpha
Excellent. I'm not sure what that margin was doing there (presumably Blend inserted it) so I got rid of it and it worked. I'm glad this occurred though, because I wouldn't have known about the clearing occurring only if the root element is the same size as the surface.
Thanks for the fast response, once again! NoesisGUI and the support from these forums has really been excellent for us.
Thanks for the fast response, once again! NoesisGUI and the support from these forums has really been excellent for us.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 45 guests