Variables
Const castRay
castRay: "bool castRay( const vec3 & ro, const vec3 & rd, float & resT ){const float delt = 0.01f;const float mint = 0.001f;const float maxt = 10.0f;for( float t = mint; t < maxt; t += delt ){const vec3 p = ro + rd*t;if( p.y < f( p.x, p.z ) ){resT = t - 0.5f*delt;return true;}}return false;}" = `bool castRay( const vec3 & ro, const vec3 & rd, float & resT ){const float delt = 0.01f;const float mint = 0.001f;const float maxt = 10.0f;for( float t = mint; t < maxt; t += delt ){const vec3 p = ro + rd*t;if( p.y < f( p.x, p.z ) ){resT = t - 0.5f*delt;return true;}}return false;}`
Const defaultVertexShader
defaultVertexShader: "varying vec2 v_uv;varying vec3 v_position;void main() {v_position = position;v_uv = uv;gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );}" = `varying vec2 v_uv;varying vec3 v_position;void main() {v_position = position;v_uv = uv;gl_Position = projectionMatrix * viewMatrix * modelMatrix * vec4( position, 1.0 );}`
Const deguGet2dRotationMatrix
deguGet2dRotationMatrix: "mat2 deguGet2dRotationMatrix(float theta) {float s = sin(theta);float c = cos(theta);return mat2(c, -s, s, c);}" = `mat2 deguGet2dRotationMatrix(float theta) {float s = sin(theta);float c = cos(theta);return mat2(c, -s, s, c);}`
Const deguGet2dScaleMatrix
deguGet2dScaleMatrix: "mat2 deguGetScaleMatrix(float scale) {return mat2(scale, 0, 0, scale);}" = `mat2 deguGetScaleMatrix(float scale) {return mat2(scale, 0, 0, scale);}`
Const deguRotate2d
deguRotate2d: "vec2 deguRotate2d(vec2 pt, float theta) {mat2 rotationMatrix = deguGet2dRotationMatrix(theta);return rotationMatrix * pt;}" = `vec2 deguRotate2d(vec2 pt, float theta) {mat2 rotationMatrix = deguGet2dRotationMatrix(theta);return rotationMatrix * pt;}`
Const deguRotate2dImage
deguRotate2dImage: "vec3 deguRotate2dImage(sampler2D texture, float aspect, vec2 uv, vec2 center, float theta, vec3 backgroundColor) {// Adjust for the center point.uv -= center;mat2 rotationMatrix = deguGet2dRotationMatrix(theta);// Go to square uv coordinates.uv.y /= aspect;// Conduct rotation.uv = rotationMatrix * uv;// Go back to whatever the aspect was.uv.y *= aspect;// Adjust back for the center point.uv += center;vec3 texel = texture2D(texture, uv).rgb;// Determine if this point is within the bounds of the rectangle.// If not, use the background color.vec2 s = step(vec2(0.0), uv) - step(vec2(1.0), uv);float t = s.x * s.y;vec3 color = mix(backgroundColor, texel, t);return color;}" = `vec3 deguRotate2dImage(sampler2D texture, float aspect, vec2 uv, vec2 center, float theta, vec3 backgroundColor) {// Adjust for the center point.uv -= center;mat2 rotationMatrix = deguGet2dRotationMatrix(theta);// Go to square uv coordinates.uv.y /= aspect;// Conduct rotation.uv = rotationMatrix * uv;// Go back to whatever the aspect was.uv.y *= aspect;// Adjust back for the center point.uv += center;vec3 texel = texture2D(texture, uv).rgb;// Determine if this point is within the bounds of the rectangle.// If not, use the background color.vec2 s = step(vec2(0.0), uv) - step(vec2(1.0), uv);float t = s.x * s.y;vec3 color = mix(backgroundColor, texel, t);return color;}`
Const deguShape2dCheckerboard
deguShape2dCheckerboard: "float deguShape2dCheckerBoard(vec2 p, float xCount, float yCount) {float x = floor(p.x * xCount);float y = floor(p.y * yCount);return mod(x + y, 2.0);}" = `float deguShape2dCheckerBoard(vec2 p, float xCount, float yCount) {float x = floor(p.x * xCount);float y = floor(p.y * yCount);return mod(x + y, 2.0);}`
Const fragChromaKey
fragChromaKey: "varying vec2 vTextureCoord;uniform sampler2D uSampler;uniform vec3 color;uniform float epsilon;void main() {vec4 currentColor = texture2D(uSampler, vTextureCoord);vec3 colorDiff = color - (currentColor.rgb / max(currentColor.a, 0.0000000001));float colorDistance = length(colorDiff);if(colorDistance < epsilon) {gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);} else {gl_FragColor = texture2D(uSampler, vTextureCoord);};}" = `varying vec2 vTextureCoord;uniform sampler2D uSampler;uniform vec3 color;uniform float epsilon;void main() {vec4 currentColor = texture2D(uSampler, vTextureCoord);vec3 colorDiff = color - (currentColor.rgb / max(currentColor.a, 0.0000000001));float colorDistance = length(colorDiff);if(colorDistance < epsilon) {gl_FragColor = vec4(0.0, 0.0, 0.0, 0.0);} else {gl_FragColor = texture2D(uSampler, vTextureCoord);};}`
Const fragDefault
fragDefault: "varying vec2 vTextureCoord;uniform sampler2D uSampler;void main() {gl_FragColor = texture2D(uSampler, vTextureCoord);}" = `varying vec2 vTextureCoord;uniform sampler2D uSampler;void main() {gl_FragColor = texture2D(uSampler, vTextureCoord);}`
Const normalizedSin
normalizedSin: "float normalizedSin(float radians) {return (sin(radians) + 1.0) / 2.0;}" = `float normalizedSin(float radians) {return (sin(radians) + 1.0) / 2.0;}`