Add a SwaggerExport to generate schema for swagger.json

package jsonStream.swaggerExporter;

import haxe.macro.Context;
import haxe.macro.Type;

using Lambda;

class SwaggerExporter {

  #if macro
  static function toItemJson(type:Type):Dynamic return {
    switch type {
      case TAbstract(_.get() => { module: "StdTypes", name: "Int" }, []):
        {
          type: "integer"
        }
      case TAbstract(_.get() => { module: "StdTypes", name: "Float" }, []):
        {
          type: "number"
        }
      case TAbstract(_.get() => { module: "StdTypes", name: "Bool" }, []):
        {
          type: "boolean"
        }
      case TInst(_.get() => { module: "String", name: "String" }, []):
        {
          type: "string"
        }
      case TAbstract(_.get() => { module: "haxe.ds.Vector", name: "Vector" }, [ elementType ]):
        {
          type: "array",
          items: toItemJson(elementType)
        }
      case TInst(_.get() => { module: module, name: name, meta: classMeta }, _) if (classMeta.has(":final")):
        var ref = {};
        Reflect.setField(ref, "$ref", '#$module/$name');
        ref;
      default:
        Context.error('Unsupported type: $type', Context.currentPos());
    }
  }
  #end

  macro public static function export(exportingModules:Array<String>, swaggerFileName:String):Void {
    var definitionJsonContent:Dynamic = {};
    for (moduleName in exportingModules) {
      var moduleJson:Dynamic = {};
      var types = haxe.macro.Context.getModule(moduleName);
      for (type in types) {
        switch type {
          case haxe.macro.Type.TInst(t, args):
            var classType = t.get();
            if (exportingModules.has(classType.module)) {
              var properties:Dynamic = {};
              for (field in classType.fields.get()) {
                var jsonFieldName = switch field.meta.extract(":jsonFieldName") {
                  case []:
                    field.name;
                  case [ { params: [ { expr: EConst(CString(jsonFieldName))} ] } ]:
                    jsonFieldName;
                  case metas:
                    Context.error('Expect one string parameter for @:jsonFieldName', metas[0].pos);

                }
                var item = toItemJson(field.type);
                Reflect.setField(properties, jsonFieldName, toItemJson(field.type));
              }
              var schemaJson = {
                type: "object",
                properties: properties
              }
              if (classType.doc != null) {
                Reflect.setField(schemaJson, "description", classType.doc);
              }
              Reflect.setField(moduleJson, classType.name, schemaJson);
            }
          default:
            Context.error('Unsupported type: $type', Context.currentPos());
        }
        Reflect.setField(definitionJsonContent, moduleName, moduleJson);
      }
    }
    // Write the types to swagger JSON file.
    sys.io.File.saveContent(swaggerFileName, haxe.format.JsonPrinter.print(definitionJsonContent, null, "\t"));
  }

}


package unreal.slatecore;

#if proletariat
/**
  Used to specify case conversion styles on TextBlocks
**/
@:umodule("SlateCore")
@:glueCppIncludes("Public/Styling/SlateTypes.h")
@:uname("ETextConvertCaseMode")
@:class @:uextern @:uenum extern enum ETextConvertCaseMode {

  /**
    Default
  **/
  Default;

  /**
    Convert all characters to lowercase
  **/
  Lowercase;

  /**
    Convert all characters to uppercase
  **/
  Uppercase;

}
#end


package unreal.umg;

import unreal.slatecore.*;

extern class FSlateChildSize_Extra {
	@:uname('.ctor') public static function create() : FSlateChildSize;
}


package passport;

import express.Middleware;

@:jsRequire("passport")
extern class Passport {
  @:selfCall function new() : Void;

  public function use(?name : String, strategy : Dynamic) : Passport;
  public function unuse(name : String) : Passport;
  // only for use outside of an Express context
  // public function framework(fw : Dynamic) : Passport
  public function initialize(?options : Dynamic) : Middleware;
  public function authenticate(strategy : String, ?options : Dynamic, callback : Dynamic) : Middleware;
  public function authorize(strategy : String, ?options : Dynamic, callback: Dynamic) : Middleware;
  public function session(?options : Dynamic) : Middleware;
  public function serializeUser(callback : Dynamic) : Void;
  public function deserializeUser(callback : Dynamic) : Void;
  public function transformAuthInfo(callback: Dynamic) : Void;
}


uniform sampler2D u_opaque;
uniform sampler2D u_accumulation;
uniform sampler2D u_revealage;

varying vec2 v_textureCoordinates;

void main()
{
    vec4 opaque = texture2D(u_opaque, v_textureCoordinates);
    vec4 accum = texture2D(u_accumulation, v_textureCoordinates);
    float r = texture2D(u_revealage, v_textureCoordinates).r;

#ifdef MRT
    vec4 transparent = vec4(accum.rgb / clamp(r, 1e-4, 5e4), accum.a);
#else
    vec4 transparent = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);
#endif

    transparent.a = 1.0 - transparent.a;

    // 0.0 if the transparent color is the clear color, 1.0 if the transparent color should be blended with the opaque color.
    float t = ceil(clamp(abs(transparent.r + transparent.g + transparent.b + transparent.a - 1.0), 0.0, 1.0));
    vec4 blended = transparent.a * transparent + (1.0 - transparent.a) * opaque;
    gl_FragColor = mix(opaque, blended, t);
}

Simplify compositing shader now that sun/sky/stars are drawn to opaque framebuffer.

uniform sampler2D u_opaque;
uniform sampler2D u_accumulation;
uniform sampler2D u_revealage;

varying vec2 v_textureCoordinates;

void main()
{
    vec4 opaque = texture2D(u_opaque, v_textureCoordinates);
    vec4 accum = texture2D(u_accumulation, v_textureCoordinates);
    float r = texture2D(u_revealage, v_textureCoordinates).r;

#ifdef MRT
    vec4 transparent = vec4(accum.rgb / clamp(r, 1e-4, 5e4), accum.a);
#else
    vec4 transparent = vec4(accum.rgb / clamp(accum.a, 1e-4, 5e4), r);
#endif

    transparent.a = 1.0 - transparent.a;
    gl_FragColor = transparent.a * transparent + (1.0 - transparent.a) * opaque;
}


//Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
vec3 tonemapFilmic(vec3 color) {
    vec3 x = max(vec3(0.0), color - 0.004);
    return (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
}

#pragma glslify: export(tonemapFilmic)

Add gamma to filmic tonemapping

//Based on Filmic Tonemapping Operators http://filmicgames.com/archives/75
vec3 tonemapFilmic(vec3 color) {
    vec3 x = max(vec3(0.0), color - 0.004);
    vec3 result = (x * (6.2 * x + 0.5)) / (x * (6.2 * x + 1.7) + 0.06);
    return pow(result, vec3(2.2));
}

#pragma glslify: export(tonemapFilmic)


/*

ALCHEMY AO

Projects random points to screen space, and uses the average unoccluded vector
to approximate AO.

*/

const int num_samples = GET_SETTING(AO, alchemy_num_samples);
float max_dist = GET_SETTING(AO, alchemy_max_distance) ;
float accum = 0.0;
float accum_count = 0;

for (int i = 0; i < num_samples; ++i) {

    // Get random texcoord offset
    vec2 offset = poisson_disk_2D_32[i] + noise_vec.xy * 0.2;
    vec2 offcoord = texcoord + offset * pixel_size * sample_radius * kernel_scale;

    // Get view position at that offset
    vec3 off_pos = get_view_pos_at(offcoord);

    // Get the vector s-p to that sample position
    vec3 sample_vec = normalize(off_pos - pixel_view_pos);

    // Check if the distance matches, discard matches which are too far away
    if (distance(off_pos, pixel_view_pos) < max_dist) {

        // Weight sample by the angle
        accum += max(0, dot(pixel_normal, sample_vec));
    }

}

// Normalize values
accum /= num_samples;
result = vec4(1 - saturate(accum));

Add missing divide to the alchemy AO

/*

ALCHEMY AO

Projects random points to screen space, and uses the average unoccluded vector
to approximate AO.

*/

const int num_samples = GET_SETTING(AO, alchemy_num_samples);
float max_dist = GET_SETTING(AO, alchemy_max_distance) ;
float accum = 0.0;
float accum_count = 0;

for (int i = 0; i < num_samples; ++i) {

    // Get random texcoord offset
    vec2 offset = poisson_disk_2D_32[i] + noise_vec.xy * 0.2;
    vec2 offcoord = texcoord + offset * pixel_size * sample_radius * kernel_scale;

    // Get view position at that offset
    vec3 off_pos = get_view_pos_at(offcoord);

    // Get the vector s-p to that sample position
    vec3 sample_vec = normalize(off_pos - pixel_view_pos);

    // Check if the distance matches, discard matches which are too far away
    float dist = distance(off_pos, pixel_view_pos) / max_dist;
    if (dist < 1.0) {

        // Weight sample by the angle
        accum += max(0, dot(pixel_normal, sample_vec)) / dist;
    }

}

// Normalize values
accum /= num_samples;
accum *= 0.5;
result = vec4(1 - saturate(accum));


#version 440

layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec4 color;
layout(location = 3) in vec2 texCoord;
layout(location = 4) in int drawId;

uniform mat4 viewProjectionMatrix;
uniform mat4 viewMatrix;

out vec4 outColor;
out vec3 outNormal;
out vec4 outPosition;
out vec4 outEyePosition;
out vec2 outTextureCoordinate;
out int outDrawId;
out vec3 cameraDirection;

#include "vertexHelper.hglsl"

void main()
{
  mat4 modelMatrix = getModelMatrix(drawId);

  outColor = color;
  outPosition = viewProjectionMatrix * modelMatrix * vec4(pos, 1.0f);
  outEyePosition = viewMatrix * modelMatrix * vec4(pos, 1.0f);
  gl_Position = outPosition;
  outNormal = normalize(mul(viewMatrix * modelMatrix, normal).xyz);
  outTextureCoordinate = texCoord;
  outDrawId = drawId;
  cameraDirection = vec3(viewMatrix[2][0], viewMatrix[2][1], viewMatrix[2][2]);
}

Fix normal transformation by calculating the normal matrix.

#version 440

layout(location = 0) in vec3 pos;
layout(location = 1) in vec3 normal;
layout(location = 2) in vec4 color;
layout(location = 3) in vec2 texCoord;
layout(location = 4) in int drawId;

uniform mat4 viewProjectionMatrix;
uniform mat4 viewMatrix;

out vec4 outColor;
out vec3 outNormal;
out vec4 outPosition;
out vec4 outEyePosition;
out vec2 outTextureCoordinate;
out int outDrawId;
out vec3 cameraDirection;

#include "vertexHelper.hglsl"

void main()
{
  mat4 modelMatrix = getModelMatrix(drawId);

  outColor = color;
  outPosition = viewProjectionMatrix * modelMatrix * vec4(pos, 1.0f);
  outEyePosition = viewMatrix * modelMatrix * vec4(pos, 1.0f);
  gl_Position = outPosition;
  outNormal =
      normalize(mul(transpose(inverse(viewMatrix * modelMatrix)), normal).xyz);
  outTextureCoordinate = texCoord;
  outDrawId = drawId;
  cameraDirection = vec3(viewMatrix[2][0], viewMatrix[2][1], viewMatrix[2][2]);
}


uniform vec3 diffuse;
uniform float opacity;

#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>

void main() {

	vec3 outgoingLight = vec3( 0.0 );
	vec4 diffuseColor = vec4( diffuse, opacity );

	#include <clipping_planes_fragment>
	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <alphatest_fragment>

	outgoingLight = diffuseColor.rgb;

	gl_FragColor = vec4( outgoingLight, diffuseColor.a );

	#include <fog_fragment>

}

Add tonemapping and encoding support

uniform vec3 diffuse;
uniform float opacity;

#include <common>
#include <packing>
#include <uv_pars_fragment>
#include <map_pars_fragment>
#include <fog_pars_fragment>
#include <logdepthbuf_pars_fragment>
#include <clipping_planes_pars_fragment>

void main() {

	#include <clipping_planes_fragment>

	vec3 outgoingLight = vec3( 0.0 );
	vec4 diffuseColor = vec4( diffuse, opacity );

	#include <logdepthbuf_fragment>
	#include <map_fragment>
	#include <alphatest_fragment>

	outgoingLight = diffuseColor.rgb;

	gl_FragColor = vec4( outgoingLight, diffuseColor.a );

	#include <tonemapping_fragment>
	#include <encodings_fragment>
	#include <fog_fragment>

}


/* #include "perspective.glsl" */

uniform float noise_amplitude;
uniform vec2 noise_freq;

varying float scaled_noise_amplitude;

void main() {
  vec4 proj;
  vec2 texc;

  proj = perspective_proj(gl_Vertex);
  gl_Position = gl_ModelViewProjectionMatrix * proj;
  texc = gl_Vertex.xy / METRE / 4.0f;
  texc *= noise_freq;
  gl_TexCoord[0] = vec4(texc.s, texc.t, 0.0f, 1.0f);
  scaled_noise_amplitude = min(1.0f, noise_amplitude -
                               noise_amplitude * abs(proj.z) / METRE / 256.0f);
}

Include z coordinate in manifold texture coordinates.

/* #include "perspective.glsl" */

uniform float noise_amplitude;
uniform vec2 noise_freq;

varying float scaled_noise_amplitude;

void main() {
  vec4 proj;
  vec2 texc;

  proj = perspective_proj(gl_Vertex);
  gl_Position = gl_ModelViewProjectionMatrix * proj;
  texc = gl_Vertex.xy / METRE / 4.0f;
  texc.s += gl_Vertex.z / METRE / 4.0f;
  texc *= noise_freq;
  gl_TexCoord[0] = vec4(texc.s, texc.t, 0.0f, 1.0f);
  scaled_noise_amplitude = min(1.0f, noise_amplitude -
                               noise_amplitude * abs(proj.z) / METRE / 256.0f);
}


/**
 * Calculates the intensity of light on a surface.
 *
 * @method applyLight
 * @private
 *
 */
vec3 applyLight(in vec3 material) {
    int numLights = int(u_NumLights);
    vec3 ambientColor = u_AmbientLight * material;
    vec3 normal = normalize(v_Normal);
    vec3 eyeVector = normalize(v_EyeVector);
    vec3 specular = vec3(0.0);
    vec3 diffuse = vec3(0.0);

    for(int i = 0; i < 4; i++) {
        if (i >= numLights) break;
        vec3 lightDirection = normalize(u_LightPosition[i].xyz - v_Position);
        float lambertian = max(dot(lightDirection, normal), 0.0);

        if (lambertian > 0.0) {
            diffuse += u_LightColor[i].rgb * material * lambertian;
            if (glossiness > 0.0) {
                vec3 halfVector = normalize(lightDirection + eyeVector);
                float specular = pow(max(dot(halfVector, normal), 0.0), glossiness);
                diffuse += u_LightColor[i].rgb * specular * lambertian;
            }
        }

    }

    return ambientColor + diffuse;
}

#pragma glslify: export(applyLight)

Add ability to change the strength and color of glossiness

/**
 * Calculates the intensity of light on a surface.
 *
 * @method applyLight
 * @private
 *
 */
vec3 applyLight(in vec3 material) {
    int numLights = int(u_NumLights);
    vec3 ambientColor = u_AmbientLight * material;
    vec3 normal = normalize(v_Normal);
    vec3 eyeVector = normalize(v_EyeVector);
    vec3 diffuse = vec3(0.0);
    bool hasGlossiness = glossiness.a > 0.0;
    bool hasSpecularColor = length(glossiness.rgb) > 0.0;

    for(int i = 0; i < 4; i++) {
        if (i >= numLights) break;
        vec3 lightDirection = normalize(u_LightPosition[i].xyz - v_Position);
        float lambertian = max(dot(lightDirection, normal), 0.0);

        if (lambertian > 0.0) {
            diffuse += u_LightColor[i].rgb * material * lambertian;
            if (hasGlossiness) {
                vec3 halfVector = normalize(lightDirection + eyeVector);
                float specularWeight = pow(max(dot(halfVector, normal), 0.0), glossiness.a);
                vec3 specularColor = hasSpecularColor ? glossiness.rgb : u_LightColor[i].rgb;
                diffuse += specularColor * specularWeight * lambertian;
            }
        }

    }

    return ambientColor + diffuse;
}

#pragma glslify: export(applyLight)


#version 410

uniform sampler2D diffuse_texture;
uniform int has_textures;

in VS_OUT {
	vec2 texcoord;
} fs_in;

out vec4 frag_color;

void main()
{
	if (has_textures != 0)
		frag_color = texture(diffuse_texture, fs_in.texcoord);
	else
		frag_color = vec4(1.0);
}

Use correct presence flag for diffuse_texture

#version 410

uniform sampler2D diffuse_texture;
uniform int has_diffuse_texture;

in VS_OUT {
	vec2 texcoord;
} fs_in;

out vec4 frag_color;

void main()
{
	if (has_diffuse_texture != 0)
		frag_color = texture(diffuse_texture, fs_in.texcoord);
	else
		frag_color = vec4(1.0);
}


#version 150

/* Cel shading fragment program for single-pass rendering */
uniform vec4 diffuse;
uniform vec4 specular;
uniform sampler1D diffuseRamp;
uniform sampler1D specularRamp;
uniform sampler1D edgeRamp;

in float diffuseIn;
in float specularIn;
in float edge;

out vec4 fragColour;

uniform lighting
{
	vec4 diffuse;
	vec4 specular;
} LightingParams;

void main()
{
	// Step functions from textures
	float diffuseStep = texture(diffuseRamp, diffuseIn).x;
	float specularStep = texture(specularRamp, specularIn).x;
	float edgeStep = texture(edgeRamp, edge).x;

//	fragColour = edgeStep * ((diffuse * diffuseStep) +
//                            (specular * specularStep));
	fragColour = edgeStep * ((LightingParams.diffuse * diffuseStep) +
                        (LightingParams.specular * specularStep));
}

Fix the Cel shading demo shader

#version 150

/* Cel shading fragment program for single-pass rendering */
uniform vec4 diffuse;
uniform vec4 specular;
uniform sampler1D diffuseRamp;
uniform sampler1D specularRamp;
uniform sampler1D edgeRamp;

in float diffuseIn;
in float specularIn;
in float edge;

out vec4 fragColour;

/*uniform lighting
{
	vec4 diffuse;
	vec4 specular;
} LightingParams;*/

void main()
{
	// Step functions from textures
	float diffuseStep = texture(diffuseRamp, diffuseIn).x;
	float specularStep = texture(specularRamp, specularIn).x;
	float edgeStep = texture(edgeRamp, edge).x;

	fragColour = edgeStep * ((diffuse * diffuseStep) +
                            (specular * specularStep));
//	fragColour = edgeStep * ((LightingParams.diffuse * diffuseStep) +
//                        (LightingParams.specular * specularStep));
}


a = 50;
lt = a; // this needs to be bigger than the stuff below, so let's just use "a"
Point(1) = {-a,-a,-a, lt};
Point(2) = {-a,a,-a, lt};
Point(3) = {a, a,-a, lt};
Point(4) = {a,-a,-a, lt};
Line(1) = {1,4};
Line(2) = {4,3};
Line(3) = {3,2};
Line(4) = {2,1};
Line Loop(5) = {2,3,4,1};
Plane Surface(6) = {5};
Physical Surface(1) = {6};

Field[1] = MathEval;
// This is generated using the formula a/5-(a/5-a/50)*(Cos(3.14*x/a)+..)/2
Field[1].F = "10-(10-1)*(Cos(3.14*x/50)+Cos(3.14*y/50))/2";

Background Field = 1;


uniform sampler2D texture1;
uniform sampler2D texture2;
varying vec2 vUv1;
varying vec2 vUv2;

void main() {
  vec4 baseColor = texture2D(texture1, vUv1);
  #ifdef ALPHATEST
  if ( baseColor.a < ALPHATEST ) discard;
  #endif
  gl_FragColor = baseColor * texture2D(texture2, vUv2) * 2.0;
}

Set static object lightmap multiplication to 2.4.

uniform sampler2D texture1;
uniform sampler2D texture2;
varying vec2 vUv1;
varying vec2 vUv2;

void main() {
  vec4 baseColor = texture2D(texture1, vUv1);
  #ifdef ALPHATEST
  if ( baseColor.a < ALPHATEST ) discard;
  #endif
  gl_FragColor = baseColor * texture2D(texture2, vUv2) * 2.4;
}


#ifdef GL_ES
    precision mediump float;
#endif

uniform sampler2D sDiffuse;

varying vec2 vTexCoord;
varying vec4 vColor;

void main(void)
{
	#ifdef PLATFORM_ANDROID
		float alpha = texture2D(sDiffuse, vTexCoord).a;
	#else
		float alpha = texture2D(sDiffuse, vTexCoord).r;
	#endif
	gl_FragColor = vec4(vColor.xyz, alpha);
}

Include vertex alpha for glyph shader - fixes a few reftests

#version 110

#ifdef GL_ES
    precision mediump float;
#endif

uniform sampler2D sDiffuse;

varying vec2 vTexCoord;
varying vec4 vColor;

void main(void)
{
	#ifdef PLATFORM_ANDROID
		float alpha = texture2D(sDiffuse, vTexCoord).a;
	#else
		float alpha = texture2D(sDiffuse, vTexCoord).r;
	#endif
	gl_FragColor = vec4(vColor.xyz, alpha * vColor.w);
}


precision highp float;
in vec2 vfPosition;
in vec2 vfCoord;
uniform sampler2D s0;

void main()
{
	vec4 src = texture2D(s0, vfCoord);
	float result = src.w;
	gl_FragColor = vec4(result);
}

Fix wrong keyword; Must be 'varying' in ES 2.0.

precision highp float;
varying vec2 vfPosition;
varying vec2 vfCoord;
uniform sampler2D s0;

void main()
{
	vec4 src = texture2D(s0, vfCoord);
	float result = src.w;
	gl_FragColor = vec4(result);
}


precision highp float;

// a.xy = resolution
// a.z = time
// a.w = fade
uniform vec4 a;

// b.x = 1
// b.y = kick drum volume
// b.z = t>>18
uniform vec4 b;

void main() {
  // ray marcher temp result
	vec3 e = b.xxx,
  cu = -e + sin(a.z + b.z),

  // ray direction
  rd = (gl_FragCoord.xyz - a.xyz) * 2. / a.y + cu;

  // ray marcher
  for(float f=1e0; f<1e1; f++)
    // plasma + sphere
    cu += e = sin(sin(rd*cu) + length(sin(rd*cu)));

  gl_FragColor = vec4(
    // material color
    sin(sin(sin(e.y - a.xyz) * 2. + b.y) / 1e1 + e.y) * a.w,

		1e0
  );
}

Use ints in for loop

precision highp float;

// a.xy = resolution
// a.z = time
// a.w = fade
uniform vec4 a;

// b.x = 1
// b.y = kick drum volume
// b.z = t>>18
uniform vec4 b;

void main() {
  // ray marcher temp result
	vec3 e = b.xxx,
  cu = -e + sin(a.z + b.z),

  // ray direction
  rd = (gl_FragCoord.xyz - a.xyz) * 2. / a.y + cu;

  // ray marcher
  //for(float f=1e0; f<1e1; f++)
  for(int f=0; f<11; f++)
    // plasma + sphere
    cu += e = sin(sin(rd*cu) + length(sin(rd*cu)));

  gl_FragColor = vec4(
    // material color
    sin(sin(sin(e.y - a.xyz) * 2. + b.y) / 1e1 + e.y) * a.w,

		1e0
  );
}


#version 330 core

in vec3 fs_w_norm;

out vec3 color;

uniform vec3 base_color;

void main()
{
	vec3 light_0_dir = vec3(0.577, 0.577, 0.577);
	vec3 light_0_col = vec3(1.0, 1.0, 1.0);
	float intensity_0 = clamp(dot(fs_w_norm, light_0_dir), 0.0, 1.0);

	vec3 light_1_dir = vec3(-0.577, -0.577, -0.577);
	vec3 light_1_col = vec3(0.45, 0.45, 0.5);
	float intensity_1 = clamp(dot(fs_w_norm, light_1_dir), 0.0, 1.0);

	vec3 lit_color = light_0_col * intensity_0 + light_1_col * intensity_1;
	color = base_color * lit_color;
}

Change shader lights to be fixed in world space

#version 330 core

in vec3 fs_w_norm;

out vec3 color;

uniform mat4x4 _V;

uniform vec3 base_color;

void main()
{
	vec3 light_0_dir = (_V * vec4(0.577, 0.577, 0.577, 0.0)).xyz;
	vec3 light_0_col = vec3(1.0, 1.0, 1.0);
	float intensity_0 = clamp(dot(fs_w_norm, light_0_dir), 0.0, 1.0);

	vec3 light_1_dir = (_V * vec4(-0.577, 0.577, -0.577, 0.0)).xyz;
	vec3 light_1_col = vec3(0.45, 0.45, 0.55);
	float intensity_1 = clamp(dot(fs_w_norm, light_1_dir), 0.0, 1.0);

	vec3 lit_color = light_0_col * intensity_0 + light_1_col * intensity_1;
	color = base_color * lit_color;
}


#pragma glslify: applyMaterial = require(./chunks/applyMaterial)
#pragma glslify: applyLight = require(./chunks/applyLight)

void main() {
    vec3 material = baseColor.r >= 0.0 ? baseColor : applyMaterial(baseColor);

    bool lightsEnabled = u_FlatShading < 1.0 && (u_LightColor.r > 0.0 || u_LightColor.g > 0.0 || u_LightColor.b > 0.0);
    vec3 color = lightsEnabled ? applyLight(material) : material;

    bool ambianceEnabled = u_AmbientLight.r > 0.0 || u_AmbientLight.g > 0.0 || u_AmbientLight.b > 0.0;
    vec3 ambience = u_AmbientLight * material;
    vec3 finalColor = ambianceEnabled ? ambience + color : color;

    gl_FragColor = vec4(finalColor, opacity);
}

Update ambient to account for flat shading

#pragma glslify: applyMaterial = require(./chunks/applyMaterial)
#pragma glslify: applyLight = require(./chunks/applyLight)

void main() {
    vec3 material = baseColor.r >= 0.0 ? baseColor : applyMaterial(baseColor);

    bool flatShading = u_FlatShading > 0.0;
    bool lights = length(u_LightColor) > 0.0;
    vec3 color = lights && !flatShading ? applyLight(material) : material;

    bool ambianceEnabled = length(u_AmbientLight) > 0.0;
    vec3 ambience = u_AmbientLight * material;
    vec3 finalColor = ambianceEnabled && !flatShading ? ambience + color : color;

    gl_FragColor = vec4(finalColor, opacity);
}


COMMONDEFS=$(srcdir)/gtk-types.defs $(srcdir)/gdk-types.defs \
		   $(srcdir)/atk-types.defs $(srcdir)/pango-types.defs

GTK_OVERRIDES = \
	$(srcdir)/gtk.overrides \
	$(srcdir)/gtkcontainer.overrides \
	$(srcdir)/gtkstyle.overrides \
	$(srcdir)/gtktextview.overrides \
	$(srcdir)/gtktreeview.overrides

$(builddir)/gen_gtk.c: $(srcdir)/gtk.defs $(COMMONDEFS) $(srcdir)/gtk-extrafuncs.defs $(GTK_OVERRIDES)
$(builddir)/gen_gdk.c: $(srcdir)/gdk.defs $(COMMONDEFS) $(srcdir)/gdk.overrides
$(builddir)/gen_atk.c: $(COMMONDEFS) $(srcdir)/atk.overrides
$(builddir)/gen_pango.c: $(COMMONDEFS) $(srcdir)/pango.overrides

gen_%.c : %.defs
	( \
     $(PHP) $(top_srcdir)/generator/generator.php \
	 	-l $(@D)/gen_$(*F).log \
        -r $(*D)/atk-types.defs \
        -r $(*D)/pango-types.defs \
        -r $(*D)/gdk-types.defs \
        -r $(*D)/gtk-types.defs \
        -o $*.overrides \
        -p $(*F) \
        -f $@ $*.defs \
     && grep -h "^PHP_GTK_EXPORT_CE" $@ | sed -e "s!^!extern !" > $(@D)/gen_$(*F).h \
	)

Adjust paths to common defs.

COMMONDEFS=$(srcdir)/gtk-types.defs $(srcdir)/gdk-types.defs \
		   $(srcdir)/atk-types.defs $(srcdir)/pango-types.defs

GTK_OVERRIDES = \
	$(srcdir)/gtk.overrides \
	$(srcdir)/gtkcontainer.overrides \
	$(srcdir)/gtkstyle.overrides \
	$(srcdir)/gtktextview.overrides \
	$(srcdir)/gtktreeview.overrides

$(builddir)/gen_gtk.c: $(srcdir)/gtk.defs $(COMMONDEFS) $(srcdir)/gtk-extrafuncs.defs $(GTK_OVERRIDES)
$(builddir)/gen_gdk.c: $(srcdir)/gdk.defs $(COMMONDEFS) $(srcdir)/gdk.overrides
$(builddir)/gen_atk.c: $(COMMONDEFS) $(srcdir)/atk.overrides
$(builddir)/gen_pango.c: $(COMMONDEFS) $(srcdir)/pango.overrides

gen_%.c : %.defs
	( \
     $(PHP) $(top_srcdir)/generator/generator.php \
	 	-l $(@D)/gen_$(*F).log \
        -r ext/gtk+/atk-types.defs   \
        -r ext/gtk+/pango-types.defs \
        -r ext/gtk+/gdk-types.defs   \
        -r ext/gtk+/gtk-types.defs   \
        -o $*.overrides \
        -p $(*F) \
        -f $@ $*.defs \
     && grep -h "^PHP_GTK_EXPORT_CE" $@ | sed -e "s!^!extern !" > $(@D)/gen_$(*F).h \
	)


#ifdef GL_ES
precision highp float;
#endif

#if __VERSION__ >= 140
in vec4 aPosition;
    int vec4 vColour;
#else
    varying vec4 vColour;
#endif

void main() {
    gl_FragColor = vColour;
}

Remove extraneous input parameter from lesson 3 if GLSL is 1.4 or higher

#ifdef GL_ES
precision highp float;
#endif

#if __VERSION__ >= 140
    int vec4 vColour;
#else
    varying vec4 vColour;
#endif

void main() {
    gl_FragColor = vColour;
}


#version 330

uniform sampler2D textureSampler;

in vec3 normalColour;
in vec2 texturePoint;

out vec4 fragmentColour;

vec3 getPrimitiveColour();

void main()
{
    //fragmentColour = vec4 (normalColour, 1.0);
    //fragmentColour = vec4 (getPrimitiveColour(), 1.0);
    vec3 textureColour = texture (textureSampler, texturePoint).rgb;
    fragmentColour = vec4 (textureColour, 1.0);
    //fragmentColour = vec4 (textureColour * normalColour, 1.0);
}

vec3 getPrimitiveColour()
{
    switch (gl_PrimitiveID % 3)
    {
        case 0:
            return vec3 (1.0, 0.0, 0.0);
        case 1:
            return vec3 (0.0, 1.0, 0.0);
        case 2:
            return vec3 (0.0, 0.0, 1.0);
    }
}

Fix the white texture issue.

#version 330

uniform sampler2D textureSampler;

in vec3 normalColour;
in vec2 textureOut;

out vec4 fragmentColour;

vec3 getPrimitiveColour();

void main()
{
    //fragmentColour = vec4 (normalColour, 1.0);
    //fragmentColour = vec4 (getPrimitiveColour(), 1.0);
    vec3 textureColour = texture (textureSampler, textureOut).rgb;
    fragmentColour = vec4 (textureColour * normalColour, 1.0);
}

vec3 getPrimitiveColour()
{
    switch (gl_PrimitiveID % 3)
    {
        case 0:
            return vec3 (1.0, 0.0, 0.0);
        case 1:
            return vec3 (0.0, 1.0, 0.0);
        case 2:
            return vec3 (0.0, 0.0, 1.0);
    }
}


attribute highp vec4 v;
uniform highp mat4 matrix;
uniform highp mat4 rotation;

// w -> apply 3d rotation and projection
uniform lowp vec4 tweak;

varying mediump vec2 pos;

void main()
{
    vec4 p = matrix * v;

    if (tweak.w > 0.0) {
        vec4 proj = rotation * p;
        gl_Position = vec4(proj.x, proj.y, 0, proj.z);
    } else {
        gl_Position = p;
    }

    pos = v.xy * 1.37;
}

Use the correct precision specifier in visualizer GLSL.

attribute highp vec4 v;
uniform highp mat4 matrix;
uniform highp mat4 rotation;

// w -> apply 3d rotation and projection
uniform mediump vec4 tweak;

varying mediump vec2 pos;

void main()
{
    vec4 p = matrix * v;

    if (tweak.w > 0.0) {
        vec4 proj = rotation * p;
        gl_Position = vec4(proj.x, proj.y, 0, proj.z);
    } else {
        gl_Position = p;
    }

    pos = v.xy * 1.37;
}


uniform sampler2D t2D;

varying vec2 vUv;

void main() {

	gl_FragColor = texture2D( t2D, vUv );

}

Support decoding, tonemapping, and output encoding

uniform sampler2D t2D;

varying vec2 vUv;

void main() {

	vec4 texColor = texture2D( t2D, vUv );

	gl_FragColor = mapTexelToLinear( texColor );

	#include <tonemapping_fragment>
	#include <encodings_fragment>

}


#version 150 core

in vec2 v_BufPos;
out vec4 Target0;

uniform sampler2D t_CharacterSheet;

const float SHADING_MULTIPLIER = 0.5;

void main() {
  vec4 tex = texture(t_CharacterSheet, v_BufPos).rgba;
  tex *= SHADING_MULTIPLIER;
  if(tex.a < 0.1) {
    discard;
  }
  Target0 = tex;
}

Adjust character & zombie sprite shadings

#version 150 core

in vec2 v_BufPos;
out vec4 Target0;

uniform sampler2D t_CharacterSheet;

void main() {
  vec4 tex = texture(t_CharacterSheet, v_BufPos).rgba;
  if(tex.a < 0.1) {
    discard;
  }
  tex.r = smoothstep(0.1, 1.0, tex.r);
  tex.g = smoothstep(0.1, 1.0, tex.g);
  tex.b = smoothstep(0.1, 1.0, tex.b);
  Target0 = tex;
}


uniform float outlineWidth;

varying vec4 v_color;
varying vec4 v_outlineColor;
varying float v_width;

czm_material czm_getMaterial(czm_materialInput materialInput)
{
    czm_material material = czm_getDefaultMaterial(materialInput);

    float halfInteriorWidth =  0.5 * (v_width - outlineWidth) / v_width;
    float s = step(0.5 - halfInteriorWidth, materialInput.st.t);
    s *= 1.0 - step(0.5 + halfInteriorWidth, materialInput.st.t);

    vec4 color = mix(v_outlineColor, v_color, s);

    material.diffuse = color.rgb;
    material.alpha = color.a;

    return material;
}

Add anti-aliasing to polyline outline material.

uniform float outlineWidth;

varying vec4 v_color;
varying vec4 v_outlineColor;
varying float v_width;

czm_material czm_getMaterial(czm_materialInput materialInput)
{
    czm_material material = czm_getDefaultMaterial(materialInput);

    vec2 st = materialInput.st;
    float halfInteriorWidth =  0.5 * (v_width - outlineWidth) / v_width;
    float b = step(0.5 - halfInteriorWidth, st.t);
    b *= 1.0 - step(0.5 + halfInteriorWidth, st.t);

    // Find the distance from the closest separator (region between two colors)
    float d1 = abs(st.t - (0.5 - halfInteriorWidth));
    float d2 = abs(st.t - (0.5 + halfInteriorWidth));
    float value = min(d1, d2);

    //anti-aliasing
    const float fuzz = 0.1;
    float val1 = clamp(value / fuzz, 0.0, 1.0);
    float val2 = clamp((value - 0.5) / fuzz, 0.0, 1.0);
    val1 = val1 * (1.0 - val2);
    val1 = val1 * val1 * (3.0 - (2.0 * val1));
    val1 = pow(val1, 0.5); //makes the transition nicer

    vec4 midColor = (v_outlineColor + v_color) * 0.5;
    vec4 currentColor = mix(v_outlineColor, v_color, b);
    vec4 color = mix(midColor, currentColor, val1);

    material.diffuse = color.rgb;
    material.alpha = color.a;

    return material;
}


#version 400 core

uniform mat4 g_mWorldViewProjection;

// GLSL tessellation evaluation shader (domain shader in HLSL).
layout(triangles, equal_spacing, cw) in;
void main()
{
    // Baricentric interpolation
    vec3 finalPos = (gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position).xyz;
    gl_Position = g_mWorldViewProjection * vec4(finalPos, 1.0);
}

Fix implicit vec 3 to vec4 conversion in Tessellation sample GLSL shader

#version 400 core

uniform mat4 g_mWorldViewProjection;

// GLSL tessellation evaluation shader (domain shader in HLSL).
layout(triangles, equal_spacing, cw) in;
void main()
{
    // Baricentric interpolation
    vec3 finalPos = vec3(gl_TessCoord.x * gl_in[0].gl_Position +
                         gl_TessCoord.y * gl_in[1].gl_Position +
                         gl_TessCoord.z * gl_in[2].gl_Position);
    gl_Position = g_mWorldViewProjection * vec4(finalPos, 1.0);
}


// Gmsh project created on Thu Mar  6 16:27:33 2008
Point(1) = {0,0,0};
Extrude {1.7,0,0} {
  Point{1}; Layers{80};
}
Extrude {0,0,0.6} {
  Line{1}; Layers{30};
}
Extrude {0,0.02,0} {
  Surface{5}; Layers{1};
}
Physical Surface(38) = {5};
Physical Surface(39) = {27};
Physical Surface(40) = {22};
Physical Surface(41) = {14};
Physical Surface(42) = {26};
Physical Surface(43) = {18};
Physical Volume(44) = {1};

Reorder order of extrusions to ensure periodic sides match up.

// Gmsh project created on Thu Mar  6 16:27:33 2008
Point(1) = {0,0,0};
Extrude {0,0,0.6} {
  Point{1}; Layers{30};
}
Extrude {0,0.02,0} {
  Line{1}; Layers{1};
}
Extrude {1.7,0,0} {
  Surface{5}; Layers{80};
}
Physical Surface(38) = {22};
Physical Surface(39) = {14};
Physical Surface(40) = {18};
Physical Surface(41) = {26};
Physical Surface(42) = {5};
Physical Surface(43) = {27};
Physical Volume(44) = {1};


uniform sampler2D texDiffuse;

varying mediump vec4 texCoord[2];

#define invLDRRange 1.0//(255.0/240.0)
#if 1
// HDTV with BT.709
#define luminance(tex) dot(tex, vec4(0.2126, 0.7152, 0.0722, 0.0) * invLDRRange)
#else
// SDTV with BT.601
#define luminance(tex) dot(tex, vec4(0.299, 0.587, 0.114, 0.0) * invLDRRange)
#endif

void main()
{
  gl_FragColor = texture2D(texDiffuse, texCoord[0].xy);
  lowp float lum = luminance(gl_FragColor);

  lowp vec4 tmp = texture2D(texDiffuse, texCoord[0].zw);
  lum = max(lum, luminance(tmp));
  gl_FragColor += tmp;

  tmp = texture2D(texDiffuse, texCoord[1].xy);
  lum = max(lum, luminance(tmp));
  gl_FragColor += tmp;

  tmp = texture2D(texDiffuse, texCoord[1].zw);
  lum = max(lum, luminance(tmp));
  gl_FragColor += tmp;

  gl_FragColor *= (1.0 / 4.0);
  gl_FragColor.a = lum;
}

Optimize the dimension of vector.

uniform sampler2D texDiffuse;

varying mediump vec4 texCoord[2];

#define invLDRRange 1.0//(255.0/240.0)
#if 1
// HDTV with BT.709
#define luminance(tex) dot(tex, vec3(0.2126, 0.7152, 0.0722) * invLDRRange)
#else
// SDTV with BT.601
#define luminance(tex) dot(tex, vec3(0.299, 0.587, 0.114) * invLDRRange)
#endif

void main()
{
  gl_FragColor.rgb = texture2D(texDiffuse, texCoord[0].xy).rgb;
  lowp float lum = luminance(gl_FragColor.rgb);

  lowp vec3 tmp = texture2D(texDiffuse, texCoord[0].zw).rgb;
  lum = max(lum, luminance(tmp));
  gl_FragColor.rgb += tmp;

  tmp = texture2D(texDiffuse, texCoord[1].xy).rgb;
  lum = max(lum, luminance(tmp));
  gl_FragColor.rgb += tmp;

  tmp = texture2D(texDiffuse, texCoord[1].zw).rgb;
  lum = max(lum, luminance(tmp));
  gl_FragColor.rgb += tmp;

  gl_FragColor.rgb *= (1.0 / 4.0);
  gl_FragColor.a = lum;
}


/*****************************************************************************************
 *                                                                                *
 * OpenSpace                                                                             *
 *                                                                                *
 * Copyright (c) 2014 - 2016                                                             *
 *                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
 * software and associated documentation files (the "Software"), to deal in the Software *
 * without restriction, including without limitation the rights to use, copy, modify,    *
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
 * permit persons to whom the Software is furnished to do so, subject to the following   *
 * conditions:                                                                           *
 *                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies *
 * or substantial portions of the Software.                                              *
 *                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
 ****************************************************************************************/

#version __CONTEXT__

in vec4 position;
out vec2 texCoord;

void main() {
    gl_Position = position;
    texCoord = 0.5 + position.xy / 2.0;
}

Fix shader compile error for inside volume raycasting

/*****************************************************************************************
 *                                                                                *
 * OpenSpace                                                                             *
 *                                                                                *
 * Copyright (c) 2014 - 2016                                                             *
 *                                                                                *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this  *
 * software and associated documentation files (the "Software"), to deal in the Software *
 * without restriction, including without limitation the rights to use, copy, modify,    *
 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to    *
 * permit persons to whom the Software is furnished to do so, subject to the following   *
 * conditions:                                                                           *
 *                                                                                *
 * The above copyright notice and this permission notice shall be included in all copies *
 * or substantial portions of the Software.                                              *
 *                                                                                *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,   *
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A         *
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT    *
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF  *
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE  *
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                                         *
 ****************************************************************************************/

#version __CONTEXT__

in vec4 position;

out vec2 texCoord;
out vec3 vPosition;
out vec4 worldPosition;

void main() {
    gl_Position = position;
    texCoord = 0.5 + position.xy / 2.0;

    vPosition = position.xyz;
    worldPosition = position;
}


attribute vec4 vertex;
attribute vec3 color;
attribute vec2 texCoordinate;
uniform mat4 modelView;
uniform mat4 projection;
varying vec2 v_texCoord;
varying vec3 fColor;
varying vec4 eyePosition;
varying float radius;

void main()
{
  radius = abs(texCoordinate.x);
  fColor = color;
  v_texCoord = texCoordinate / radius;
  gl_Position = modelView * vertex;
  eyePosition = gl_Position;
  gl_Position.xy += texCoordinate;
  gl_Position = projection * gl_Position;
}

Fix rendering artifact for partially-clipped spheres.

attribute vec4 vertex;
attribute vec3 color;
attribute vec2 texCoordinate;
uniform mat4 modelView;
uniform mat4 projection;
varying vec2 v_texCoord;
varying vec3 fColor;
varying vec4 eyePosition;
varying float radius;

void main()
{
  radius = abs(texCoordinate.x);
  fColor = color;
  v_texCoord = texCoordinate / radius;
  gl_Position = modelView * vertex;
  eyePosition = gl_Position;

  // Test if the closest point on the sphere would be clipped.
  vec4 clipTestNear = eyePosition;
  clipTestNear.z += radius;
  clipTestNear = projection * clipTestNear;
  if (clipTestNear.z > -clipTestNear.w) {
    // If not, calculate clip coordinate
    gl_Position.xy += texCoordinate;
    gl_Position = projection * gl_Position;
  }
  else {
    // If so, invalidate the clip coordinate to ensure that it will be clipped.
    gl_Position.w = 0.0;
  }
}


#version 330

in vec4 io_color;
in vec2 io_texcoord;

uniform sampler2D surface_texture;

void main()
{
	gl_FragColor = io_color * texture2D(surface_texture, io_texcoord);
}

Fix GLSL forward compatibility issues

#version 330

in vec4 io_color;
in vec2 io_texcoord;

uniform sampler2D surface_texture;

out vec4 o_color;

void main()
{
	o_color = io_color * texture(surface_texture, io_texcoord);
}


attribute vec4 attrib0;
attribute vec4 attrib1;

uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
uniform float tileCount;

varying vec3  normal;
varying vec2  tileCoord;
varying vec2  texCoord;
varying float ambientOcclusion;

void main() {
  //Compute position
  vec3 position = attrib0.xyz;

  //Compute ambient occlusion
  ambientOcclusion = attrib0.w / 255.0;

  //Compute normal
  normal = 128.0 - attrib1.xyz;

  //Compute texture coordinate
  texCoord = vec2(dot(position, vec3(normal.y-normal.z, 0, normal.x)),
                  dot(position, vec3(0, -abs(normal.x+normal.z), normal.y)));

  //Compute tile coordinate
  float tx    = attrib1.w / tileCount;
  tileCoord.x = floor(tx);
  tileCoord.y = fract(tx) * tileCount;

  gl_Position = projection * view * model * vec4(position, 1.0);
}

Read packed normal for mesher voxel format change

attribute vec4 attrib0;
attribute vec4 attrib1;

uniform mat4 projection;
uniform mat4 view;
uniform mat4 model;
uniform float tileCount;

varying vec3  normal;
varying vec2  tileCoord;
varying vec2  texCoord;
varying float ambientOcclusion;

void main() {
  //Compute position
  vec3 position = attrib0.xyz;

  //Compute ambient occlusion
  ambientOcclusion = attrib0.w / 255.0;

  //Extracted packed bits of normal. GLSL 1.0 doesn't support bitfieldExtract or even bitwise operations :(
  int packedNormal = int(attrib1.x);
  int nx = packedNormal / 16;               // xx____
  int ny = packedNormal / 4 - nx * 4;       // __xx__
  int nz = packedNormal - nx * 16 - ny * 4; // ____xx

  normal = 128.0 - vec3(nx + 127, ny + 127, nz + 127);

  //Compute texture coordinate
  texCoord = vec2(dot(position, vec3(normal.y-normal.z, 0, normal.x)),
                  dot(position, vec3(0, -abs(normal.x+normal.z), normal.y)));

  //Compute tile coordinate
  float tx    = attrib1.w / tileCount;
  tileCoord.x = floor(tx);
  tileCoord.y = fract(tx) * tileCount;

  gl_Position = projection * view * model * vec4(position, 1.0);
}


#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D state;
uniform vec2 scale;

float get(vec2 offset) {
    return texture2D(state, (gl_FragCoord.xy + offset) / scale).r;
}

void main() {
    float current = get(vec2(0.0, 0.0));
    float sum =
        get(vec2(-1.0, -1.0)) +
        get(vec2(-1.0,  0.0)) +
        get(vec2(-1.0,  1.0)) +
        get(vec2( 0.0, -1.0)) +
        get(vec2( 0.0,  1.0)) +
        get(vec2( 1.0, -1.0)) +
        get(vec2( 1.0,  0.0)) +
        get(vec2( 1.0,  1.0));
    if (sum == 3.0) {
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    } else if (sum == 2.0) {
        gl_FragColor = vec4(current, current, current, 1.0);
    } else {
        gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    }
}

Use ints in the GoL shader.

#ifdef GL_ES
precision mediump float;
#endif

uniform sampler2D state;
uniform vec2 scale;

int get(vec2 offset) {
    return int(texture2D(state, (gl_FragCoord.xy + offset) / scale).r);
}

void main() {
    int sum =
        get(vec2(-1.0, -1.0)) +
        get(vec2(-1.0,  0.0)) +
        get(vec2(-1.0,  1.0)) +
        get(vec2( 0.0, -1.0)) +
        get(vec2( 0.0,  1.0)) +
        get(vec2( 1.0, -1.0)) +
        get(vec2( 1.0,  0.0)) +
        get(vec2( 1.0,  1.0));
    if (sum == 3) {
        gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
    } else if (sum == 2) {
        float current = float(get(vec2(0.0, 0.0)));
        gl_FragColor = vec4(current, current, current, 1.0);
    } else {
        gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
    }
}


#version 420 core

#extension GL_ARB_shading_language_420pack : require

in VS_OUT {
    vec2 uv;
} fs_in;

out vec4 out_color;

uniform vec4 screenSize;

layout(binding = 0) uniform sampler2D colorTexture;

void main(void) {
    const vec2 image_size = textureSize(colorTexture, 0);
    const vec2 ratio = screenSize.xy / image_size.xy;
    const vec2 scaled_image_size = image_size.xy * min(ratio.x, ratio.y);

    // Compute the size of the black bars left/right or above/below the image
    const vec2 offset = (screenSize.xy - scaled_image_size) / 2.0;

    // Compute the normalized clip coordinates to position the image in the center
    const vec2 begin_uv = offset / screenSize.xy;
    const vec2 end_uv = vec2(1.0) - begin_uv;

    const bool e1 = all(greaterThanEqual(fs_in.uv, begin_uv));
    const bool e2 = all(lessThanEqual(fs_in.uv, end_uv));

    const vec2 image_uv = clamp((fs_in.uv - begin_uv) / (end_uv - begin_uv), 0.0, 1.0);
    out_color.rgb = float(e1 && e2) * vec3(texture(colorTexture, image_uv));
}

Set alpha to 100 % opaque in KTX viewer to avoid glitches

#version 420 core

#extension GL_ARB_shading_language_420pack : require

in VS_OUT {
    vec2 uv;
} fs_in;

out vec4 out_color;

uniform vec4 screenSize;

layout(binding = 0) uniform sampler2D colorTexture;

void main(void) {
    const vec2 image_size = textureSize(colorTexture, 0);
    const vec2 ratio = screenSize.xy / image_size.xy;
    const vec2 scaled_image_size = image_size.xy * min(ratio.x, ratio.y);

    // Compute the size of the black bars left/right or above/below the image
    const vec2 offset = (screenSize.xy - scaled_image_size) / 2.0;

    // Compute the normalized clip coordinates to position the image in the center
    const vec2 begin_uv = offset / screenSize.xy;
    const vec2 end_uv = vec2(1.0) - begin_uv;

    const bool e1 = all(greaterThanEqual(fs_in.uv, begin_uv));
    const bool e2 = all(lessThanEqual(fs_in.uv, end_uv));

    const vec2 image_uv = clamp((fs_in.uv - begin_uv) / (end_uv - begin_uv), 0.0, 1.0);
    out_color.rgb = float(e1 && e2) * vec3(texture(colorTexture, image_uv));
    out_color.a = 1.0;
}


#version 330 core

in vec2 TexCoords;
in vec4 Color;

out vec4 color;

uniform sampler2D text;

void main()
{
    vec4 t = texture(text, TexCoords);
    if (t.r < 0.1)
        discard;
    color = vec4(Color.xyz, Color.w * t.r);
}

Improve shader for UI and alpha handling

#version 330 core

in vec2 TexCoords;
in vec4 Color;

out vec4 color;

uniform sampler2D text;

void main()
{
    vec4 t = texture(text, TexCoords);
    float a = Color.w * t.r;
    if (a < 0.1)
        discard;
    color = vec4(Color.xyz, a);
}


$(srcdir)/php_gtk_ext.c: $(srcdir)/php_gtk_ext.c.in $(builddir)/config.status
	@echo "creating main/php_gtk_ext.c"
	sh $(top_srcdir)/build2/genext.sh $(srcdir)/php_gtk_ext.c.in $(top_srcdir) "" $(AWK) $(PHP_GTK_EXTENSIONS) > $(srcdir)/php_gtk_ext.c

cvsclean:
	@for i in `find . -name .cvsignore`; do \
		(cd `dirname $$i` 2>/dev/null && rm -rf `cat .cvsignore` *.o *.a || true); \
	done
	@rm -f $(SUBDIRS) 2>/dev/null || true

Add clean-gen and clean-caches targets.

$(srcdir)/php_gtk_ext.c: $(srcdir)/php_gtk_ext.c.in $(builddir)/config.status
	@echo "creating main/php_gtk_ext.c"
	sh $(top_srcdir)/build2/genext.sh $(srcdir)/php_gtk_ext.c.in $(top_srcdir) "" $(AWK) $(PHP_GTK_EXTENSIONS) > $(srcdir)/php_gtk_ext.c

cvsclean:
	@for i in `find . -name .cvsignore`; do \
		(cd `dirname $$i` 2>/dev/null && rm -rf `cat .cvsignore` *.o *.a || true); \
	done
	@rm -f $(SUBDIRS) 2>/dev/null || true

clean-caches:
	find ext -name gen\*.cache | xargs rm -f

clean-gen:
	find ext -name gen\*.[ch] | xargs rm -f

.PHONY: clean-caches clean-gen


#version 330 core

#define NB_DIRECTIONAL_LIGHTS 1
#define NB_POINT_LIGHTS 1

in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

out vec4 color;

#include "lighting.frag"

void main()
{
    // Properties
    vec3 norm = normalize(Normal);
    vec3 viewDir = normalize(viewPos - FragPos);

    vec3 result;
    for(int i = 0; i < NB_DIRECTIONAL_LIGHTS; i++)
      result += CalcDirLight(dirLights[i], norm, viewDir);
    for(int i = 0; i < NB_POINT_LIGHTS; i++)
        result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
    // result += CalcSpotLight(spotLight, norm, FragPos, viewDir);

    color = vec4(result, 1.0);
}

Fix uninitialized variable in shader causing glitches from time to time (and code style)

#version 330 core

#define NB_DIRECTIONAL_LIGHTS 1
#define NB_POINT_LIGHTS 1

in vec3 FragPos;
in vec3 Normal;
in vec2 TexCoords;

out vec4 color;

#include "lighting.frag"

void main()
{
    // Properties
    vec3 norm = normalize(Normal);
    vec3 viewDir = normalize(viewPos - FragPos);

    vec3 result = vec3(0.0, 0.0, 0.0);
    for (int i = 0; i < NB_DIRECTIONAL_LIGHTS; i++) {
        result += CalcDirLight(dirLights[i], norm, viewDir);
    }

    for (int i = 0; i < NB_POINT_LIGHTS; i++) {
        result += CalcPointLight(pointLights[i], norm, FragPos, viewDir);
    }
    // result += CalcSpotLight(spotLight, norm, FragPos, viewDir);

    color = vec4(result, 1.0);
}


#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_out
{
    float4 gl_Position [[position]];
};

struct main0_in
{
    uint gl_BaseVertex [[base_vertex]];
    uint gl_BaseInstance [[base_instance]];
};

vertex main0_out main0(main0_in in [[stage_in]])
{
    main0_out out = {};
    out.gl_Position = float4(float(in.gl_BaseVertex), float(in.gl_BaseInstance), 0.0f, 1.0f);
    return out;
}

Fix MSL shader_draw_parameters reference output.

#include <metal_stdlib>
#include <simd/simd.h>

using namespace metal;

struct main0_out
{
    float4 gl_Position [[position]];
};

vertex main0_out main0(uint gl_BaseVertex [[base_vertex]], uint gl_BaseInstance [[base_instance]])
{
    main0_out out = {};
    out.gl_Position = float4(float(gl_BaseVertex), float(gl_BaseInstance), 0.0, 1.0);
    return out;
}


/**
 * @private
 */
float czm_alphaWeight(float a)
{
    // See Weighted Blended Order-Independent Transparency for examples of different weighting functions:
    // http://jcgt.org/published/0002/02/09/
    float z = czm_windowToEyeCoordinates(gl_FragCoord).z;
    return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 100.0 / (1e-5 + pow(abs(z) / 10.0, 3.0) + pow(abs(z) / 200.0, 6.0))));
}

