Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1452 | chris | 1 | #version 110 |
| 2 | // www.OpenTK.net GLSL Julia Set (c) 2008 Christoph Brandtner |
||
| 3 | |||
| 4 | // uniforms from OpenGL |
||
| 5 | uniform sampler1D COLORTABLE; |
||
| 6 | uniform float CETX; |
||
| 7 | uniform float CETY; |
||
| 8 | uniform float SCALINGX; |
||
| 9 | uniform float SCALINGY; |
||
| 10 | uniform float OFFSETX; |
||
| 11 | uniform float OFFSETY; |
||
| 12 | |||
| 13 | // GLSL internal variables. |
||
| 14 | const int MAXIterations = 16; // must be greater than zero, 16 is a good blend between detail and speed |
||
| 15 | float XPos; |
||
| 16 | float YPos; |
||
| 17 | float XQuad; |
||
| 18 | float YQuad; // half precision floating point could be used on those 4 floats for speed, but will throw a warning. |
||
| 19 | int TableIndex; |
||
| 20 | int LoopCount; |
||
| 21 | |||
| 22 | // this function reduces duplicate code |
||
| 23 | void Iterate(void) |
||
| 24 | { |
||
| 25 | YPos = 2.0 * XPos * YPos + CETY; |
||
| 26 | XPos = XQuad - YQuad + CETX; |
||
| 27 | XQuad = pow(XPos, 2.0); |
||
| 28 | YQuad = pow(YPos, 2.0); |
||
| 29 | TableIndex++; |
||
| 30 | if ( (XQuad + YQuad) > 4.0 ) LoopCount = MAXIterations; // skip further iterations for this Pixel |
||
| 31 | LoopCount++; |
||
| 32 | } |
||
| 33 | |||
| 34 | // Shader entry point, this is executed per Pixel |
||
| 35 | void main(void) |
||
| 36 | { |
||
| 37 | XPos = gl_FragCoord.x / SCALINGX - OFFSETX; |
||
| 38 | YPos = gl_FragCoord.y / SCALINGY - OFFSETY; |
||
| 39 | XQuad = pow(XPos, 2.0); |
||
| 40 | YQuad = pow(YPos, 2.0); |
||
| 41 | TableIndex = -1; |
||
| 42 | LoopCount = 0; |
||
| 43 | // the loop is unrolled for SM 2.0 compatibility |
||
| 44 | if ( LoopCount <= MAXIterations ) Iterate(); // TableIndex==0 |
||
| 45 | if ( LoopCount > 1 ) discard; // attempt to early-out, will affect ~1/3 of all Pixels |
||
| 46 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 47 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 48 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 49 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 50 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 51 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 52 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 53 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 54 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 55 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 56 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 57 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 58 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 59 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 60 | if ( LoopCount <= MAXIterations ) Iterate(); |
||
| 61 | if ( LoopCount <= MAXIterations ) Iterate(); // TableIndex==16 |
||
| 62 | float FinalTableIndex = float( TableIndex ) / float( MAXIterations ); |
||
| 63 | |||
| 64 | gl_FragColor = texture1D( COLORTABLE, FinalTableIndex ); // lookup texture for output |
||
| 65 | // gl_FragColor.rgb = vec3(FinalTableIndex); // Debug: output greyscale |
||
| 66 | } |