--- /dev/null
+/// <summary>Amplitude of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float contrast : register(C1);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>100</maxValue>\r
+/// <defaultValue>100</defaultValue>\r
+float frequency: register(C2);\r
+\r
+/// <summary>Phase of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float phase: register(C3);\r
+\r
+/// <summary>Orientation of Grating</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>6.283184</maxValue>\r
+/// <defaultValue>0</defaultValue>\r
+float orientation: register(C4);\r
+\r
+/// <summary>Half bandwidth of envelope</summary>\r
+/// <minValue>2</minValue>\r
+/// <maxValue>8</maxValue>\r
+/// <defaultValue>4</defaultValue>\r
+float sigma : register(C5);\r
+\r
+/// <summary>Transparency of Figure</summary>\r
+/// <minValue>0</minValue>\r
+/// <maxValue>1</maxValue>\r
+/// <defaultValue>1</defaultValue>\r
+float alpha : register(C6);\r
+\r
+\r
+float rp(float2 uv)\r
+{\r
+ const float2 Center = float2(0.5,0.5);\r
+ float2 dir = uv - Center; // vector from center to pixel\r
+ float dist = length(dir);\r
+ //dir /= dist;\r
+ return dist;\r
+}\r
+\r
+float4 main(float2 uv : TEXCOORD) : COLOR\r
+//float4 main(float2 uv : VPOS ) : COLOR\r
+{\r
+ //float _r = rp(uv)*sigma*4.0;\r
+ //float env = exp( -(_r*_r) / 2.0 ) * alpha;\r
+ float _r = rp(uv)*8;\r
+ float env = 1.0;//exp( -(_r*_r) / (2.0) ) * alpha;\r
+\r
+ float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+ float l = 0.5+env*contrast*0.5*cos(frequency*_x + phase);\r
+ \r
+ float4 color = float4(l,l,l,1.0);\r
+ return color;\r
+}\r
\r
\r
}\r
+\r
+\r
+ public class ShaderGaborAlpha : ShaderField\r
+ {\r
+ protected Shader.GaborAlphaProgram ps = null;\r
+ public ShaderGaborAlpha()\r
+ {\r
+ initialize__ = initialize___;\r
+ setParameters = setParameters__;\r
+ }\r
+ internal void initialize()\r
+ {\r
+ if (!initialized)\r
+ {\r
+ Main.canvas.beginInvoke(initialize___);\r
+ initialized = true;\r
+ }\r
+ }\r
+ internal void initialize___()\r
+ {\r
+ if (!initialized)\r
+ {\r
+ if (ps == null)\r
+ {\r
+ ps = new Shader.GaborAlphaProgram();\r
+ initializeShader();\r
+ }\r
+ shader = ps;\r
+ initialized = true;\r
+ }\r
+ }\r
+\r
+ //public double contrast { get; set; }\r
+ //public double frequency { get; set; }\r
+ //public double phase { get; set; }\r
+ //public double orientation { get; set; }\r
+ public double contrast = 1.0, wavelength = 20.0, phase = 0.0, orientation = 0.0, alpha = 1.0;\r
+ public ShaderGaborAlpha setSigma(double s)\r
+ {\r
+ set(s * 8, s * 8);\r
+ return this;\r
+ }\r
+\r
+ public void setParameters__()\r
+ {\r
+ ps.Contrast = contrast;\r
+ ps.WaveLength = wavelength;\r
+ ps.Phase = phase;\r
+ ps.Orientation = orientation;\r
+ ps.Sigma = 4.0;\r
+ ps.Size = width;\r
+ ps.Alpha = alpha;\r
+ ps.Update();\r
+ }\r
+\r
+\r
+ }\r
}\r
\r
\r
{\r
}\r
\r
+ #region GaborProgram\r
public class GaborProgram : ShaderProgram\r
{\r
public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/Gabor.ps", UriKind.Relative);\r
}\r
}\r
}\r
+ #endregion\r
+\r
+ #region GaborAlphaProgram\r
+ public class GaborAlphaProgram : ShaderProgram\r
+ {\r
+ public static readonly Uri ps = new Uri(@"/PsychlopsSilverlight4;component/Shader/GaborAlpha.ps", UriKind.Relative);\r
+\r
+ public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(GaborAlphaProgram), 0);\r
+ public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(1)));\r
+ public static readonly DependencyProperty FrequencyProperty = DependencyProperty.Register("Frequency", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(100D)), PixelShaderConstantCallback(2)));\r
+ public static readonly DependencyProperty PhaseProperty = DependencyProperty.Register("Phase", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(3)));\r
+ public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register("Orientation", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(0D)), PixelShaderConstantCallback(4)));\r
+ public static readonly DependencyProperty SigmaProperty = DependencyProperty.Register("Sigma", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(4D)), PixelShaderConstantCallback(5)));\r
+ public static readonly DependencyProperty AlphaProperty = DependencyProperty.Register("Alpha", typeof(double), typeof(GaborAlphaProgram), new PropertyMetadata(((double)(1D)), PixelShaderConstantCallback(6)));\r
+ public GaborAlphaProgram()\r
+ {\r
+ PixelShader pixelShader = new PixelShader();\r
+ pixelShader.UriSource = ps;\r
+ this.PixelShader = pixelShader;\r
+\r
+ this.UpdateShaderValue(InputProperty);\r
+ this.UpdateShaderValue(ContrastProperty);\r
+ this.UpdateShaderValue(FrequencyProperty);\r
+ this.UpdateShaderValue(PhaseProperty);\r
+ this.UpdateShaderValue(OrientationProperty);\r
+ this.UpdateShaderValue(SigmaProperty);\r
+ this.UpdateShaderValue(AlphaProperty);\r
+\r
+ Size = 200;\r
+ Contrast = 1.0;\r
+ WaveLength = 100.0;\r
+ Orientation = 0.0;\r
+ Sigma = 4.0;\r
+ Alpha = 1.0;\r
+ }\r
+\r
+ public void Update()\r
+ {\r
+ this.UpdateShaderValue(InputProperty);\r
+ this.UpdateShaderValue(ContrastProperty);\r
+ this.UpdateShaderValue(FrequencyProperty);\r
+ this.UpdateShaderValue(PhaseProperty);\r
+ this.UpdateShaderValue(OrientationProperty);\r
+ this.UpdateShaderValue(SigmaProperty);\r
+ this.UpdateShaderValue(AlphaProperty);\r
+ }\r
+\r
\r
+ private double size__, wavelength__;\r
+ public double Size { get { return size__; } set { size__ = value; setFrequency(); } }\r
+ private void setFrequency()\r
+ {\r
+ double freq = size__ * 2.0 * Math.PI / (wavelength__);\r
+ this.SetValue(FrequencyProperty, freq);\r
+ }\r
+\r
+ /// <summary>Amplitude of Grating</summary>\r
+ public double Contrast\r
+ {\r
+ get\r
+ {\r
+ return ((double)(this.GetValue(ContrastProperty))) * 2.0;\r
+ }\r
+ set\r
+ {\r
+ this.SetValue(ContrastProperty, value / 2.0);\r
+ }\r
+ }\r
+ /// <summary>Phase of Grating</summary>\r
+ public double WaveLength\r
+ {\r
+ get\r
+ {\r
+ return wavelength__;\r
+ }\r
+ set\r
+ {\r
+ wavelength__ = value;\r
+ setFrequency();\r
+ }\r
+ }\r
+ /// <summary>Phase of Grating</summary>\r
+ public double Phase\r
+ {\r
+ get\r
+ {\r
+ return ((double)(this.GetValue(PhaseProperty)));\r
+ }\r
+ set\r
+ {\r
+ this.SetValue(PhaseProperty, value);\r
+ }\r
+ }\r
+ /// <summary>Orientation of Grating</summary>\r
+ public double Orientation\r
+ {\r
+ get\r
+ {\r
+ return ((double)(this.GetValue(OrientationProperty)));\r
+ }\r
+ set\r
+ {\r
+ this.SetValue(OrientationProperty, value);\r
+ }\r
+ }\r
+ /// <summary>Half bandwidth of envelope</summary>\r
+ public double Sigma\r
+ {\r
+ get\r
+ {\r
+ return ((double)(this.GetValue(SigmaProperty)));\r
+ }\r
+ set\r
+ {\r
+ this.SetValue(SigmaProperty, value);\r
+ }\r
+ }\r
+ /// <summary>Transparency of Figure</summary>\r
+ public double Alpha\r
+ {\r
+ get\r
+ {\r
+ return ((double)(this.GetValue(AlphaProperty)));\r
+ }\r
+ set\r
+ {\r
+ this.SetValue(AlphaProperty, value);\r
+ }\r
+ }\r
+ }\r
+ #endregion\r
\r
}\r
}
\ No newline at end of file