OSDN Git Service

sll
authorHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Thu, 26 May 2011 15:17:33 +0000 (00:17 +0900)
committerHOSOKAWA Kenchi <hskwk@users.sourceforge.jp>
Thu, 26 May 2011 15:17:33 +0000 (00:17 +0900)
dev4/Shader/Gabor.fx
dev4/Shader/Gabor.ps
dev4/psychlops/core/graphic/canvas.cs
test4/PsychlopsMain.cs

index 095d01f..5ec9fbf 100644 (file)
@@ -45,16 +45,15 @@ float rp(float2 uv)
 }\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 = 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
+      float _r = rp(uv)*8;\r
+      float env = exp( -(_r*_r) / (2.0) ) * alpha;\r
+\r
+      float _x = sin(orientation)*uv[0]-cos(orientation)*uv[1];\r
+      float cl = 127.0/255.0+env*contrast*127.0/255.0*cos(frequency*_x + phase);\r
+      if(_r>3.2) if(abs(cl-127.0/255.0)<0.005) cl=127.0/255.0;\r
+      float l = cl;\r
+     \r
+      float4 color = float4(l,l,l,1.0);\r
+      return color;\r
+}
\ No newline at end of file
index cdc54db..e937ad4 100644 (file)
Binary files a/dev4/Shader/Gabor.ps and b/dev4/Shader/Gabor.ps differ
index 7f0267b..e67c6ae 100644 (file)
@@ -730,6 +730,16 @@ namespace Psychlops
                {\r
                        return new System.Windows.Point(d.x, d.y);\r
                }\r
+\r
+\r
+               public Point datum { get { return this; } set { this = value; } }\r
+               public Point shift(Point p) { this = this + p; return this; }\r
+               public Point centering(Point p) { this = p; return this; }\r
+               public Point getDatum() { return this; }\r
+               public Point setDatum(Point p) { this = p; return p; }\r
+               public Point shift(double x, double y, double z = 0.0) { return shift(new Point(x, y, z)); }\r
+               public Point centering() { return centering(Main.drawable.getCenter()); }\r
+               public Point centering(double x, double y, double z = 0.0) { return centering(new Point(x, y, z)); }\r
        }\r
 \r
        partial struct Color\r
index 16acfd8..3969c0b 100644 (file)
@@ -1,5 +1,140 @@
-\r
+using Psychlops;\r
 \r