Update weight function and fix 2D.

/**
 * @private
 */
float czm_alphaWeight(float a)
{
    // See Weighted Blended Order-Independent Transparency for examples of different weighting functions:
    // http://jcgt.org/published/0002/02/09/

    // This function uses the fragment depth. The other functions in the paper are based on distance from the camera.
    // If we decide to use one of those functions, we could use czm_windowToEyeCoordinates, but that would break
    // 2D because it relies on czm_inverseProjection which would throw when trying to invert the orthographic
    // projection matrix. Another option would be to use a varying containing the position in eye coordinates.

    return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 1e10 * pow(1.0 - gl_FragCoord.z, 3.0)));
}


#property description De-sync the shutter and the film feed

void main(void) {

    // Lookup what offset to display the picture at
    float offset = texture(iChannel[1], vec2(0.5, 0.5)).r;

    // Display the frame from iChannel[2] at that offset
    vec4 c = texture(iChannel[2], mod(uv + vec2(0., offset), 1.));

    fragColor = c;
}

#buffershader

// This shader integrates iIntensity
// on a per-frame basis
// to maintain vsync
// (all pixels are the same color)

void main(void) {
    float v = mod(texture(iChannel[1], vec2(0.5, 0.5)).r + iIntensity, 1.);

    // If intensity is low, decay to zero
    v *= 0.9 + 0.1 * step(0.05, iIntensity);

    fragColor = vec4(v);
}

