File: BasicPerlinNoiseShader.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 (45 lines) | stat: -rw-r--r-- 1,545 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
42
43
44
45
/* BasicPerlinNoiseShader.frag.txt - GLSL shader for on-the-fly generation
 * of 2D Perlin noise textures. Used by CreateProceduralNoise, 'DrawTexture'
 * and friends to generate procedural noise textures.
 *
 * This is a thin wrapper around the fast procedural perlin noise
 * generation code from https://github.com/ashima/webgl-noise
 *
 * (c) 2011-2012 Mario Kleiner. This is licensed to you under the MIT license.
 *
 */

uniform vec4  Offset;
varying vec4  baseColor;
varying float seed;
varying vec2  texSize;

/* Function prototype for the 3D simplex noise random number generator: */
float perlinNoise(vec3 P);

void main()
{
    vec3 v;

    /* Query current output texel position: */
    v.xy = gl_TexCoord[0].xy;

    /* Normalization:
     * 1. floor() position to remove texture coordinate interpolator skew.
     * 2. Divide by texture size by multiplying with reciprocal, ie., 
     *    texSize is = (1 / texture size), so multiply here is actual a divide.
     * 3. Scale up normalized 0-1 range to 0.0 - 289.0, the period size of the
     *    noise function.
     */
    v.xy = floor(v.xy) * vec2(289.0) * texSize.xy;

    /* Assign random seed value as 3rd component of v: */
    v.z = seed;

    /* Compute random value rval, using the Perlin noise subroutines: */
    float rval = perlinNoise(v);

    /* Multiply/Modulate base color and alpha with calculated rval random number,   */
    /* add some constant color/alpha Offset, assign as final fragment output color: */
    gl_FragColor = (baseColor * rval) + Offset;
}