+namespace PsychlopsSilverlightApp\r
+{\r
+\r
+       public class PsychlopsMain\r
+       {\r
+\r
+\r
+               public void psychlops_main() {\r
+\r
+       Canvas display = new Canvas(768,768);\r
+\r
+       double rect_size = 100;\r
+       double rect_lum  = 0.5;\r
+       double bg_lum    = 0.5;\r
+       double size = 250.0;\r
+   double sigma;\r
+   sigma = size/6.0;\r
+   double lambda;\r
+   lambda = 6*sigma;\r
+   int envelopemode = 0;\r
+   double refresh = display.getRefreshRate();\r
+   double[] SF=new double[2];\r
+\r
+   SF[0]=4.0;\r
+   SF[1]=4.0;\r
+\r
+   double phase=0;\r
+\r
+   double[] initphase = new double[2];\r
+   double _i, _j, _x, _y, _x2, _y2, col;\r
+   double amplitude = 1.0;\r
+\r
+       Rectangle fixation1 = new Rectangle(3,9);\r
+   Rectangle fixation2 = new Rectangle(9,3);\r
+       fixation1.centering();\r
+       fixation2.centering();\r
+   Rectangle contrastrect = new Rectangle();\r
+   contrastrect.set(760,760);\r
+\r
+   Image envelope = new Image();\r
+   Psychlops.Color bglum= new Color(0.5,0.5,0.5);\r
+   Psychlops.Color masklum = new Color(0.5,0.5,0.5,0.5);\r
+\r
+       Interval rng = new Interval();\r
+\r
+\r
+       Psychlops.Widgets.Slider TF;\r
+       TF = new Psychlops.Widgets.Slider("TF", 0.25<=rng<=2.0 , 0.1);\r
+   TF.value=0.75;\r
+\r
+\r
+\r
+       Psychlops.Widgets.Slider SFs;\r
+       SFs = new Psychlops.Widgets.Slider("SF", 4.0<=rng<=16.0 ,  4.0);\r
+       SFs.value = 4.0;\r
+\r
+   Psychlops.Widgets.Slider contrast;\r
+       contrast= new Psychlops.Widgets.Slider("Contrast", 0.0<=rng<=1.0 ,  0.1);\r
+       contrast.value = 0.1;\r
+\r
+\r
+       var element =  StaticFunctions.NewArray<Figures.ShaderGabor>(2);\r
+    for (int i = 0; i < element.Length; i++){\r
+           element[i].setSigma(sigma); // set a size of patch as a halfwidth of Gaussian\r
+           element[i].orientation = Math.PI/4.0+Math.PI/2.0*(1-i);//Math.PI/2*(rand()%2);// //set orientations\r
+           initphase[i]=0;\r
+  }\r
+\r
+\r
+\r
+      envelope.set(size, size);\r
+      envelope.clear(bglum);\r
+\r
+   for(int i=0; i<size; i++){\r
+       for(int j=0; j<size; j++){\r
+           _i=i-size*0.5;\r
+           _j=j-size*0.5;\r
+           _x=_i*Math.cos(-Math.PI/4.0)+_j*Math.sin(-Math.PI/4.0);\r
+           _y=-_i*Math.sin(-Math.PI/4.0)+_j*Math.cos(-Math.PI/4.0);\r
+           col=Math.exp(-(_x*_x)/(2*Math.pow(sigma*2/6.0,2.0))-(_y*_y)/(2*Math.pow(sigma*2,2.0)));\r
+           envelope.alpha(i,j,1.0-col);\r
+\r
+           }\r
+       }\r
+\r
+\r
+       while(!Keyboard.esc.pushed()) {\r
+           if(Keyboard.spc.pushed())envelopemode++; envelopemode%=2;\r
+       Display.clear(bglum);\r
+       phase ++;\r
+       //phase = fmod(phase,60);\r
+\r
+       for(int i=0; i<2; i++) {\r
+           element[i].phase =(SF[i]/SF[0])*amplitude*\r
+Math.PI*Math.sin(Math.PI/2*i+2*Math.PI*phase*TF/refresh);\r
+           element[i].wavelength = lambda/SF[i];\r
+           element[i].contrast = contrast;\r
+       }\r
+\r
+\r
+       element[0].centering().shift(-size * 0.6, -size * 0.6);\r
+       element[0].draw();\r
+       element[1].centering().shift(size*0.6,-size*0.6);\r
+       element[1].draw();\r
+               element[1].centering().shift(-size*0.6,size*0.6);\r
+       element[1].draw();\r
+               element[0].centering().shift(size*0.6,size*0.6);\r
+       element[0].draw();\r
+\r
+\r
+               if(envelopemode>0){\r
+                   envelope.centering().shift(size*0.6,-size*0.6).draw();\r
+                   envelope.centering().shift(-size*0.6,size*0.6).draw();\r
+                   }\r
+       masklum.set(bg_lum, bg_lum, bg_lum, 1-contrast);\r
+       contrastrect.centering();\r
+       contrastrect.draw(masklum);\r
+       fixation1.centering().shift(size*2,0.0);\r
+       fixation1.draw(Color.red);\r
+       fixation2.centering().shift(size*2,0.0);\r
+       fixation2.draw(Color.red);\r
+\r
+               Display.flip();\r
+\r
+\r
+       }\r
+\r
+}\r
+\r
+\r
+\r
+       }\r
+\r
+}\r
+/*\r
 \r
 using Psychlops;\r
 //Position Bias Program\r
@@ -53,15 +188,16 @@ namespace PsychlopsSilverlightApp
                                //img3.centering().shift(0, isize * 1.5).draw();\r
 \r
 \r
-                               foreach (var g in gabor1)\r
+                               //foreach (var g in gabor1)\r
+                               for (int i = 0; i < gabor1.Length; i++)\r
                                {\r
-                                       g.wavelength = lambda;\r
-                                       g.phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
-                                       g.contrast = contrast;\r
+                                       gabor1[i].wavelength = lambda;\r
+                                       gabor1[i].phase = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
+                                       gabor1[i].contrast = contrast;\r
                                        //g.wavelength2 = lambda * 2;\r
                                        //g.phase2 = (double)frames * 2.0 * Math.PI * tfreq / 60;\r
                                        //g.contrast2 = contrast / 2;\r
-                                       g.draw();\r
+                                       gabor1[i].draw();\r
                                }\r
 \r
                                if (!Mouse.left.pressed()) frames++;\r