Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何创建多个着色器效果实例?_C#_Wpf_Shader_Pixel Shader - Fatal编程技术网

C# 如何创建多个着色器效果实例?

C# 如何创建多个着色器效果实例?,c#,wpf,shader,pixel-shader,C#,Wpf,Shader,Pixel Shader,我创建了如下自定义着色器效果: class MyShaderEffect : ShaderEffect { private PixelShader _pixelShader = new PixelShader(); public readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(MyShaderEf

我创建了如下自定义着色器效果:


class MyShaderEffect : ShaderEffect
{
    private PixelShader _pixelShader = new PixelShader();
    public readonly DependencyProperty InputProperty =
        ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(MyShaderEffect), 0);

    public MyShaderEffect()
    {
        _pixelShader.UriSource = new Uri("MyShader.ps", UriKind.Relative);
        this.PixelShader = _pixelShader;
        this.UpdateShaderValue(InputProperty);
    }

    public Brush Input
    {
        get { return (Brush)this.GetValue(InputProperty); }
        set { this.SetValue(InputProperty, value); }
    }
}
我需要对不同的图像应用稍微不同的着色器效果(它有一些参数),但是当我尝试创建第二个MyShaderEffect对象时,我得到了“'Input'属性已注册”异常


有没有办法解决这个问题,这样我就可以从一个着色器创建多个ShaderEffect实例?

依赖项属性应该注册到
静态
字段,因此每个类型只注册一次:

public static readonly DependencyProperty InputProperty =
    ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(MyShaderEffect), 0);

但是其他属性呢?我使用它们来设置着色器参数。如果我将它们设置为静态,那么对于不同的实例,我不能有不同的着色器行为。此字段只是属性的标识符。它是一个键,用于使用
GetValue
SetValue
访问属性值。
输入
属性本身不是静态的。