File: ExpandingRingsShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.14.20170103%2Bgit6-g605ff5c.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,044 kB
  • ctags: 69,483
  • sloc: ansic: 167,371; cpp: 11,232; objc: 4,708; sh: 1,875; python: 383; php: 344; makefile: 207; java: 113
file content (41 lines) | stat: -rw-r--r-- 1,368 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ExpandingRings shader
 * Draws a sequence of rings of alternating color. The center
 * of all rings is assigned in 'RingCenter' by the Matlab script,
 * width of a ring is assigned in 'RingWidth', the radius of the
 * outermost ring is assigned in 'Radius', a shift (scrolling offset)
 * is assigned in 'Shift'. See ExpandingRingsDemo.m for explanation.
 *
 *
 * Written 2007 by Mario Kleiner, licensed to you under MIT license.
 */

#version 110

uniform vec2  RingCenter;

/* Values passed from vertex shader: */
varying float RingWidth;
varying float Radius;
varying float Shift;
varying vec4  firstColor;
varying vec4  secondColor;

void main()
{
    /* Query current output texel position: */
    vec2 pos = gl_TexCoord[0].xy;

    /* Compute euclidean distance to center of our ring stim: */
    float d = distance(pos, RingCenter);

    /* If distance greater than maximum radius, discard this pixel: */
    if (d > Radius) discard;

    /* Convert distance from units of pixels into units of ringwidths, apply shift offset: */
    d = floor((d - Shift) / RingWidth);

    /* A pixel in an even-numbered ring is drawn in gl_Color, the color assigned in the */
    /* Screen('DrawTexture') command as modulateColor, whereas a pixel in an odd-numbered */
    /* ring is assigned 'secondColor': */
    gl_FragColor = mix(firstColor, secondColor, mod(d,2.0));
}