Mikael Gyth
Topic Author
Posts: 33
Joined: 15 Aug 2013, 12:53

Render Texture Does not update Alpha

25 Sep 2014, 17:44

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.
 
User avatar
jsantos
Site Admin
Posts: 2904
Joined: 20 Jan 2012, 17:18
Contact:

Re: Render Texture Does not update Alpha

26 Sep 2014, 10:58

Yes, it is happening because the background is not being cleared. You need a root element with a Background set to transparent, for example:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Background="Transparent">
      <!-- ... -->
</Grid>
Seeing that this generate confusion we are going to include a toggle in the component to indicate this behaviour and the clear color also.
 
Mikael Gyth
Topic Author
Posts: 33
Joined: 15 Aug 2013, 12:53

Re: Render Texture Does not update Alpha

26 Sep 2014, 13:59

Thank you very much for this information :D
 
Basp
Posts: 22
Joined: 08 May 2014, 10:09

Re: Render Texture Does not update Alpha

10 Mar 2015, 18:39

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:
<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>
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:
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));
            });
            
        }                
    }
}
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?
 
User avatar
sfernandez
Site Admin
Posts: 1912
Joined: 22 Dec 2011, 19:20

Re: Render Texture Does not update Alpha

10 Mar 2015, 19:01

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:
<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>
 
Basp
Posts: 22
Joined: 08 May 2014, 10:09

Re: Render Texture Does not update Alpha

11 Mar 2015, 07:49

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.

Who is online

Users browsing this forum: No registered users and 1 guest