code: def initShaders():
      global Shaders
      Shaders = [
          ShaderProgram(None, []),
          ## increases fragment alpha as the normal turns orthogonal to the view
          ## this is useful for viewing shells that enclose a volume (such as isosurfaces)
          ShaderProgram(
              "balloon",
              [
                  VertexShader(
                      """
                  varying vec3 normal;
                  void main() {
                      // compute here for use in fragment shader
                      normal = normalize(gl_NormalMatrix * gl_Normal);
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  varying vec3 normal;
                  void main() {
                      vec4 color = gl_Color;
                      color.w = min(color.w + 2.0 * color.w * pow(normal.x*normal.x + normal.y*normal.y, 5.0), 1.0);
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
          ),
          ## colors fragments based on face normals relative to view
          ## This means that the colors will change depending on how the view is rotated
          ShaderProgram(
              "viewNormalColor",
              [
                  VertexShader(
                      """
                  varying vec3 normal;
                  void main() {
                      // compute here for use in fragment shader
                      normal = normalize(gl_NormalMatrix * gl_Normal);
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  varying vec3 normal;
                  void main() {
                      vec4 color = gl_Color;
                      color.x = (normal.x + 1.0) * 0.5;
                      color.y = (normal.y + 1.0) * 0.5;
                      color.z = (normal.z + 1.0) * 0.5;
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
          ),
          ## colors fragments based on absolute face normals.
          ShaderProgram(
              "normalColor",
              [
                  VertexShader(
                      """
                  varying vec3 normal;
                  void main() {
                      // compute here for use in fragment shader
                      normal = normalize(gl_Normal);
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  varying vec3 normal;
                  void main() {
                      vec4 color = gl_Color;
                      color.x = (normal.x + 1.0) * 0.5;
                      color.y = (normal.y + 1.0) * 0.5;
                      color.z = (normal.z + 1.0) * 0.5;
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
          ),
          ## very simple simulation of lighting.
          ## The light source position is always relative to the camera.
          ShaderProgram(
              "shaded",
              [
                  VertexShader(
                      """
                  varying vec3 normal;
                  void main() {
                      // compute here for use in fragment shader
                      normal = normalize(gl_NormalMatrix * gl_Normal);
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  varying vec3 normal;
                  void main() {
                      float p = dot(normal, normalize(vec3(1.0, -1.0, -1.0)));
                      p = p < 0. ? 0. : p * 0.8;
                      vec4 color = gl_Color;
                      color.x = color.x * (0.2 + p);
                      color.y = color.y * (0.2 + p);
                      color.z = color.z * (0.2 + p);
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
          ),
          ## colors get brighter near edges of object
          ShaderProgram(
              "edgeHilight",
              [
                  VertexShader(
                      """
                  varying vec3 normal;
                  void main() {
                      // compute here for use in fragment shader
                      normal = normalize(gl_NormalMatrix * gl_Normal);
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  varying vec3 normal;
                  void main() {
                      vec4 color = gl_Color;
                      float s = pow(normal.x*normal.x + normal.y*normal.y, 2.0);
                      color.x = color.x + s * (1.0-color.x);
                      color.y = color.y + s * (1.0-color.y);
                      color.z = color.z + s * (1.0-color.z);
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
          ),
          ## colors fragments by z-value.
          ## This is useful for coloring surface plots by height.
          ## This shader uses a uniform called "colorMap" to determine how to map the colors:
          ##    red   = pow(colorMap[0]*(z + colorMap[1]), colorMap[2])
          ##    green = pow(colorMap[3]*(z + colorMap[4]), colorMap[5])
          ##    blue  = pow(colorMap[6]*(z + colorMap[7]), colorMap[8])
          ## (set the values like this: shader['uniformMap'] = array([...])
          ShaderProgram(
              "heightColor",
              [
                  VertexShader(
                      """
                  varying vec4 pos;
                  void main() {
                      gl_FrontColor = gl_Color;
                      gl_BackColor = gl_Color;
                      pos = gl_Vertex;
                      gl_Position = ftransform();
                  }
              """
                  ),
                  FragmentShader(
                      """
                  uniform float colorMap[9];
                  varying vec4 pos;
                  //out vec4 gl_FragColor;   // only needed for later glsl versions
                  //in vec4 gl_Color;
                  void main() {
                      vec4 color = gl_Color;
                      color.x = colorMap[0] * (pos.z + colorMap[1]);
                      if (colorMap[2] != 1.0)
                          color.x = pow(color.x, colorMap[2]);
                      color.x = color.x < 0. ? 0. : (color.x > 1. ? 1. : color.x);
                      
                      color.y = colorMap[3] * (pos.z + colorMap[4]);
                      if (colorMap[5] != 1.0)
                          color.y = pow(color.y, colorMap[5]);
                      color.y = color.y < 0. ? 0. : (color.y > 1. ? 1. : color.y);
                      
                      color.z = colorMap[6] * (pos.z + colorMap[7]);
                      if (colorMap[8] != 1.0)
                          color.z = pow(color.z, colorMap[8]);
                      color.z = color.z < 0. ? 0. : (color.z > 1. ? 1. : color.z);
                      
                      color.w = 1.0;
                      gl_FragColor = color;
                  }
              """
                  ),
              ],
              uniforms={"colorMap": [1, 1, 1, 1, 0.5, 1, 1, 0, 1]},
          ),
          ShaderProgram(
              "pointSprite",
              [  ## allows specifying point size using normal.x
                  ## See:
                  ##
                  ##  http://stackoverflow.com/questions/9609423/applying-part-of-a-texture-sprite-sheet-texture-map-to-a-point-sprite-in-ios
                  ##  http://stackoverflow.com/questions/3497068/textured-points-in-opengl-es-2-0
                  ##
                  ##
                  VertexShader(
                      """
                  void main() {
                      gl_FrontColor=gl_Color;
                      gl_PointSize = gl_Normal.x;
                      gl_Position = ftransform();
                  } 
              """
                  ),
                  # FragmentShader("""
                  ##version 120
                  # uniform sampler2D texture;
                  # void main ( )
                  # {
                  # gl_FragColor = texture2D(texture, gl_PointCoord) * gl_Color;
                  # }
                  # """)
              ],
          ),
      ]
  
imports: from OpenGL.GL import *
  from OpenGL.GL import shaders
  import numpy
  import re
label_desc: Use image node_id 1 for calling a global function with example usage: initShaders() without return types