Custom Pixel Shader Effect はじめました。(その2)
外から輝度を変更できるように変更。
Brighten.fx は以下。
float Threshold : register(C0); sampler2D input : register(s0); float4 main(float2 uv : TEXCOORD) : COLOR { float4 Color; Color = tex2D(input , uv.xy)*Threshold; return Color; }
BrightenEffect は以下。
public class BrightenEffect : ShaderEffect { private static PixelShader shader = new PixelShader() { UriSource = new Uri("/SilverlightSquare.CustomEffect;component/Assets/Shader/Brighten.ps", UriKind.Relative) }; public BrightenEffect() { this.PixelShader = shader; this.UpdateShaderValue(InputProperty); this.UpdateShaderValue(ThresholdProperty); } public static DependencyProperty ThresholdProperty = DependencyProperty.Register("Threshold", typeof(double), typeof(BrightenEffect), new PropertyMetadata(1d, PixelShaderConstantCallback(0))); public virtual double Threshold { get { return (double)GetValue(ThresholdProperty); } set { SetValue(ThresholdProperty, value); } } public static DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BrightenEffect), 0); public virtual Brush Input { get { return (Brush)GetValue(InputProperty); } set { SetValue(InputProperty, value); } } }