#buffershader

// This shader mirrors the input when intensity is low,
// and freezes the frame more and more as the intensity increases

void main(void) {
    float freeze = step(0.8, iIntensity);
    fragColor = mix(texture(iInputs[0], uv), texture(iChannel[2], uv), freeze);
}

Stop film in direction of travel

#property description De-sync the shutter and the film feed

void main(void) {

    // Lookup what offset to display the picture at
    float offset = texture(iChannel[1], vec2(0.5, 0.5)).r;

    // Display the frame from iChannel[2] at that offset
    vec4 c = texture(iChannel[2], mod(uv + vec2(0., offset), 1.));

    fragColor = c;
}

#buffershader

// This shader integrates iIntensity
// on a per-frame basis
// to maintain vsync
// (all pixels are the same color)

void main(void) {
    float v = mod(texture(iChannel[1], vec2(0.5, 0.5)).r - iIntensity, 1.);

    // If intensity is low, decay to zero
    v *= 0.9 + 0.1 * step(0.05, iIntensity);

    fragColor = vec4(v);
}

#buffershader

// This shader mirrors the input when intensity is low,
// and freezes the frame more and more as the intensity increases

void main(void) {
    float freeze = step(0.8, iIntensity);
    fragColor = mix(texture(iInputs[0], uv), texture(iChannel[2], uv), freeze);
}


