{
  "shaderbuilder": {
    "templates": {
      "vertex": "//\n// surfacecurve-shaderbuilder generated vertex shader\n//\n//\nprecision mediump float;\n\nuniform mat4 unifModelMatrix;       // object -> world coordinates\nuniform mat4 unifViewMatrix;        // world -> view coordinates\nuniform mat4 unifProjMatrix;        // view -> eye coordinates\nuniform mat3 unifNormalMatrix;      // object -> world vectors\n\nattribute vec3 vertPosition;\nattribute vec3 vertNormal;\n\nvarying vec3 fragPositionWc;\nvarying vec3 fragPositionOc;\nvarying vec4 fragPositionEc;\nvarying vec3 fragNormalEc;\n\nvoid main () \n{\n    fragPositionOc = vertPosition;\n    vec4 positionWc = unifModelMatrix * vec4(vertPosition, 1.0);     \n    fragPositionWc = positionWc.xyz;\n    fragPositionEc = unifProjMatrix * unifViewMatrix * positionWc;\n    \n    fragNormalEc = normalize(unifNormalMatrix * vertNormal);\n    \n    gl_Position = fragPositionEc;\n}\n    ",
      "fragment": "// Generated fragment shader\n//\n// Compiler        : <%= builder.name %> <%= builder.version %>\n// Graph Unique ID : <not yet implemented>\n// \n\nprecision mediump float;\n\n//\n// Uniforms\n//\nuniform mat3 unifNormalMatrix;\n \nREM <% _.each(uniforms, function(uniform, name) { with(uniform) { %>\nuniform <%= type %> <%= name %>; // = <%= uniform.default %>\nREM <% }}); %>\n\n\n//\n// Fragment shader inputs\n//\nvarying vec3 fragPositionWc;\nvarying vec3 fragPositionOc;\nvarying vec4 fragPositionEc;\nvarying vec3 fragNormalEc;\n\n//\n// Shader constants\n//\nREM <% _.each(constants, function(constant, name) { with(constant) { %>\n<%= type %> <%= name %> = <%= value %>;\nREM <% }}); %>\n\n//\n// Built-ins\n//\nvec2 trunc(vec2 v)\n{\n    return v - fract(v);\n}\n\n// \n// Graph node functions\n//\nREM <% _.each(functions, function(func, name) { with(func) { %>\n\n<%= type %> <%= name %> (<%= paramList %>) \n{\n<%= code %>\n}\nREM <% }}); %>\n\n\n//\n// Fragment shader entry-point\n//\nvoid main()\n{\n    // Statements\nREM <% _.each(statements, function (statement) { %>\n    <%= statement %>;\nREM <% }); %>\n\n    // Graph output\n    gl_FragColor = n0_value;\n}\n"
    },
    "nodes": {
      "diffuse": "{\n    output : \"vec4\",\n    input  : {\n        color : [ \"vec3\",   [ .5, .5, .5 ],     \"color\" ],\n    },\n}\n<source>\n    vec3 N = fragNormalEc;\n    vec3 L = normalize(unifNormalMatrix * vec3(1, 1, 2));\n    \n    vec3 c = color * max(dot(N,L), 0.2);\n    return vec4(c.x, c.y, c.z, 1);\n</source>\n",
      "gooch": "{\n    output : \"vec4\",\n    input  : {\n        warm : [ \"vec3\",   [ .8, .5, .2 ],     \"color\" ],\n        cool : [ \"vec3\",   [ .1, .1, .4 ],     \"color\" ],\n    },\n}\n<source>\n    vec3 N = normalize(fragNormalEc);\n    vec3 L = normalize(unifNormalMatrix * normalize(vec3(-.5, 1, -1.7)));\n    vec3 V = fragPositionEc.xyz;\n    vec3 H = normalize(L+V);\n    \n    float diffuse = max(dot(N,L), 0.0);\n    float specular = pow(max(dot(N,H), 0.0), 128.0);\n\n    vec3 color = mix(warm, cool, diffuse) + specular * vec3(1,1,.9);\n\n    return vec4(color, 1.0);\n</source>\n",
      "solid": "{\n    output : \"vec4\",\n    input  : {\n        color : [ \"vec3\",   [ .5, .5, .5 ],     \"color\" ],\n    },\n}\n<source>\n    return vec4(color.x, color.y, color.z, 1);\n</source>\n",
      "checker": "{\n    output : \"vec3\",\n    input  : {\n        color0 : [ \"vec3\",   [ 1, 1, 1 ],           \"color\" ],\n        color1 : [ \"vec3\",   [ 0, 0, 0 ],           \"color\" ],\n        uv     : [ \"vec2\",   { spherical : {} },    \"mapper\" ],\n    }\n}\n<source>            \n    vec2 t = abs( fract(uv) );\n    vec2 s = trunc(2.0 * t);\n      \n    float c = mod(s.x + s.y, 2.0);\n    if (c < 1.0)\n        return color0;\n    else\n        return color1;        \n</source>",
      "weave": "{\n    output : \"vec3\",\n    input  : {\n        color0 : [ \"vec3\",   [ 1, 1, 1 ],           \"color\" ],\n        color1 : [ \"vec3\",   [ 0, 0, 0 ],           \"color\" ],\n        uv     : [ \"vec2\",   { spherical : {} },    \"mapper\" ],\n    },\n}\n<source>\n    //\n    // Compute the the distance from the center of the tile\n    // as well as the x,y of the tile itself.\n    //\n    vec2  f = abs(.5 - fract(uv));\n    ivec2 i = ivec2(trunc(uv));\n\n    //\n    // Use the distance from the center to determine the\n    // color strength at that point.\n    //\n    vec2 d = .5 + .5 * pow(cos(PI * f), vec2(.75, .75));\n\n    //\n    // Now look at the tile index and swap which color strip\n    // goes 'on top' every other tile.\n    //\n    //if ((i.x + i.y) % 2 == 0)\n    if (mod(float(i.x) + float(i.y), 2.0) <= 0.0)\n    {\n        f.xy = f.yx;\n        d.xy = d.yx;\n    }\n\n    // Invert the gradiation of the bottom strip\n    d.x = 1.0 - d.x;\n\n    if (f.x < .4)\n        return mix(color1, color0, d.y);\n    else if (f.y < .4)\n        return mix(color1, color0, d.x);\n    return\n        color1;\n</source>\n",
      "planar_xy": "{\n    output : \"vec2\",\n    input  : {\n        scale  : [ \"vec2\",   [ 1, 1 ],     \"scale\" ],\n    }\n}\n<source>        \n    return scale * fragPositionWc.xy;\n</source>",
      "spherical": "{\n    output : \"vec2\",\n    input  : {\n        scale  : [ \"vec2\",   [ 1, 1 ],     \"scale\" ],\n    }\n}\n<source>        \n    // Hard-coded while in development\n    vec3 position = fragPositionOc;\n\n    // Convert to spherical coordinates.  Note in this definition\n    // theta runs along the z axis and phi is in the xy plane.\n    float r = length(position);\n    float phi = atan(position.y, position.x);\n    float theta = acos(position.z / r);\n\n    // Normalize to [0-1) range\n    vec2 uv = vec2(1.0, 1.0);\n    uv.x = (phi + PI) / (2.0 * PI);\n    uv.y = theta / PI;\n    return scale * uv;\n</source>"
    },
    "materials": {
      "checker-nested": "{\n    diffuse : {\n        color : { \n            checker : {\n                uv     : { spherical : { scale : [4, 4] } },\n                color0 : {\n                    checker : {\n                        uv     : { spherical : { scale : [8, 8] } },\n                        color0 : {\n                            checker : {\n                                uv     : { spherical : { scale : [32, 32] } },\n                                color0 : [ 1.0, 1.0, 0.9 ],\n                                color1 : [ .25, .55, 1.0 ]\n                            }\n                        },\n                        color1 : [ 0.98, 0.98, 0.92 ]\n                    }\n                },\n                color1 : {\n                    checker : {\n                        uv     : { spherical : { scale : [16, 16] } },\n                        color0 : [ 0.9, 0.9, 0.93 ],\n                        color1 : {\n                            checker : {\n                                uv     : { spherical : { scale : [32, 32] } },\n                                color0 : [ 0.95, 0.25, 0.25 ],\n                                color1 : [ 1.0, 1.0, 1.0 ]\n                            }\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n",
      "checker-redblack": "{\n    diffuse : {\n        color : { \n            checker : {\n                uv     : { spherical : { scale : [4, 4] } },\n                color0 : [ .8, .1, .1 ],\n                color1 : [ .1, .1, .1 ]\n            }\n        }\n    }\n}\n",
      "checker-simple": "{\n    diffuse : {\n        color : { \n            checker : {\n                uv     : { spherical : { scale : [4, 4] } },\n                color0 : [ 0, 0, 1 ],\n                color1 : [ 1, 1, 1 ]\n            }\n        }\n    }\n}\n",
      "checker-worldxy": "{\n    diffuse : {\n        color : { \n            checker : {\n                uv     : { planar_xy : { scale : [4, 4] } },\n                color0 : [ 0, 0, 1 ],\n                color1 : [ 1, 1, 1 ]\n            }\n        }\n    }\n}\n",
      "gooch": "{\n    gooch : { \n        warm : [ 1.0, .55, .4],\n        cool : [ .15, .05, .4 ],\n    }\n}\n",
      "solid-blue": "{\n    solid : { color : [ 0, 0, 1 ] }\n}\n",
      "solid-green": "{\n    solid : { color : [ .4, .65, .5 ] }\n}\n",
      "solid-red": "{\n    solid : { color : [ 1, 0, 0 ] }\n}\n",
      "weave-simple": "{\n    diffuse : {\n        color : { \n            weave : {\n                uv     : { spherical : { scale : [32, 32] } },\n                color0 : [ 1, 1, .97 ],\n                color1 : [ 0.24, 0.2, 0.2 ]\n            }\n        }\n    }\n}\n"
    }
  }
}