Wpf 像素着色器效果不适用于红色、绿色和;蓝色

Wpf 像素着色器效果不适用于红色、绿色和;蓝色,wpf,image,c#-4.0,hlsl,pixel-shader,Wpf,Image,C# 4.0,Hlsl,Pixel Shader,我真的在寻找一个解决方案来解决应用颜色红、绿和蓝的着色器效果的问题。当我移动红色、绿色和蓝色的滑块时,图像中没有变化 注意:亮度和对比度在此代码中起作用。 ShaderEffect类的代码: public class BrightContrastEffect : ShaderEffect { private static PixelShader m_shader = new PixelShader() { UriSource = MakePackUri("bricon.

我真的在寻找一个解决方案来解决应用颜色
红、绿和蓝的着色器效果的问题。当我移动
红色、绿色和蓝色的滑块时,图像中没有变化

注意:亮度和对比度在此代码中起作用。

ShaderEffect类的代码:

 public class BrightContrastEffect : ShaderEffect
    {
        private static PixelShader m_shader = new PixelShader() { UriSource = MakePackUri("bricon.ps") };

        public BrightContrastEffect()
        {
            PixelShader = m_shader;
            UpdateShaderValue(InputProperty);
            UpdateShaderValue(BrightnessProperty);
            UpdateShaderValue(ContrastProperty);
            UpdateShaderValue(RedProperty);
            UpdateShaderValue(GreenProperty);
            UpdateShaderValue(BlueProperty);
        }

        public static Uri MakePackUri(string relativeFile)
        {
            Assembly a = typeof(BrightContrastEffect).Assembly;
            string assemblyShortName = a.ToString().Split(',')[0];
            string uriString = "pack://application:,,,/" +assemblyShortName +";component/" +relativeFile;
            return new Uri(uriString);
        }

        public Brush Input
        {
            get { return (Brush)GetValue(InputProperty); }
            set { SetValue(InputProperty, value); }
        }

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

        public float Brightness
        {
            get { return (float)GetValue(BrightnessProperty); }
            set { SetValue(BrightnessProperty, value); }
        }

        public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0)));

        public float Contrast
        {
            get { return (float)GetValue(ContrastProperty); }
            set { SetValue(ContrastProperty, value); }
        }

        public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1)));


        public float Red
        {
            get { return (float)GetValue(RedProperty); }
            set { SetValue(RedProperty, value); }
        }

        public static readonly DependencyProperty RedProperty = DependencyProperty.Register("Red", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(2)));

        public float Green
        {
            get { return (float)GetValue(GreenProperty); }
            set { SetValue(RedProperty, value); }
        }

        public static readonly DependencyProperty GreenProperty = DependencyProperty.Register("Green", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3)));

        public float Blue
        {
            get { return (float)GetValue(BlueProperty); }
            set { SetValue(BlueProperty, value); }
        }

        public static readonly DependencyProperty BlueProperty = DependencyProperty.Register("Blue", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(4)));

    }
}
XAML代码:

<Image Name="ViewedPhoto" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Stretch="Uniform"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
            <Image.Effect>
                <l:BrightContrastEffect 
                    Brightness="{Binding ElementName=bVal, Path=Value}"
                    Contrast="{Binding ElementName=cVal, Path=Value}"
                    Red="{Binding ElementName=rVal, Path=Value}"
                    Green="{Binding ElementName=gVal, Path=Value}"
                    Blue="{Binding ElementName=blVal, Path=Value}"
                    />
            </Image.Effect>
</Image>
<!-- Sliders for Reg, Green & Blue -->
<TextBlock Text="Red"/>
<Slider Maximum="1" Minimum="-1" Name="rVal" TickFrequency="1" TickPlacement="BottomRight"/>
<TextBox Text="{Binding ElementName=rVal, Path=Value, 
UpdateSourceTrigger=PropertyChanged}"  TextAlignment="Right" Width="30" />

<TextBlock Text="Green"/>
<Slider Maximum="1" Minimum="-1" Name="gVal" TickFrequency="1" TickPlacement="BottomRight"/>
<TextBox Text="{Binding ElementName=gVal, Path=Value, 
UpdateSourceTrigger=PropertyChanged}"  TextAlignment="Right" Width="30" />

<TextBlock Text="Blue"/>
<Slider Maximum="1" Minimum="-1" Name="blVal" TickFrequency="1" TickPlacement="BottomRight"/>
<TextBox Text="{Binding ElementName=blVal, Path=Value, 
UpdateSourceTrigger=PropertyChanged}"  TextAlignment="Right" Width="30" />

这是根据Nico Schertler

float Brightness : register(C0);
float Contrast : register(C1);
float Red: register(C2);
float Green: register(C3);
float Blue: register(C4);

sampler2D Texture1Sampler : register(S0);

float4 main(float2 uv : TEXCOORD) : COLOR
{

    float4 pixelColor = tex2D(Texture1Sampler, uv);
    pixelColor.rgb /= pixelColor.a;

    // Apply contrast.
    //pixelColor.rgb = ((pixelColor.rgb - 1.5f) * max(Contrast, 1)) + 1.5f;
    pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(Contrast+1, 0)) + 0.5f;

    // Apply brightness.
    pixelColor.rgb += Brightness;


    // Return final pixel color.
    pixelColor.rgb *= pixelColor.a;

    pixelColor.r += Red;
    pixelColor.g += Green;
    pixelColor.b += Blue;

//return float4(Red, Green Blue, 1);
    return pixelColor;
}

很抱歉,我帮不上什么忙了。最后一个想法:更改着色器后是否重新编译了它?@NicoSchertler/我放置了bricon.pasas资源(不要复制),因此每次单击“重建”时它都会编译……如果我错了,请纠正我。至少我做得对吗?如果你有一个合适的构建规则。*.ps文件必须在某个位置。检查一下它的修改日期。@NicoSchertler:捕捉得好。该文件于23032014修改。如何重新构建/编译.ps文件.Hm。。不知道你的环境是什么样子。尝试右键单击并构建/编译/类似的内容。
float Brightness : register(C0);
float Contrast : register(C1);
float Red: register(C2);
float Green: register(C3);
float Blue: register(C4);

sampler2D Texture1Sampler : register(S0);

float4 main(float2 uv : TEXCOORD) : COLOR
{

    float4 pixelColor = tex2D(Texture1Sampler, uv);
    pixelColor.rgb /= pixelColor.a;

    // Apply contrast.
    //pixelColor.rgb = ((pixelColor.rgb - 1.5f) * max(Contrast, 1)) + 1.5f;
    pixelColor.rgb = ((pixelColor.rgb - 0.5f) * max(Contrast+1, 0)) + 0.5f;

    // Apply brightness.
    pixelColor.rgb += Brightness;


    // Return final pixel color.
    pixelColor.rgb *= pixelColor.a;

    pixelColor.r += Red;
    pixelColor.g += Green;
    pixelColor.b += Blue;

//return float4(Red, Green Blue, 1);
    return pixelColor;
}