attribute vec3 aVertexPosition;
attribute vec2 aWeight;

attribute float aJointIndex;
attribute float aJointWeight;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

uniform mat4 boneMatrices[2];

void main (void) {
  float foo = aJointIndex + aJointWeight;
  gl_Position = uPMatrix * uMVMatrix * boneMatrices[1] * vec4(aVertexPosition, 1.0);
}

Use the right joints in the shader

attribute vec3 aVertexPosition;
attribute vec2 aWeight;

attribute float aJointIndex;
attribute float aJointWeight;

uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;

uniform mat4 boneMatrices[2];

void main (void) {
  mat4 jointMatrix;
  if (aJointIndex < 1.0) {
    jointMatrix = boneMatrices[0];
  } else if (aJointIndex < 2.0) {
    jointMatrix = boneMatrices[1];
  }
  // We only have one index right now... so the weight is always 1.
  gl_Position = uPMatrix * uMVMatrix * jointMatrix * aJointWeight * vec4(aVertexPosition, 1.0);
}


#include "glsl_globals.h"

IO_LOCATION(0) out vec4 color_out;

void main(void)
{
  color_out = intBitsToFloat(gl_PrimitiveID).xxxx;
}

Add missing copyright statement in shader

/******************************************************************************
 * The MIT License (MIT)
 *
 * Copyright (c) 2020 Baldur Karlsson
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 ******************************************************************************/

#include "glsl_globals.h"

IO_LOCATION(0) out vec4 color_out;

void main(void)
{
  color_out = intBitsToFloat(gl_PrimitiveID).xxxx;
}


#version 150

uniform sampler2D image;

in vec3 cI; // incident ray, camera space
in vec3 cN; // normal, camera space

out vec4 fragColor;

void main()
{
    vec3  r = reflect( cI, cN );
    float m = 2.0 * sqrt( pow( r.x, 2.0 ) + pow( r.y, 2.0 ) + pow( r.z + 1., 2.0 ) );
    vec2 vN = r.xy / m + 0.5;

    fragColor = vec4( texture2D( image, vN ).rgb, 1.0 );
}

Refactor of matcap fragment shader.

#version 150

uniform sampler2D image;

in vec3 cI; // incident ray, camera space
in vec3 cN; // normal, camera space

out vec4 fragColor;

void main()
{
	vec3 r = reflect( cI, cN );  r.z += 1.0;
	float m = 0.5 * inversesqrt( dot( r, r ) );
	vec2 uv = r.xy * m + 0.5;

	fragColor = vec4( texture( image, uv ).rgb, 1.0 );
}


#ifdef TANGRAM_FRAGMENT_SHADER

uniform sampler2D u_rasters[TANGRAM_NUM_RASTER_SOURCES];
uniform vec2 u_raster_sizes[TANGRAM_NUM_RASTER_SOURCES];
uniform vec3 u_raster_offsets[TANGRAM_NUM_RASTER_SOURCES];

#define currentRasterUV(raster_index) \
    (v_modelpos_base_zoom.xy)

#define sampleRaster(raster_index) \
    (texture2D(u_rasters[raster_index], currentRasterUV(raster_index)))

#endif

Add pixel sampler/raster size shader accesors

#ifdef TANGRAM_FRAGMENT_SHADER

uniform sampler2D u_rasters[TANGRAM_NUM_RASTER_SOURCES];
uniform vec2 u_raster_sizes[TANGRAM_NUM_RASTER_SOURCES];
uniform vec3 u_raster_offsets[TANGRAM_NUM_RASTER_SOURCES];

// TODO
#define adjustRasterUV(raster_index, uv) \
    (uv)

#define currentRasterUV(raster_index) \
    (v_modelpos_base_zoom.xy)

#define sampleRasterAtPixel(raster_index, pixel) \
    (texture2D(u_rasters[raster_index], adjustRasterUV(raster_index, (pixel) / rasterPixelSize(raster_index))))

#define sampleRaster(raster_index) \
    (texture2D(u_rasters[raster_index], currentRasterUV(raster_index)))

#define rasterPixelSize(raster_index) \
    (u_raster_sizes[raster_index])

#endif


COMMONDEFS=$(srcdir)/gtk-types.defs $(srcdir)/gdk-types.defs \
		   $(srcdir)/atk-types.defs $(srcdir)/pango-types.defs

GTK_OVERRIDES = \
	$(srcdir)/gtk.overrides \
	$(srcdir)/gtkstyle.overrides

$(srcdir)/gen_gtk.c: $(srcdir)/gtk.defs $(COMMONDEFS) $(srcdir)/gtk-extrafuncs.defs $(GTK_OVERRIDES)
$(srcdir)/gen_gdk.c: $(srcdir)/gdk.defs $(COMMONDEFS) $(srcdir)/gdk.overrides
$(srcdir)/gen_atk.c: $(COMMONDEFS) $(srcdir)/atk.overrides
$(srcdir)/gen_pango.c: $(COMMONDEFS) $(srcdir)/pango.overrides

gen_%.c : %.defs
	( \
     $(PHP) $(top_srcdir)/generator/generator.php \
	 	-l $(@D)/gen_$(*F).log \
        -r $(*D)/atk-types.defs \
        -r $(*D)/pango-types.defs \
        -r $(*D)/gdk-types.defs \
        -r $(*D)/gtk-types.defs \
        -o $*.overrides \
        -p $(*F) \
        -f $@ $*.defs \
     && grep -h "^PHP_GTK_EXPORT_CE" $@ | sed -e "s!^!extern !" > $(@D)/gen_$(@F).h \
	)

Fix generation error that resulted in a wrong header file being created.

COMMONDEFS=$(srcdir)/gtk-types.defs $(srcdir)/gdk-types.defs \
		   $(srcdir)/atk-types.defs $(srcdir)/pango-types.defs

GTK_OVERRIDES = \
	$(srcdir)/gtk.overrides \
	$(srcdir)/gtkstyle.overrides

