File: JuliaSet_SM3_FS.glsl

package info (click to toggle)
opentk 1.0.20101006%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 38,896 kB
  • ctags: 68,704
  • sloc: cs: 424,330; xml: 96,546; ansic: 3,597; makefile: 24
file content (41 lines) | stat: -rw-r--r-- 1,167 bytes parent folder | download
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
#version 120
// www.OpenTK.net GLSL Julia Set (c) 2008 Christoph Brandtner

uniform sampler1D COLORTABLE;
uniform float CETX;
uniform float CETY;
uniform float SCALINGX;
uniform float SCALINGY;
uniform float OFFSETX;
uniform float OFFSETY;

const int MAXIterations = 32; // *must* be > 0

void main(void)
{
  float XPos = gl_FragCoord.x / SCALINGX - OFFSETX;
  float YPos = gl_FragCoord.y / SCALINGY - OFFSETY;
  float XQuad = pow( XPos, 2.0 );
  float YQuad = pow( YPos, 2.0 );
  int TableIndex = -1;
  int LoopCount = 0;
  while ( LoopCount <= MAXIterations )
    {
      YPos = 2.0 * XPos * YPos + CETY;
      XPos = XQuad - YQuad + CETX;
      XQuad = pow( XPos, 2.0 );
      YQuad = pow( YPos, 2.0 );
      TableIndex++;
      if ( (XQuad + YQuad) > 4.0 )
      { 
         if (TableIndex == 0)
           discard;
         LoopCount = MAXIterations;
      }
      LoopCount++;
    }
  float FinalTableIndex = float( TableIndex ) / float( MAXIterations );

  gl_FragColor = texture1D( COLORTABLE, FinalTableIndex ); // lookup texture for output
  // gl_FragColor.rgb = vec3( FinalTableIndex ); // Debug: output greyscale
}