X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=dev4%2Fpsychlops%2Fextention%2Fstandard%2Fshader.cs;fp=dev4%2Fpsychlops%2Fextention%2Fstandard%2Fshader.cs;h=7d7c935b9c70c4eb083efd1715ecce07b1ad36e6;hb=6f8443d682c25aa44d9158e8728ced9dd54fa4ca;hp=8a511b65ac3312bac23a6497f141b6a712a441ef;hpb=e816f42793839d5dc3eb9cf933bbcb8e104d9fdb;p=psychlops%2Fsilverlight.git
diff --git a/dev4/psychlops/extention/standard/shader.cs b/dev4/psychlops/extention/standard/shader.cs
index 8a511b6..7d7c935 100644
--- a/dev4/psychlops/extention/standard/shader.cs
+++ b/dev4/psychlops/extention/standard/shader.cs
@@ -22,6 +22,109 @@ namespace Psychlops
public static partial class Figures
{
+ public class ShaderGrating : ShaderField
+ {
+ protected Shader.GratingProgram ps = null;
+ public ShaderGrating()
+ {
+ 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.GratingProgram();
+ initializeShader();
+ }
+ shader = ps;
+ initialized = true;
+ }
+ }
+
+ public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0;
+ public ShaderGrating setSize(double s) { set(s, s); return this; }
+ public ShaderGrating setSize(double h, double v) { set(h, v); return this; }
+
+ public void setParameters__()
+ {
+ ps.Contrast = contrast;
+ ps.WaveLength = wavelength;
+ ps.Phase = phase;
+ ps.Orientation = orientation;
+ ps.SizeH = width;
+ ps.SizeV = height;
+ ps.Update();
+ }
+
+
+ }
+
+
+ public class ShaderPlaid : ShaderField
+ {
+ protected Shader.PlaidProgram ps = null;
+ public ShaderPlaid()
+ {
+ 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.PlaidProgram();
+ initializeShader();
+ }
+ shader = ps;
+ initialized = true;
+ }
+ }
+
+ public double contrast = 0.5, wavelength = 20.0, phase = 0.0, orientation = 0.0;
+ public double contrast2 = 0.5, wavelength2 = 20.0, phase2 = 0.0, orientation2 = Math.PI / 4;
+ public ShaderPlaid setSize(double s) { set(s, s); return this; }
+ public ShaderPlaid setSize(double h, double v) { set(h, v); return this; }
+
+ public void setParameters__()
+ {
+ ps.Contrast = contrast;
+ ps.WaveLength = wavelength;
+ ps.Phase = phase;
+ ps.Orientation = orientation;
+ ps.Size = width;
+ ps.Contrast2 = contrast;
+ ps.WaveLength2 = wavelength;
+ ps.Phase2 = phase;
+ ps.Orientation2 = orientation;
+ ps.SizeH = width;
+ ps.SizeV = height;
+ ps.Update();
+ }
+
+
+ }
+
public class ShaderGabor : ShaderField
{
@@ -150,6 +253,334 @@ namespace Psychlops
{
}
+ #region GratingProgram
+ public class GratingProgram : ShaderProgram
+ {
+ public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/Grating.ps", UriKind.Relative);
+
+ public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GratingProgram), 0);
+ public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1)));
+ public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));
+ public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));
+ public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));
+ public static readonly DependencyProperty SizeHProperty = DependencyProperty.Register("SizeH", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(5)));
+ public static readonly DependencyProperty SizeVProperty = DependencyProperty.Register("SizeV", typeof(double), typeof(GratingProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(6)));
+ public GratingProgram()
+ {
+ 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(SizeHProperty);
+ this.UpdateShaderValue(SizeVProperty);
+
+ Size = 200;
+ Contrast = 1.0;
+ WaveLength = 100.0;
+ Orientation = 0.0;
+ SizeH = 32.0;
+ SizeV = 32.0;
+ }
+
+ public void Update()
+ {
+ this.UpdateShaderValue(InputProperty);
+ this.UpdateShaderValue(ContrastProperty);
+ this.UpdateShaderValue(FrequencyProperty);
+ this.UpdateShaderValue(PhaseProperty);
+ this.UpdateShaderValue(OrientationProperty);
+ this.UpdateShaderValue(SizeHProperty);
+ this.UpdateShaderValue(SizeVProperty);
+ }
+
+
+ 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);
+ }
+ }
+ /// Width of envelope
+ public double SizeH
+ {
+ get
+ {
+ return ((double)(this.GetValue(SizeHProperty)));
+ }
+ set
+ {
+ this.SetValue(SizeHProperty, value);
+ }
+ }
+ /// Height of Figure
+ public double SizeV
+ {
+ get
+ {
+ return ((double)(this.GetValue(SizeVProperty)));
+ }
+ set
+ {
+ this.SetValue(SizeVProperty, value);
+ }
+ }
+ }
+ #endregion
+
+ #region PlaidProgram
+ public class PlaidProgram : ShaderProgram
+ {
+ public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/Plaid.ps", UriKind.Relative);
+
+ public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(PlaidProgram), 0);
+ public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.5D)), PixelShaderConstantCallback(1)));
+ public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));
+ public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));
+ public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));
+ public static readonly DependencyProperty Contrast2Property = DependencyProperty.Register("Contrast2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.5D)), PixelShaderConstantCallback(5)));
+ public static readonly DependencyProperty Frequency2Property = DependencyProperty.Register("Frequency2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(6)));
+ public static readonly DependencyProperty Phase2Property = DependencyProperty.Register("Phase2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(7)));
+ public static readonly DependencyProperty Orientation2Property = DependencyProperty.Register("Orientation2", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(0.785398D)), PixelShaderConstantCallback(8)));
+ public static readonly DependencyProperty SizeHProperty = DependencyProperty.Register("SizeH", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(9)));
+ public static readonly DependencyProperty SizeVProperty = DependencyProperty.Register("SizeV", typeof(double), typeof(PlaidProgram), new PropertyMetadata(((double)(32D)), PixelShaderConstantCallback(10)));
+ public PlaidProgram()
+ {
+ 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(Contrast2Property);
+ this.UpdateShaderValue(Frequency2Property);
+ this.UpdateShaderValue(Phase2Property);
+ this.UpdateShaderValue(Orientation2Property);
+ this.UpdateShaderValue(SizeHProperty);
+ this.UpdateShaderValue(SizeVProperty);
+
+ Size = 200;
+ Contrast = 0.5;
+ WaveLength = 100.0;
+ Phase = 0.0;
+ Orientation = 0.0;
+ Contrast2 = 0.5;
+ WaveLength2 = 100.0;
+ Phase2 = 0.0;
+ Orientation2 = Math.PI/4;
+ SizeH = 32.0;
+ SizeV = 32.0;
+ }
+
+ public void Update()
+ {
+ this.UpdateShaderValue(InputProperty);
+ this.UpdateShaderValue(ContrastProperty);
+ this.UpdateShaderValue(FrequencyProperty);
+ this.UpdateShaderValue(PhaseProperty);
+ this.UpdateShaderValue(OrientationProperty);
+ this.UpdateShaderValue(Contrast2Property);
+ this.UpdateShaderValue(Frequency2Property);
+ this.UpdateShaderValue(Phase2Property);
+ this.UpdateShaderValue(Orientation2Property);
+ this.UpdateShaderValue(SizeHProperty);
+ this.UpdateShaderValue(SizeVProperty);
+ }
+
+
+ private double size__, wavelength__, wavelength2__;
+ 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);
+ double freq2 = size__ * 2.0 * Math.PI / (wavelength2__);
+ this.SetValue(Frequency2Property, 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);
+ }
+ }
+ /// Amplitude of Grating
+ public double Contrast2
+ {
+ get
+ {
+ return ((double)(this.GetValue(Contrast2Property))) * 2.0;
+ }
+ set
+ {
+ this.SetValue(Contrast2Property, value / 2.0);
+ }
+ }
+ /// Phase of Grating
+ public double WaveLength2
+ {
+ get
+ {
+ return wavelength2__;
+ }
+ set
+ {
+ wavelength2__ = value;
+ setFrequency();
+ }
+ }
+ /// Phase2 of Grating
+ public double Phase2
+ {
+ get
+ {
+ return ((double)(this.GetValue(Phase2Property)));
+ }
+ set
+ {
+ this.SetValue(Phase2Property, value);
+ }
+ }
+ /// Orientation2 of Grating
+ public double Orientation2
+ {
+ get
+ {
+ return ((double)(this.GetValue(Orientation2Property)));
+ }
+ set
+ {
+ this.SetValue(Orientation2Property, value);
+ }
+ }
+ /// Width of envelope
+ public double SizeH
+ {
+ get
+ {
+ return ((double)(this.GetValue(SizeHProperty)));
+ }
+ set
+ {
+ this.SetValue(SizeHProperty, value);
+ }
+ }
+ /// Height of Figure
+ public double SizeV
+ {
+ get
+ {
+ return ((double)(this.GetValue(SizeVProperty)));
+ }
+ set
+ {
+ this.SetValue(SizeVProperty, value);
+ }
+ }
+ }
+ #endregion
+
#region GaborProgram
public class GaborProgram : ShaderProgram
{