$(srcdir)/gen_gtk.c: $(srcdir)/gtk.defs $(COMMONDEFS) $(srcdir)/gtk-extrafuncs.defs $(GTK_OVERRIDES)
$(srcdir)/gen_gdk.c: $(srcdir)/gdk.defs $(COMMONDEFS) $(srcdir)/gdk.overrides
$(srcdir)/gen_atk.c: $(COMMONDEFS) $(srcdir)/atk.overrides
$(srcdir)/gen_pango.c: $(COMMONDEFS) $(srcdir)/pango.overrides

gen_%.c : %.defs
	( \
     $(PHP) $(top_srcdir)/generator/generator.php \
	 	-l $(@D)/gen_$(*F).log \
        -r $(*D)/atk-types.defs \
        -r $(*D)/pango-types.defs \
        -r $(*D)/gdk-types.defs \
        -r $(*D)/gtk-types.defs \
        -o $*.overrides \
        -p $(*F) \
        -f $@ $*.defs \
     && grep -h "^PHP_GTK_EXPORT_CE" $@ | sed -e "s!^!extern !" > $(@D)/gen_$(*F).h \
	)


uniform mat4 transform;
uniform mat4 texMatrix;
uniform mat3 normalMatrix;

uniform sampler2D displacementMap;
uniform float displaceStrength;

attribute vec4 vertex;
attribute vec4 color;
attribute vec2 texCoord;
attribute vec3 normal;

varying vec4 vertColor;
varying vec4 vertTexCoord;
varying vec3 vertNormal;
varying vec3 vertLightDir;

void main() {
	// Calculating texture coordinates, with r and q set both to one
	vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);

	vec4 dv = texture2D( displacementMap, vertTexCoord.xy ); // rgba color of displacement map
	float df = 0.30*dv.r + 0.59*dv.g + 0.11*dv.b; // brightness calculation to create displacement float from rgb values
	vec4 newVertexPos = vertex + vec4(normal * df * 2.0, 0.0); // regular vertex position + direction * displacementMap * displaceStrength

	// Vertex in clip coordinates
	// general displacement:
		// gl_Position = transform * newVertexPos;
	// for a flat sheet:
	// gl_Position = transform * vec4(newVertexPos.x, newVertexPos.y, displaceStrength * df, 1.0);
	gl_Position = transform * vec4(vertex.x, vertex.y, displaceStrength * df, 1.0);

	// pass values along to fragment shader
	vertColor = color;
	vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
}

Clean up w/Marc & Jeremy

uniform mat4 transform;
uniform mat4 texMatrix;
uniform mat3 normalMatrix;

uniform sampler2D displacementMap;
uniform float displaceStrength;

attribute vec4 vertex;
attribute vec4 color;
attribute vec2 texCoord;
attribute vec3 normal;

varying vec4 vertColor;
varying vec4 vertTexCoord;
varying vec3 vertNormal;
varying vec3 vertLightDir;

void main() {
	// Calculating texture coordinates, with r and q set both to one
	// And pass values along to fragment shader
	vertTexCoord = texMatrix * vec4(texCoord, 1.0, 1.0);
	vertColor = color;

	vec4 dv = texture2D( displacementMap, vertTexCoord.xy ); // rgba color of displacement map
	float df = 0.30*dv.r + 0.59*dv.g + 0.11*dv.b; // brightness calculation to create displacement float from rgb values
	gl_Position = transform * vec4(vertex.x, vertex.y, displaceStrength * df, 1.0);
}


/* #include "perspective.glsl" */

uniform float noise_amplitude;
uniform vec2 noise_freq;

varying float scaled_noise_amplitude;

void main() {
  vec4 proj;
  vec2 texc;

  proj = perspective_proj(gl_Vertex);
  gl_Position = gl_ModelViewProjectionMatrix * proj;
  texc = gl_Vertex.xy / METRE / 4.0f;
  texc.s += gl_Vertex.z / METRE / 4.0f;
  texc *= noise_freq;
  gl_TexCoord[0] = vec4(texc.s, texc.t, 0.0f, 1.0f);
  scaled_noise_amplitude = min(1.0f, noise_amplitude -
                               noise_amplitude * abs(proj.z) / METRE / 256.0f);
}

Fix manifold noise amplitude calculation.

/* #include "perspective.glsl" */

uniform float noise_amplitude;
uniform vec2 noise_freq;

varying float scaled_noise_amplitude;

void main() {
  vec4 proj;
  vec2 texc;

  proj = perspective_proj(gl_Vertex);
  gl_Position = gl_ModelViewProjectionMatrix * proj;
  texc = gl_Vertex.xy / METRE / 4.0f;
  texc.s += gl_Vertex.z / METRE / 4.0f;
  texc *= noise_freq;
  gl_TexCoord[0] = vec4(texc.s, texc.t, 0.0f, 1.0f);
  scaled_noise_amplitude = noise_amplitude - noise_amplitude * clamp(
    abs(proj.z) / METRE / 256.0f, 0.0f, 1.0f);
}


#version 400 core

uniform mat4 g_mWorldViewProjection;

// GLSL tessellation evaluation shader (domain shader in HLSL).
layout(triangles, equal_spacing, cw) in;
void main()
{
    // Baricentric interpolation
    vec3 finalPos = (gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position).xyz;
    gl_Position = g_mWorldViewProjection * vec4(finalPos, 1.0);
}

Fix implicit vec 3 to vec4 conversion in Tessellation sample GLSL shader

#version 400 core

uniform mat4 g_mWorldViewProjection;

// GLSL tessellation evaluation shader (domain shader in HLSL).
layout(triangles, equal_spacing, cw) in;
void main()
{
    // Baricentric interpolation
    vec3 finalPos = vec3(gl_TessCoord.x * gl_in[0].gl_Position +
                         gl_TessCoord.y * gl_in[1].gl_Position +
                         gl_TessCoord.z * gl_in[2].gl_Position);
    gl_Position = g_mWorldViewProjection * vec4(finalPos, 1.0);
}


// @program p_simple, vertex, fragment

uniform mat4 u_mvp;

-- vertex

attribute vec4 a_position;

void main()
{
    vec4 p = a_position;
    p.xy -= 0.5;
    p.y *= -1.0;
    gl_Position = u_mvp * p;
}

-- fragment

void main()
{
    gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0);
}

Fix point size on web.

// @program p_simple, vertex, fragment

uniform mat4 u_mvp;

-- vertex

attribute vec4 a_position;

void main()
{
    vec4 p = a_position;
    p.xy -= 0.5;
    p.y *= -1.0;
    gl_Position = u_mvp * p;
    gl_PointSize = 2.0;
}

-- fragment

void main()
{
    gl_FragColor = vec4(0.2, 0.2, 0.2, 1.0);
}


#version 140
#extension GL_ARB_shading_language_include : enable
#extension GL_ARB_explicit_attrib_location : enable

layout(location = 0) out vec4 color;
in vec2 position;

uniform ivec2 windowSize;

// The symbols below will be auto-replaced
#textures
#includes

void main()
{
    vec4 sphereData = sphere(position, vec2(0.5, 0.5), 0.2, vec2(windowSize));
    vec3 light = vec3(1, 1, 1);
    vec3 sphereColor = vec3(0.3, 0.3, 0.9);
    color = vec4(sphereData.a * diffuse(sphereData.xyz, light) * sphereColor, 2000);
}

Add phong shading example to main shader

#version 140
#extension GL_ARB_shading_language_include : enable
#extension GL_ARB_explicit_attrib_location : enable

layout(location = 0) out vec4 color;
in vec2 position;

uniform ivec2 windowSize;

// The symbols below will be auto-replaced
#id
#textures
#includes

void main()
{
    vec4 sphereData = sphere(position, vec2(0.5, 0.5), 0.2, vec2(windowSize));
    vec3 light = normalize(vec3(1, 1, 1));
    vec3 sphereColor = vec3(0.3, 0.3, 0.9);
    vec3 eye = vec3(0, 0, 1);
    vec4 factors = vec4(0, 0.6, 0, 16);
    color = vec4(sphereData.a * phong(sphereData.xyz, light, eye, factors) * sphereColor, 0);
}


#ifdef GL_ES
precision highp float;
#endif

varying vec2 v_texcoord0;
varying vec4 v_color;

uniform sampler2D u_texture0;

void main() {
    gl_FragColor = v_color * vec4(v_color.rgb, texture2D(u_texture0, v_texcoord0).a);
}

Remove erroneous squaring of fragment color in texture shader

#ifdef GL_ES
precision highp float;
#endif

varying vec2 v_texcoord0;
varying vec4 v_color;

uniform sampler2D u_texture0;

void main() {
    gl_FragColor = vec4(v_color.rgb, texture2D(u_texture0, v_texcoord0).a);
}


// Begin!
(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define('bic', [
            'feature!promises',
            'jquery',
            'underscore',
            'backbone',
            'mustache',
            'BlinkForms',
            'jquerymobile',
            'BMP.Blobs',
            'modernizr',
            'pouchdb',
            'pollUntil',
            'feature!es5',
            'BlinkGap'
        ], factory);
    } else {
        root.bic = factory();
    }
}(this, function (Promise, $, _, Backbone, Mustache, BlinkForms, jquerymobile, BMP, Modernizr, Pouch, pollUntil) {

Fix to get the BlinkGap helper library working with PollUntil

// Begin!
(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define('bic', [
            'feature!promises',
            'jquery',
            'underscore',
            'backbone',
            'mustache',
            'BlinkForms',
            'jquerymobile',
            'BMP.Blobs',
            'modernizr',
            'pouchdb',
            'pollUntil',
            'feature!es5',
            'BlinkGap'
        ], factory);
    } else {
        root.bic = factory();
    }
}(this, function (Promise, $, _, Backbone, Mustache, BlinkForms, jquerymobile, BMP, Modernizr, Pouch, pollUntil) {
  window.pollUntil = pollUntil;


attribute mediump vec2 aPosition;
varying highp vec2 vTexCoord;
uniform highp vec3 uSize;
uniform mediump float uDelta;
uniform mediump vec2 uTextureSize;
uniform mediump float uGap;
uniform mediump float uHorizontalAlign;
uniform mediump float uVerticalAlign;

uniform highp mat4 uMvpMatrix;

//Visual size and offset
uniform mediump vec2 offset;
uniform highp vec2 size;
uniform mediump vec4 offsetSizeMode;
uniform mediump vec2 origin;
uniform mediump vec2 anchorPoint;

void main()
{
  mediump vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
  mediump vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );

  vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + floor( aPosition.x * visualSize.x ) + 0.5 - uGap * 0.5 ) / uTextureSize.x + 0.5;
  vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + floor( aPosition.y * visualSize.y ) + 0.5 ) / ( uTextureSize.y ) + 0.5;

  mediump vec4 vertexPosition = vec4( floor( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy ), 0.0, 1.0 );

  gl_Position = uMvpMatrix * vertexPosition;
}

Fix visual defect during text scroll

attribute mediump vec2 aPosition;
varying highp vec2 vTexCoord;
uniform highp vec3 uSize;
uniform highp float uDelta;
uniform mediump vec2 uTextureSize;
uniform highp float uGap;
uniform mediump float uHorizontalAlign;
uniform mediump float uVerticalAlign;

uniform highp mat4 uMvpMatrix;

//Visual size and offset
uniform mediump vec2 offset;
uniform highp vec2 size;
uniform mediump vec4 offsetSizeMode;
uniform mediump vec2 origin;
uniform mediump vec2 anchorPoint;

void main()
{
  highp vec2 visualOffset = mix( offset, offset/uSize.xy, offsetSizeMode.xy );
  highp vec2 visualSize = mix( uSize.xy * size, size, offsetSizeMode.zw );

  vTexCoord.x = ( uDelta + uHorizontalAlign * ( uTextureSize.x - visualSize.x - uGap ) + aPosition.x * visualSize.x - uGap * 0.5 ) / uTextureSize.x + 0.5;
  vTexCoord.y = ( uVerticalAlign * ( uTextureSize.y - visualSize.y ) + aPosition.y * visualSize.y ) / ( uTextureSize.y ) + 0.5;

  highp vec4 vertexPosition = vec4( ( aPosition + anchorPoint ) * visualSize + ( visualOffset + origin ) * uSize.xy, 0.0, 1.0 );

  gl_Position = uMvpMatrix * vertexPosition;
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, Intel Corporation
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of
// the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * MegaMol
 * Copyright (c) 2021, MegaMol Dev Team
 * All rights reserved.
 */

vec3 LoadNormal( ivec2 pos, ivec2 offset )
{
    vec3 encodedNormal = texelFetchOffset(g_NormalmapSource, pos, 0, offset ).xyz;
    if(g_ASSAOConsts.TransformNormalsToViewSpace == 1) {
        encodedNormal = transpose(inverse(mat3(g_ASSAOConsts.ViewMX))) * (encodedNormal);
    }
    return normalize(encodedNormal);
}

Fix shader compiler error "offset needs to be a constant"

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2016, Intel Corporation
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of
// the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
 * MegaMol
 * Copyright (c) 2021, MegaMol Dev Team
 * All rights reserved.
 */

vec3 LoadNormal( ivec2 pos, ivec2 offset )
{
    vec3 encodedNormal = texelFetch(g_NormalmapSource, pos + offset, 0 ).xyz;
    if(g_ASSAOConsts.TransformNormalsToViewSpace == 1) {
        encodedNormal = transpose(inverse(mat3(g_ASSAOConsts.ViewMX))) * (encodedNormal);
    }
    return normalize(encodedNormal);
}


#version 440

in vec2 vertexTexCoord;

uniform sampler2D textureSampler;
uniform vec4 backgroundColor = vec4(0.8, 0.8, 0.8, 1);

out vec4 color;

vec4 blend(vec4 clr, vec4 srf)
{
  return clr + (1.0 - clr.w) * vec4(srf.xyz * srf.w, srf.w);
}

void main()
{
  color = blend(
      texture(textureSampler, vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y)),
      backgroundColor);
}

