File: BasicGaborShader.frag.txt

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (44 lines) | stat: -rw-r--r-- 1,589 bytes parent folder | download | duplicates (5)
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
42
43
44
/*
 * File: BasicGaborShader.frag.txt
 * Shader for drawing of basic parameterized gabor patches.
 *
 * This is the fragment shader. It gets the per-patch-constant
 * parameters as varyings from the vertex shader and hardware
 * interpolators, then performs per fragment calculations to
 * compute and write the final pixel color.
 *
 * (c) 2007-2016 by Mario Kleiner, licensed under MIT license.
 *
 */

uniform vec4 Offset;
uniform vec2 validModulationRange;

varying float Angle;
varying vec4  baseColor;
varying float Phase;
varying float FreqTwoPi;
varying float Expmultiplier;

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

    /* Compute (x,y) distance weighting coefficients, based on rotation angle: */
    /* Note that this is a constant for all fragments, but we can not do it in */
    /* the vertex shader, because the vertex shader does not have sufficient   */
    /* numeric precision on some common hardware out there. */
    vec2 coeff = vec2(cos(Angle), sin(Angle)) * FreqTwoPi;

    /* Evaluate sine grating at requested position, angle and phase: */
    float sv = sin(dot(coeff, pos) + Phase);

    /* Compute exponential hull for the gabor: */
    float ev = exp(dot(pos, pos) * Expmultiplier);

    /* Multiply/Modulate base color and alpha with calculated sine/gauss      */
    /* values, add some constant color/alpha Offset, assign as final fragment */
    /* output color: */
    gl_FragColor = (baseColor * clamp(ev * sv, validModulationRange[0], validModulationRange[1])) + Offset;
}