From: HOSOKAWA Kenchi Date: Wed, 30 Mar 2011 01:44:52 +0000 (+0900) Subject: 123 X-Git-Url: http://git.osdn.jp/view?p=psychlops%2Fsilverlight.git;a=commitdiff_plain;h=0518057c18438b6b749a3845c8eeeb5402ee893b 123 --- diff --git a/dev4/Shader/GaborAlpha.fx b/dev4/Shader/GaborAlpha.fx index 095d01f..0a162e8 100644 --- a/dev4/Shader/GaborAlpha.fx +++ b/dev4/Shader/GaborAlpha.fx @@ -53,7 +53,7 @@ float4 main(float2 uv : TEXCOORD) : COLOR float env = exp( -(_r*_r) / (2.0) ) * alpha; float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1]; - float l = 0.5+env*contrast*0.5*cos(frequency*_x + phase); + float l = 0.5+contrast*0.5*cos(frequency*_x + phase); float4 color = float4(l,l,l,1.0); return color; diff --git a/dev4/Shader/GaborAlpha.ps b/dev4/Shader/GaborAlpha.ps index 5a395e2..1d39b76 100644 Binary files a/dev4/Shader/GaborAlpha.ps and b/dev4/Shader/GaborAlpha.ps differ diff --git a/dev4/psychlops/extention/standard/shader.cs b/dev4/psychlops/extention/standard/shader.cs index af94a38..8a511b6 100644 --- a/dev4/psychlops/extention/standard/shader.cs +++ b/dev4/psychlops/extention/standard/shader.cs @@ -78,6 +78,63 @@ namespace Psychlops } + + + public class ShaderGaborAlpha : ShaderField + { + protected Shader.GaborAlphaProgram ps = null; + public ShaderGaborAlpha() + { + initialize__ = initialize___; + setParameters = setParameters__; + } + internal void initialize() + { + if (!initialized) + { + Main.canvas.beginInvoke(initialize___); + initialized = true; + } + } + internal void initialize___() + { + if (!initialized) + { + if (ps == null) + { + ps = new Shader.GaborAlphaProgram(); + initializeShader(); + } + shader = ps; + initialized = true; + } + } + + //public double contrast { get; set; } + //public double frequency { get; set; } + //public double phase { get; set; } + //public double orientation { get; set; } + public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0, alpha = 1.0; + public ShaderGaborAlpha setSigma(double s) + { + set(s * 8, s * 8); + return this; + } + + public void setParameters__() + { + ps.Contrast = contrast; + ps.WaveLength = wavelength; + ps.Phase = phase; + ps.Orientation = orientation; + ps.Sigma = 4.0; + ps.Size = width; + ps.Alpha = alpha; + ps.Update(); + } + + + } } @@ -93,6 +150,7 @@ namespace Psychlops { } + #region GaborProgram public class GaborProgram : ShaderProgram { public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/Gabor.ps", UriKind.Relative); @@ -220,7 +278,137 @@ namespace Psychlops } } } + #endregion + + #region GaborAlphaProgram + public class GaborAlphaProgram : ShaderProgram + { + public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/GaborAlpha.ps", UriKind.Relative); + + public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GaborAlphaProgram), 0); + public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1))); + public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2))); + public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3))); + public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4))); + public static readonly DependencyProperty SigmaProperty = DependencyProperty.Register("Sigma", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(4D)), PixelShaderConstantCallback(5))); + public static readonly DependencyProperty AlphaProperty = DependencyProperty.Register("Alpha", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(6))); + public GaborAlphaProgram() + { + PixelShader pixelShader = new PixelShader(); + pixelShader.UriSource = ps; + this.PixelShader = pixelShader; + + this.UpdateShaderValue(InputProperty); + this.UpdateShaderValue(ContrastProperty); + this.UpdateShaderValue(FrequencyProperty); + this.UpdateShaderValue(PhaseProperty); + this.UpdateShaderValue(OrientationProperty); + this.UpdateShaderValue(SigmaProperty); + this.UpdateShaderValue(AlphaProperty); + + Size = 200; + Contrast = 1.0; + WaveLength = 100.0; + Orientation = 0.0; + Sigma = 4.0; + Alpha = 1.0; + } + + public void Update() + { + this.UpdateShaderValue(InputProperty); + this.UpdateShaderValue(ContrastProperty); + this.UpdateShaderValue(FrequencyProperty); + this.UpdateShaderValue(PhaseProperty); + this.UpdateShaderValue(OrientationProperty); + this.UpdateShaderValue(SigmaProperty); + this.UpdateShaderValue(AlphaProperty); + } + + private double size__, wavelength__; + public double Size { get { return size__; } set { size__ = value; setFrequency(); } } + private void setFrequency() + { + double freq = size__ * 2.0 * Math.PI / (wavelength__); + this.SetValue(FrequencyProperty, freq); + } + + /// Amplitude of Grating + public double Contrast + { + get + { + return ((double)(this.GetValue(ContrastProperty))) * 2.0; + } + set + { + this.SetValue(ContrastProperty, value / 2.0); + } + } + /// Phase of Grating + public double WaveLength + { + get + { + return wavelength__; + } + set + { + wavelength__ = value; + setFrequency(); + } + } + /// Phase of Grating + public double Phase + { + get + { + return ((double)(this.GetValue(PhaseProperty))); + } + set + { + this.SetValue(PhaseProperty, value); + } + } + /// Orientation of Grating + public double Orientation + { + get + { + return ((double)(this.GetValue(OrientationProperty))); + } + set + { + this.SetValue(OrientationProperty, value); + } + } + /// Half bandwidth of envelope + public double Sigma + { + get + { + return ((double)(this.GetValue(SigmaProperty))); + } + set + { + this.SetValue(SigmaProperty, value); + } + } + /// Transparency of Figure + public double Alpha + { + get + { + return ((double)(this.GetValue(AlphaProperty))); + } + set + { + this.SetValue(AlphaProperty, value); + } + } + } + #endregion } } \ No newline at end of file diff --git a/test4/PsychlopsMain.cs b/test4/PsychlopsMain.cs index 9090e56..4cfe448 100644 --- a/test4/PsychlopsMain.cs +++ b/test4/PsychlopsMain.cs @@ -257,7 +257,7 @@ namespace PsychlopsSilverlightApp img2 = new Image(isize * 2, isize * 2); img3 = new Image(isize * 2, isize * 2); - Figures.ShaderGabor[] gabor1 = StaticFunctions.NewArray(100); + var gabor1 = StaticFunctions.NewArray(100); foreach(var g in gabor1) { g.setSigma(isize / 8).centering().shift(Math.random(300) - 150, Math.random(600) - 300);