Use white background also in single layer renderings.

#version 440

in vec2 vertexTexCoord;

uniform sampler2D textureSampler;
uniform vec4 backgroundColor = vec4(1, 1, 1, 1);

out vec4 color;

vec4 blend(vec4 clr, vec4 srf)
{
  return clr + (1.0 - clr.w) * vec4(srf.xyz * srf.w, srf.w);
}

void main()
{
  color = blend(
      texture(textureSampler, vec2(vertexTexCoord.x, 1.0 - vertexTexCoord.y)),
      backgroundColor);
}


#version 330

in vec3 f_color;
in vec4 f_normal;
in vec2 f_uv;

layout(location = 0) out vec4 diffuse;
layout(location = 1) out vec4 normal;

void main(){
	diffuse = vec4(f_color, 1.f);
	//Scale the normal values from [-1,1] range to [0,1] range
	normal = ((f_normal - vec4(-1.f, -1.f, -1.f, 0.f) / 2.f));
}

Set normal alpha color to 1.f

#version 330

in vec3 f_color;
in vec4 f_normal;
in vec2 f_uv;

layout(location = 0) out vec4 diffuse;
layout(location = 1) out vec4 normal;

void main(){
	diffuse = vec4(f_color, 1.f);
	//Scale the normal values from [-1,1] range to [0,1] range
	normal = ((f_normal - vec4(-1.f, -1.f, -1.f, 0.f) / 2.f));
	normal.w = 1.f;
}


/**
 * @private
 */
float czm_alphaWeight(float z, float a)
{
    // See Weighted Blended Order-Independent Transparency for examples of different weighting functions:
    // http://jcgt.org/published/0002/02/09/
    return clamp(0.5 / 1e-5 + pow(abs(z) / 200.0, 6.0), 1e-2, 3e-3);
}

Change weight function yet again. This looks better with outlined geometry.

/**
 * @private
 */
float czm_alphaWeight(float z, float a)
{
    // See Weighted Blended Order-Independent Transparency for examples of different weighting functions:
    // http://jcgt.org/published/0002/02/09/
    return pow(a + 0.01, 4.0) + max(1e-2, min(3.0 * 1e3, 100.0 / (1e-5 + pow(abs(z) / 10.0, 3.0) + pow(abs(z) / 200.0, 6.0))));
}


#version 100
// Copyright 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ES 2 fragment shader that samples from a (non-external) texture with
// uTexSampler, copying from this texture to the current output
// while adjusting contrast based on uContrastFactor.

precision mediump float;
uniform sampler2D uTexSampler;
uniform float uContrastFactor;
varying vec2 vTexSamplingCoord;

void main() {
    vec4 inputColor = texture2D(uTexSampler, vTexSamplingCoord);

    gl_FragColor = vec4(
        clamp(uContrastFactor * (inputColor.r - 0.5) + 0.5, 0.0, 1.0),
        clamp(uContrastFactor * (inputColor.g - 0.5) + 0.5, 0.0, 1.0),
        clamp(uContrastFactor * (inputColor.b - 0.5) + 0.5, 0.0, 1.0),
        inputColor.a);
}

Remove clamp function in contrast fragment shader.

#version 100
// Copyright 2022 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// ES 2 fragment shader that samples from a (non-external) texture with
// uTexSampler, copying from this texture to the current output
// while adjusting contrast based on uContrastFactor.

precision mediump float;
uniform sampler2D uTexSampler;
uniform float uContrastFactor;
varying vec2 vTexSamplingCoord;

void main() {
    vec4 inputColor = texture2D(uTexSampler, vTexSamplingCoord);

    gl_FragColor = vec4(
        uContrastFactor * (inputColor.r - 0.5) + 0.5,
        uContrastFactor * (inputColor.g - 0.5) + 0.5,
        uContrastFactor * (inputColor.b - 0.5) + 0.5,
        inputColor.a);
}


#version 310 es
precision mediump float;

layout(location = 0) in highp vec2 vUV;

layout(location = 0) out vec3 Emissive;
layout(location = 1) out vec4 BaseColor;
layout(location = 2) out vec3 Normal;
layout(location = 3) out vec2 PBR;

layout(set = 2, binding = 0) uniform sampler2D uReflection;

layout(std430, push_constant) uniform Registers
{
    vec3 normal;
    vec3 tangent;
    vec3 bitangent;

    vec3 position;
    vec3 dPdx;
    vec3 dPdy;
} registers;

void main()
{
    Emissive = texture(uReflection, vUV).rgb;
    Normal = registers.normal * 0.5 + 0.5;
    BaseColor = vec4(0.02, 0.02, 0.02, 1.0);
    PBR = vec2(1.0, 1.0); // No diffuse, no specular, only reflection.
}

Use no albedo for water plane.

#version 310 es
precision mediump float;

layout(location = 0) in highp vec2 vUV;

layout(location = 0) out vec3 Emissive;
layout(location = 1) out vec4 BaseColor;
layout(location = 2) out vec3 Normal;
layout(location = 3) out vec2 PBR;

layout(set = 2, binding = 0) uniform sampler2D uReflection;

layout(std430, push_constant) uniform Registers
{
    vec3 normal;
    vec3 tangent;
    vec3 bitangent;

    vec3 position;
    vec3 dPdx;
    vec3 dPdy;
} registers;

void main()
{
    Emissive = texture(uReflection, vUV).rgb;
    Normal = registers.normal * 0.5 + 0.5;
    BaseColor = vec4(0.0, 0.0, 0.0, 1.0);
    PBR = vec2(0.0, 1.0); // No diffuse, no specular, only reflection.
}


varying float rel;
varying vec2 screen_coords;
uniform sampler2D hmap, tex;
uniform float ty_below;
uniform float line_thickness;
uniform vec2 screen_size;

void main() {
  float low, high;
  float value;
  float thickness;

  if (gl_TexCoord[0].t > 1)
    thickness = line_thickness;
  else
    thickness = max(1.0f, line_thickness/2.0f);

  high = texture2D(hmap, gl_TexCoord[0].st).r * 65536;
  low = texture2D(hmap, vec2(gl_TexCoord[0].s,
                             gl_TexCoord[0].t-ty_below)).r * 65536;

  if (high >= low &&
      screen_coords.y >= high &&
      screen_coords.y < high + thickness) {
    gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
  } else if (screen_coords.y < high || screen_coords.y >= low) {
    discard;
  } else {
    value = texture2D(tex,
                      vec2(screen_coords.x, screen_coords.y - high) *
                      4 / screen_size).r;
    if (rel + value*4 > 3.5)
      gl_FragColor = value * gl_SecondaryColor;
    else
      gl_FragColor = value * gl_Color;
  }
}

Fix hole in terrabuff when looking directly down.

varying float rel;
varying vec2 screen_coords;
uniform sampler2D hmap, tex;
uniform float ty_below;
uniform float line_thickness;
uniform vec2 screen_size;

void main() {
  float low, high;
  float value;
  float thickness;

  if (gl_TexCoord[0].t > 1)
    thickness = line_thickness;
  else
    thickness = max(1.0f, line_thickness/2.0f);

  high = texture2D(hmap, gl_TexCoord[0].st).r * 65536;
  if (gl_TexCoord[0].t > ty_below)
    low = texture2D(hmap, vec2(gl_TexCoord[0].s,
                               gl_TexCoord[0].t-ty_below)).r * 65536;
  else
    low = 65536;

  if (high >= low &&
      screen_coords.y >= high &&
      screen_coords.y < high + thickness) {
    gl_FragColor = vec4(0.05, 0.05, 0.05, 1.0);
  } else if (screen_coords.y < high || screen_coords.y >= low) {
    discard;
  } else {
    value = texture2D(tex,
                      vec2(screen_coords.x, screen_coords.y - high) *
                      4 / screen_size).r;
    if (rel + value*4 > 3.5)
      gl_FragColor = value * gl_SecondaryColor;
    else
      gl_FragColor = value * gl_Color;
  }
}


// Copyright 2014 Joshua R. Rodgers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

attribute vec3 a_vertexPosition;
attribute vec2 a_vertexUV;
attribute vec3 a_vertexNormal;

uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;

varying vec2 v_textureCoordinates;
varying float v_lightWeighting;

void main(void) {
	vec3 lightDirection = vec3(1, 1, 1);

	v_textureCoordinates = a_vertexUV;
	v_lightWeighting = 0.5 + max(dot(a_vertexNormal, lightDirection), 0.0) * 0.5;

    gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * vec4(a_vertexPosition, 1.0);
}

Normalize the light direction to reduce issues with the light being overly intense.

// Copyright 2014 Joshua R. Rodgers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//    http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

attribute vec3 a_vertexPosition;
attribute vec2 a_vertexUV;
attribute vec3 a_vertexNormal;

uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat4 u_projectionMatrix;

varying vec2 v_textureCoordinates;
varying float v_lightWeighting;

void main(void) {
	vec3 lightDirection = normalize(vec3(0, 1, 1));

	v_textureCoordinates = a_vertexUV;
	v_lightWeighting = 0.5 + max(dot(a_vertexNormal, lightDirection), 0.0) * 0.5;

    gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * vec4(a_vertexPosition, 1.0);
}


$(SAPI_PCONN_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
	$(BUILD_PCONN)

Add PCONN objects to build instruction

$(SAPI_PCONN_PATH): $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS) $(PHP_PCONN_OBJS)
	$(BUILD_PCONN)


precision mediump float;

uniform sampler2D textures[5];

varying vec4 vColour;
varying vec2 vTexturePos;
varying vec2 vTextureOffset;
varying float vLighting;
varying float vTextureSize;
varying float texture;

void main(void) {
    vec4 colour = vec4(0.0);
    vec2 pos = vTexturePos + fract(vTextureOffset) * vTextureSize;
    // I hate GLSL
    int tid = int(texture);
    if (tid == 0) {
        colour = texture2D(textures[0], pos);
    } else if (tid == 1) {
        colour = texture2D(textures[1], pos);
    } else if (tid == 2) {
        colour = texture2D(textures[2], pos);
    } else if (tid == 3) {
        colour = texture2D(textures[3], pos);
    } else if (tid == 1) {
        colour = texture2D(textures[4], pos);
    }
    colour *= vColour;
    colour.rgb *= vLighting;
    #ifndef alpha
        if (colour.a < 0.5) discard;
    #endif
    gl_FragColor = colour;
}

Fix typo in the fragment shader

precision mediump float;

uniform sampler2D textures[5];

varying vec4 vColour;
varying vec2 vTexturePos;
varying vec2 vTextureOffset;
varying float vLighting;
varying float vTextureSize;
varying float texture;

void main(void) {
    vec4 colour = vec4(0.0);
    vec2 pos = vTexturePos + fract(vTextureOffset) * vTextureSize;
    // I hate GLSL
    int tid = int(texture);
    if (tid == 0) {
        colour = texture2D(textures[0], pos);
    } else if (tid == 1) {
        colour = texture2D(textures[1], pos);
    } else if (tid == 2) {
        colour = texture2D(textures[2], pos);
    } else if (tid == 3) {
        colour = texture2D(textures[3], pos);
    } else if (tid == 4) {
        colour = texture2D(textures[4], pos);
    }
    colour *= vColour;
    colour.rgb *= vLighting;
    #ifndef alpha
        if (colour.a < 0.5) discard;
    #endif
    gl_FragColor = colour;
}


// The return value from here will be assigned to window.Livefyre

    var Livefyre = window.Livefyre || {};

    // We only have an async reference to the Livefyre.js object...
    // So define it here as something special
    Livefyre.require = function () {
        var args = arguments;
        var self = this;
        require(['Livefyre'], function (LivefyreJS) {
            LivefyreJS.require.apply(self, args);
        });
    };
    // and define
    Livefyre.define = define;

    Livefyre.require(['Livefyre'], function (LivefyreJS) {
        for (var key in LivefyreJS) {
            Livefyre[key] = LivefyreJS[key];
        }
    });
    return Livefyre;
}));

Build frag end exports all keys from LivefyreJS/main onto window.Livefyre

