How can i use a compiled hlsl-file in WinUI3?

Viewed 46

everyone! I have already used shader language in my WPF project, I just had to create a C#-class which inherits System.Windows.Media.Effects.ShaderEffect and to add dependency properties to properties that I had in hlsl code. But now I have no clue how to deal with that in WinUI 3...

Here is my hlsl code:

sampler2D Input : register(s0);
sampler2D Palette : register(s1);

float4 main(float2 uv : TEXCOORD) : COLOR
{
    float4 c = tex2D(Input, uv.xy);
    float2 index = float2(c.x, 0);
    float4 heat = tex2D(Palette, index);
    return heat;
}

And this was my C# class:

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Media.Media3D;

namespace CompilerForFXFiles.Effects
{
    public class HeatColorizer : System.Windows.Media.Effects.ShaderEffect
    {

        /// <summary></summary>
        public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(HeatColorizer), 0, SamplingMode.Auto);
        /// <summary></summary>
        public static readonly DependencyProperty PaletteProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Palette", typeof(HeatColorizer), 1, SamplingMode.Auto);

        public HeatColorizer()
        {
            PixelShader pixelShader = new PixelShader
            {
                // in the next line it is required to insert an uri, where a compiled ps-file is located
                UriSource = new Uri("/CompilerForFXFiles;component/CompiledShaders/myFile.ps", UriKind.Relative)
            };
            this.PixelShader = pixelShader;
            this.UpdateShaderValue (InputProperty);
            this.UpdateShaderValue (PaletteProperty);
        }

        /// <summary></summary>
        public virtual Brush Input
        {
            get => ((Brush) (this.GetValue(InputProperty)));
            set => this.SetValue(InputProperty, value);
        }

        /// <summary></summary>
        public virtual Brush Palette
        {
            get => ((Brush) (this.GetValue(PaletteProperty)));
            set => this.SetValue (PaletteProperty, value);
        }
    }
}
0 Answers
Related