topical media & game development

talk show tell print

graphic-webgl-scenejs-examples-tron-tank-sky-sphere.js / js



  var skySphereJSON = {
  
   type: "shader",
  
   shaders: [
  
    /* Vertex shader with our custom function to intercept the matrix
     */
    {
     stage: "vertex",
     code: [
  
      "mat4 myViewMatrix(mat4 m) {",
      " m[3][0] =m[3][1] = m[3][2] = 0.0;" +
      " return m; ",
      "}"
     ],
  
     hooks: {
      viewMatrix: "myViewMatrix" // Bind our custom function to hook
     }
    },
  
    {
     stage: "fragment",
     code: [
      "vec4 savedWorldPos;",
  
      "vec4 getWorldPos(vec4 pos) {",
      " savedWorldPos = pos;" +
      " return pos; ",
      "}",
  
      "vec4 tweakPixelColor(vec4 color) {",
      " color.rgb -= ((savedWorldPos.y-1.5) * 0.01);",
      " return color; ",
      "}"
     ],
  
     hooks: {
      worldPos: "getWorldPos",
      pixelColor: "tweakPixelColor"
     }
    }
   ],
  
   nodes: [
    {
     type: "scale",
  
     x: 1000,
     y: 1000,
     z: 1000,
  
     nodes: [
      {
       type: "material",
  
       baseColor: { r: .7, g: .7, b: 1.0 },
       emit: 0.3,
  
       nodes: [
        {
         type: "sphere"
        }
       ]
      }
     ]
    }
   ]
  };
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.