// The return value from here will be assigned to window.Livefyre

    var Livefyre = window.Livefyre || {};

    require(['Livefyre'], function (LivefyreJS) {
        for (var key in LivefyreJS) {
            Livefyre[key] = LivefyreJS[key];
        }
    });

    // We only have an async reference to the Livefyre.js object...
    // So define it here as something special
    Livefyre.require = function () {
        var args = arguments;
        var self = this;
        require(['Livefyre'], function (LivefyreJS) {
            LivefyreJS.require.apply(self, args);
        });
    };
    // and define
    Livefyre.define = define;

    return Livefyre;
}));


float brightness() {
  return 0.0;
}

//Do not change this line
#pragma glslify: export(brightness)

Fix shader file in 00-intro-0

float brightness() {
  return -1.0;
}

//Do not change this line
#pragma glslify: export(brightness)


#version 330

// Input: UV coordinates
in INTERFACE {
	vec2 uv;
} In ;

// Uniforms: the texture, inverse of the screen size, FXAA flag.
uniform sampler2D screenTexture;
uniform vec2 inverseScreenSize;
uniform bool useFXAA;

// Output: the fragment color
out vec3 fragColor;

void main(){

	vec3 colorCenter = texture(screenTexture,In.uv).rgb;

	// If AA disabled, return directly the fragment color.
	if(!useFXAA){
		fragColor = colorCenter;
		return;
	}

	// Display a small green square in the bottom-left corner if AA is enabled.
	if(max(gl_FragCoord.x, gl_FragCoord.y) < 20){
		fragColor = vec3(0.2,0.8,0.4);
		return;
	}

	fragColor = colorCenter;
}

Add a function to compute perceptual luma.

#version 330

// Input: UV coordinates
in INTERFACE {
	vec2 uv;
} In ;

// Uniforms: the texture, inverse of the screen size, FXAA flag.
uniform sampler2D screenTexture;
uniform vec2 inverseScreenSize;
uniform bool useFXAA;

// Output: the fragment color
out vec3 fragColor;

// Return the luma value in perceptual space for a given RGB color in linear space.
float rgb2luma(vec3 rgb){
	return sqrt(dot(rgb, vec3(0.299, 0.587, 0.114)));
}

void main(){

	vec3 colorCenter = texture(screenTexture,In.uv).rgb;

	// If AA disabled, return directly the fragment color.
	if(!useFXAA){
		fragColor = colorCenter;
		return;
	}

	// Display a small green square in the bottom-left corner if AA is enabled.
	if(max(gl_FragCoord.x, gl_FragCoord.y) < 20){
		fragColor = vec3(0.2,0.8,0.4);
		return;
	}

	// Luma at the current fragment
	float lumaCenter = rgb2luma(colorCenter);

	fragColor = vec3(lumaCenter);

}


/*
Text rendering - Vertex Shader
*/
#version 400
layout(location = 0) in vec2 vertexPosition;
layout(location = 1) in vec2 vertexTexture;

uniform vec2 position;
uniform vec2 size;

uniform vec2 uv1;
uniform vec2 uv2;

out VertexData {
	vec2 texCoords;
} vertexOut;

void main () {
	//vertexOut.tex_coords = vertex_position;
	vertexOut.texCoords.x = uv1.x + vertexTexture.x * (uv2.x - uv1.x);
	vertexOut.texCoords.y = uv1.y + vertexTexture.y * (uv2.y - uv1.y);

    vec2 pos = (vertexPosition + vec2(1.0, 1.0)) / 2.0;
	pos = position + size * pos;
	pos = 2.0 * pos - vec2(1.0, 1.0);
	pos.y = -pos.y;

	gl_Position = vec4(pos, 0.0, 1.0);
}

Fix font rendering winding order.

/*
Text rendering - Vertex Shader
*/
#version 400
layout(location = 0) in vec2 vertexPosition;
layout(location = 1) in vec2 vertexTexture;

uniform vec2 position;
uniform vec2 size;

uniform vec2 uv1;
uniform vec2 uv2;

out VertexData {
    vec2 texCoords;
} vertexOut;

void main () {
    vertexOut.texCoords.x = uv1.x + vertexTexture.x * (uv2.x - uv1.x);
    vertexOut.texCoords.y = uv2.y + vertexTexture.y * (uv1.y - uv2.y);

    vec2 pos = (vertexPosition + vec2(1.0, 1.0)) * 0.5;
    vec2 bottomLeft = vec2(2.0 * position.x - 1.0, 1.0 - 2.0 * (position.y + size.y));
    pos = bottomLeft + 2.0 * size * pos;

    gl_Position = vec4(pos, 0.0, 1.0);
}


#pragma glslify: applyMaterial = require(./chunks/applyMaterial)
#pragma glslify: applyLight = require(./chunks/applyLight)

void main() {
    vec3 material = baseColor.r >= 0.0 ? baseColor : applyMaterial(baseColor);

    bool flatShading = u_FlatShading > 0.0;
    bool lights = length(u_LightColor) > 0.0;
    vec3 color = lights && !flatShading ? applyLight(material) : material;

    bool ambianceEnabled = length(u_AmbientLight) > 0.0;
    vec3 ambience = u_AmbientLight * material;
    vec3 finalColor = ambianceEnabled && !flatShading ? ambience + color : color;

    gl_FragColor = vec4(finalColor, opacity);
}

Update ambient to account for flat shading

#pragma glslify: applyMaterial = require(./chunks/applyMaterial)
#pragma glslify: applyLight = require(./chunks/applyLight)

void main() {
    vec3 material = baseColor.r >= 0.0 ? baseColor : applyMaterial(baseColor);

    bool flatShading = u_FlatShading > 0.0;
    bool lights = length(u_LightColor) > 0.0;
    vec3 color = lights && !flatShading ? applyLight(material) : material;

    bool ambience = length(u_AmbientLight) > 0.0;
    vec3 ambientLight = u_AmbientLight * material;
    vec3 finalColor = ambience && !flatShading ? ambientLight + color : color;

    gl_FragColor = vec4(finalColor, opacity);
}


/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

attribute vec4 position;
void main() {
   gl_Position = position;
};

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Remove the extra colon at the end of shader

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

attribute vec4 position;
void main() {
   gl_Position = position;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


#version 120

uniform vec4 u_lightType;

varying vec4 lightVec;

void main()
{
	vec4 lp;
	//lp = lightPosition;
	//lp = vec4(0.0,0.0,0.0,1.0);

	vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;
	if(u_lightType == 0)
		lightVec = vec4(0.0, 0.0, ecPos.z, 0.0);//vec4(ecPos.xyz - vec3(ecPos.xy,0.0), 0.0);
	else //	if(u_lightType == 2)
		lightVec = ecPos;

	gl_Position = ftransform();
}

Fix compilation (in generateDepth shader)

#version 120

uniform int u_lightType;

varying vec4 lightVec;

void main()
{
	vec4 lp;
	//lp = lightPosition;
	//lp = vec4(0.0,0.0,0.0,1.0);

	vec4 ecPos = gl_ModelViewMatrix * gl_Vertex;
	if(u_lightType == 0)
		lightVec = vec4(0.0, 0.0, ecPos.z, 0.0);//vec4(ecPos.xyz - vec3(ecPos.xy,0.0), 0.0);
	else //	if(u_lightType == 2)
		lightVec = ecPos;

	gl_Position = ftransform();
}


/**
 * @file impostorF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

uniform sampler2D diffuseMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;

void main()
{
	gl_FragData[0] = texture2D(diffuseMap, gl_TexCoord[0].xy);
	gl_FragData[1] = texture2D(specularMap, gl_TexCoord[0].xy);
	gl_FragData[2] = vec4(texture2D(normalMap, gl_TexCoord[0].xy).xyz, 0.0);
}

Fix for impostors being fullbright when deferred rendering enabled.

/**
 * @file impostorF.glsl
 *
 * Copyright (c) 2007-$CurrentYear$, Linden Research, Inc.
 * $License$
 */

uniform sampler2D diffuseMap;
uniform sampler2D normalMap;
uniform sampler2D specularMap;

void main()
{
	vec4 col = texture2D(diffuseMap, gl_TexCoord[0].xy);
	gl_FragData[0] = vec4(col.rgb, col.a <= 0.5 ? 0.0 : 0.005);
	gl_FragData[1] = texture2D(specularMap, gl_TexCoord[0].xy);
	gl_FragData[2] = vec4(texture2D(normalMap, gl_TexCoord[0].xy).xyz, 0.0);
}


#version 150

uniform vec2 c;
in vec2 fragment_z;
out vec4 color;

// Complex multiplication.
vec2 cmul(vec2 a, vec2 b) {
    return vec2(a[0] * b[0] - a[1] * b[1],
                a[0] * b[1] + a[1] * b[0]);
}

// Complex reciprocal.
vec2 cinv(vec2 a) {
    float norm = dot(a, a);
    return vec2(a[0] / norm, -a[1] / norm);
}

void main() {
    vec2 z = cinv(fragment_z);
    int it = 0;
    const int limit = 100;
    for (it = 0; it < limit; it++) {
        z = cmul(z, z) + c;
        if (dot(z, z) > 4.0)
            break;
    }

    // Map the iteration count to value between 0 and 1.
    float gray;
    if (it >= limit) {
        gray = 1.0;
    } else {
        gray = float(it) / float(limit);
    }

    // Brighten things up a bit: invert, cube to push it towards zero,
    // and revert.
    gray = 1.0 - gray;
    gray = gray * gray * gray;

    color = vec4(gray, gray, gray, 1.0);
}

Revert to a plain Julia set, not reciprocal.

#version 150

uniform vec2 c;
in vec2 fragment_z;
out vec4 color;

// Complex multiplication.
vec2 cmul(vec2 a, vec2 b) {
    return vec2(a[0] * b[0] - a[1] * b[1],
                a[0] * b[1] + a[1] * b[0]);
}

void main() {
    vec2 z = fragment_z;
    int it = 0;
    const int limit = 100;
    for (it = 0; it < limit; it++) {
        z = cmul(z, z) + c;
        if (dot(z, z) > 4.0)
            break;
    }

    // Map the iteration count to value between 0 and 1.
    float gray;
    if (it >= limit) {
        gray = 1.0;
    } else {
        gray = float(it) / float(limit);
    }

    // Brighten things up a bit: invert, cube to push it towards zero,
    // and revert.
    gray = 1.0 - gray;
    gray = gray * gray * gray;

    color = vec4(gray, gray, gray, 1.0);
}


/**
 * Calculates the intensity of light on a surface.
 *
 * @method transpose
 * @private
 *
 *
 */

vec3 applyLight(in vec3 material) {
    int numLights = int(u_NumLights);
    float lambertianTerm;
    vec3 finalColor = vec3(0.0);
    vec3 normal = normalize(v_Normal);
    vec3 ambientLight = u_AmbientLight * material;
    vec3 eyeVector = vec3(-v_Position);
    vec3 diffuse, specular, lightDirection;

    for(int i = 0; i < 4; i++) {
        if (i >= numLights) break;
        diffuse = vec3(0.0, 0.0, 0.0);
        specular = vec3(0.0, 0.0, 0.0);
        lightDirection = normalize(u_LightPosition[i].xyz - v_Position);
        lambertianTerm = dot(lightDirection, normal);
        if (lambertianTerm > 0.0 && glossiness > 0.0) {
            diffuse = material * lambertianTerm;
            vec3 E = normalize(eyeVector);
            vec3 R = reflect(lightDirection, normal);
            float specularWeight = pow(max(dot(R, E), 0.0), glossiness);
            specular = u_LightColor[i].rgb * specularWeight;
            finalColor += diffuse + specular;
        }
        else {
            lambertianTerm = max(lambertianTerm, 0.0);
            finalColor += u_LightColor[i].rgb * material * lambertianTerm;
        }
    }

    return ambientLight + finalColor;
}

#pragma glslify: export(applyLight)

Update lighting model to a faster reflection model

/**
 * Calculates the intensity of light on a surface.
 *
 * @method applyLight
 * @private
 *
 */
vec3 applyLight(in vec3 material) {
    int numLights = int(u_NumLights);
    vec3 ambientColor = u_AmbientLight * material;
    vec3 normal = normalize(v_Normal);
    vec3 center = resolution * 0.5;
    vec3 eyeVector = normalize(center - v_Position);
    vec3 specular = vec3(0.0);
    vec3 finalColor = vec3(0.0);

    for(int i = 0; i < 4; i++) {
        if (i >= numLights) break;
        vec3 lightDirection = normalize(u_LightPosition[i].xyz - v_Position);
        float lambertian = max(dot(lightDirection, normal), 0.0);
        vec3 diffuse = u_LightColor[i].rgb * material;

        if (lambertian > 0.0) {
            vec3 halfVector = normalize(lightDirection + eyeVector);
            float specularAngle = max(dot(halfVector, normal), 0.0);
            specular = u_LightColor[i].rgb * pow(specularAngle, glossiness * 10.0);
            if (glossiness > 0.0) finalColor += specular;
        }

        finalColor += lambertian * diffuse;
    }

    return ambientColor + finalColor;
}

#pragma glslify: export(applyLight)