dojox/gfx3d/lighting.js

  • Provides:

    • dojox.gfx3d.lighting
  • Requires:

    • dojox.gfx._base in common
  • dojox.gfx3d.lighting.Model

    • type
      Function
    • parameters:
      • incident: (typeof )
      • lights: (typeof )
      • ambient: (typeof )
      • specular: (typeof )
    • source: [view]
         this.incident = lite.normalize(incident);
         this.lights = [];
         for(var i = 0; i < lights.length; ++i){
          var l = lights[i];
          this.lights.push({direction: lite.normalize(l.direction), color: lite.toStdColor(l.color)});
         }
         this.ambient = lite.toStdColor(ambient.color ? ambient.color : "white");
         this.ambient = lite.scaleColor(ambient.intensity, this.ambient);
         this.ambient = lite.scaleColor(this.ambient.a, this.ambient);
         this.ambient.a = 1;
         this.specular = lite.toStdColor(specular ? specular : "white");
         this.specular = lite.scaleColor(this.specular.a, this.specular);
         this.specular.a = 1;
         this.npr_cool = {r: 0, g: 0, b: 0.4, a: 1};
         this.npr_warm = {r: 0.4, g: 0.4, b: 0.2, a: 1};
         this.npr_alpha = 0.2;
         this.npr_beta = 0.6;
         this.npr_scale = 0.6;
    • summary
  • dojox.gfx3d.lighting.Model.constant

    • type
      Function
    • parameters:
      • normal: (typeof )
      • finish: (typeof )
      • pigment: (typeof )
    • source: [view]
         pigment = lite.toStdColor(pigment);
         var alpha = pigment.a, color = lite.scaleColor(alpha, pigment);
         color.a = alpha;
         return lite.fromStdColor(lite.saturateColor(color));
    • summary
  • dojox.gfx3d.lighting.Model.matte

    • type
      Function
    • parameters:
      • normal: (typeof )
      • finish: (typeof )
      • pigment: (typeof )
    • source: [view]
         if(typeof finish == "string"){ finish = lite.finish[finish]; }
         pigment = lite.toStdColor(pigment);
         normal = lite.faceforward(lite.normalize(normal), this.incident);
         var ambient = lite.scaleColor(finish.Ka, this.ambient),
          shadow = lite.saturate(-4 * lite.dot(normal, this.incident)),
          diffuse = lite.scaleColor(shadow * finish.Kd, lite.diffuse(normal, this.lights)),
          color = lite.scaleColor(pigment.a, lite.multiplyColor(pigment, lite.addColor(ambient, diffuse)));
         color.a = pigment.a;
         return lite.fromStdColor(lite.saturateColor(color));
    • summary
  • dojox.gfx3d.lighting.Model.metal

    • type
      Function
    • parameters:
      • normal: (typeof )
      • finish: (typeof )
      • pigment: (typeof )
    • source: [view]
         if(typeof finish == "string"){ finish = lite.finish[finish]; }
         pigment = lite.toStdColor(pigment);
         normal = lite.faceforward(lite.normalize(normal), this.incident);
         var v = lite.scale(-1, this.incident), specular, color,
          ambient = lite.scaleColor(finish.Ka, this.ambient),
          shadow = lite.saturate(-4 * lite.dot(normal, this.incident));
         if("phong" in finish){
          specular = lite.scaleColor(shadow * finish.Ks * finish.phong, lite.phong(normal, v, finish.phong_size, this.lights));
         }else{
          specular = lite.scaleColor(shadow * finish.Ks, lite.specular(normal, v, finish.roughness, this.lights));
         }
         color = lite.scaleColor(pigment.a, lite.addColor(lite.multiplyColor(pigment, ambient), lite.multiplyColor(this.specular, specular)));
         color.a = pigment.a;
         return lite.fromStdColor(lite.saturateColor(color));
    • summary
  • dojox.gfx3d.lighting.Model.plastic

    • type
      Function
    • parameters:
      • normal: (typeof )
      • finish: (typeof )
      • pigment: (typeof )
    • source: [view]
         if(typeof finish == "string"){ finish = lite.finish[finish]; }
         pigment = lite.toStdColor(pigment);
         normal = lite.faceforward(lite.normalize(normal), this.incident);
         var v = lite.scale(-1, this.incident), specular, color,
          ambient = lite.scaleColor(finish.Ka, this.ambient),
          shadow = lite.saturate(-4 * lite.dot(normal, this.incident)),
          diffuse = lite.scaleColor(shadow * finish.Kd, lite.diffuse(normal, this.lights));
         if("phong" in finish){
          specular = lite.scaleColor(shadow * finish.Ks * finish.phong, lite.phong(normal, v, finish.phong_size, this.lights));
         }else{
          specular = lite.scaleColor(shadow * finish.Ks, lite.specular(normal, v, finish.roughness, this.lights));
         }
         color = lite.scaleColor(pigment.a, lite.addColor(lite.multiplyColor(pigment, lite.addColor(ambient, diffuse)), lite.multiplyColor(this.specular, specular)));
         color.a = pigment.a;
         return lite.fromStdColor(lite.saturateColor(color));
    • summary
  • dojox.gfx3d.lighting.Model.npr

    • type
      Function
    • parameters:
      • normal: (typeof )
      • finish: (typeof )
      • pigment: (typeof )
    • source: [view]
         if(typeof finish == "string"){ finish = lite.finish[finish]; }
         pigment = lite.toStdColor(pigment);
         normal = lite.faceforward(lite.normalize(normal), this.incident);
         var ambient = lite.scaleColor(finish.Ka, this.ambient),
          shadow = lite.saturate(-4 * lite.dot(normal, this.incident)),
          diffuse = lite.scaleColor(shadow * finish.Kd, lite.diffuse(normal, this.lights)),
          color = lite.scaleColor(pigment.a, lite.multiplyColor(pigment, lite.addColor(ambient, diffuse))),
          cool = lite.addColor(this.npr_cool, lite.scaleColor(this.npr_alpha, color)),
          warm = lite.addColor(this.npr_warm, lite.scaleColor(this.npr_beta, color)),
          d = (1 + lite.dot(this.incident, normal)) / 2,
          color = lite.scaleColor(this.npr_scale, lite.addColor(color, lite.mixColor(cool, warm, d)));
         color.a = pigment.a;
         return lite.fromStdColor(lite.saturateColor(color));
    • summary
  • dojox.gfx3d.lighting.Model.incident

    • summary
  • dojox.gfx3d.lighting.Model.lights

    • summary
  • dojox.gfx3d.lighting.Model.ambient

    • summary
  • dojox.gfx3d.lighting.Model.ambient.a

    • summary
  • dojox.gfx3d.lighting.Model.specular

    • summary
  • dojox.gfx3d.lighting.Model.specular.a

    • summary
  • dojox.gfx3d.lighting.Model.npr_cool

    • summary
  • dojox.gfx3d.lighting.Model.npr_warm

    • summary
  • dojox.gfx3d.lighting.Model.npr_alpha

    • summary
  • dojox.gfx3d.lighting.Model.npr_beta

    • summary
  • dojox.gfx3d.lighting.Model.npr_scale

    • summary
  • dojox.gfx3d.lighting.finish

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.defaults.Ka

    • summary
  • dojox.gfx3d.lighting.finish.defaults.Kd

    • summary
  • dojox.gfx3d.lighting.finish.defaults.Ks

    • summary
  • dojox.gfx3d.lighting.finish.defaults.roughness

    • summary
  • dojox.gfx3d.lighting.finish.defaults

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.dull.Ka

    • summary
  • dojox.gfx3d.lighting.finish.dull.Kd

    • summary
  • dojox.gfx3d.lighting.finish.dull.Ks

    • summary
  • dojox.gfx3d.lighting.finish.dull.roughness

    • summary
  • dojox.gfx3d.lighting.finish.dull

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.shiny.Ka

    • summary
  • dojox.gfx3d.lighting.finish.shiny.Kd

    • summary
  • dojox.gfx3d.lighting.finish.shiny.Ks

    • summary
  • dojox.gfx3d.lighting.finish.shiny.roughness

    • summary
  • dojox.gfx3d.lighting.finish.shiny

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.glossy.Ka

    • summary
  • dojox.gfx3d.lighting.finish.glossy.Kd

    • summary
  • dojox.gfx3d.lighting.finish.glossy.Ks

    • summary
  • dojox.gfx3d.lighting.finish.glossy.roughness

    • summary
  • dojox.gfx3d.lighting.finish.glossy

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.phong_dull.Ka

    • summary
  • dojox.gfx3d.lighting.finish.phong_dull.Kd

    • summary
  • dojox.gfx3d.lighting.finish.phong_dull.Ks

    • summary
  • dojox.gfx3d.lighting.finish.phong_dull.phong

    • summary
  • dojox.gfx3d.lighting.finish.phong_dull.phong_size

    • summary
  • dojox.gfx3d.lighting.finish.phong_dull

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny.Ka

    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny.Kd

    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny.Ks

    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny.phong

    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny.phong_size

    • summary
  • dojox.gfx3d.lighting.finish.phong_shiny

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy.Ka

    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy.Kd

    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy.Ks

    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy.phong

    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy.phong_size

    • summary
  • dojox.gfx3d.lighting.finish.phong_glossy

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.luminous.Ka

    • summary
  • dojox.gfx3d.lighting.finish.luminous.Kd

    • summary
  • dojox.gfx3d.lighting.finish.luminous.Ks

    • summary
  • dojox.gfx3d.lighting.finish.luminous.roughness

    • summary
  • dojox.gfx3d.lighting.finish.luminous

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.metalA.Ka

    • summary
  • dojox.gfx3d.lighting.finish.metalA.Kd

    • summary
  • dojox.gfx3d.lighting.finish.metalA.Ks

    • summary
  • dojox.gfx3d.lighting.finish.metalA.roughness

    • summary
  • dojox.gfx3d.lighting.finish.metalA

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.metalB.Ka

    • summary
  • dojox.gfx3d.lighting.finish.metalB.Kd

    • summary
  • dojox.gfx3d.lighting.finish.metalB.Ks

    • summary
  • dojox.gfx3d.lighting.finish.metalB.roughness

    • summary
  • dojox.gfx3d.lighting.finish.metalB

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.metalC.Ka

    • summary
  • dojox.gfx3d.lighting.finish.metalC.Kd

    • summary
  • dojox.gfx3d.lighting.finish.metalC.Ks

    • summary
  • dojox.gfx3d.lighting.finish.metalC.roughness

    • summary
  • dojox.gfx3d.lighting.finish.metalC

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.metalD.Ka

    • summary
  • dojox.gfx3d.lighting.finish.metalD.Kd

    • summary
  • dojox.gfx3d.lighting.finish.metalD.Ks

    • summary
  • dojox.gfx3d.lighting.finish.metalD.roughness

    • summary
  • dojox.gfx3d.lighting.finish.metalD

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.finish.metalE.Ka

    • summary
  • dojox.gfx3d.lighting.finish.metalE.Kd

    • summary
  • dojox.gfx3d.lighting.finish.metalE.Ks

    • summary
  • dojox.gfx3d.lighting.finish.metalE.roughness

    • summary
  • dojox.gfx3d.lighting.finish.metalE

    • type
      Object
    • summary
  • dojox.gfx3d.lighting.black

    • type
      Function
    • source: [view]
         return {r: 0, g: 0, b: 0, a: 1};
    • summary
  • dojox.gfx3d.lighting.white

    • type
      Function
    • source: [view]
         return {r: 1, g: 1, b: 1, a: 1};
    • summary
  • dojox.gfx3d.lighting.toStdColor

    • type
      Function
    • parameters:
      • c: (typeof )
    • source: [view]
         c = dojox.gfx.normalizeColor(c);
         return {r: c.r / 255, g: c.g / 255, b: c.b / 255, a: c.a};
    • summary
  • dojox.gfx3d.lighting.fromStdColor

    • type
      Function
    • parameters:
      • c: (typeof )
    • source: [view]
         return new dojo.Color([Math.round(255 * c.r), Math.round(255 * c.g), Math.round(255 * c.b), c.a]);
    • summary
  • dojox.gfx3d.lighting.scaleColor

    • type
      Function
    • parameters:
      • s: (typeof )
      • c: (typeof )
    • source: [view]
         return {r: s * c.r, g: s * c.g, b: s * c.b, a: s * c.a};
    • summary
  • dojox.gfx3d.lighting.addColor

    • type
      Function
    • parameters:
      • a: (typeof )
      • b: (typeof )
    • source: [view]
         return {r: a.r + b.r, g: a.g + b.g, b: a.b + b.b, a: a.a + b.a};
    • summary
  • dojox.gfx3d.lighting.multiplyColor

    • type
      Function
    • parameters:
      • a: (typeof )
      • b: (typeof )
    • source: [view]
         return {r: a.r * b.r, g: a.g * b.g, b: a.b * b.b, a: a.a * b.a};
    • summary
  • dojox.gfx3d.lighting.saturateColor

    • type
      Function
    • parameters:
      • c: (typeof )
    • source: [view]
         return {
          r: c.r < 0 ? 0 : c.r > 1 ? 1 : c.r,
          g: c.g < 0 ? 0 : c.g > 1 ? 1 : c.g,
          b: c.b < 0 ? 0 : c.b > 1 ? 1 : c.b,
          a: c.a < 0 ? 0 : c.a > 1 ? 1 : c.a
         };
    • summary
  • dojox.gfx3d.lighting.mixColor

    • type
      Function
    • parameters:
      • c1: (typeof )
      • c2: (typeof )
      • s: (typeof )
    • source: [view]
         return lite.addColor(lite.scaleColor(s, c1), lite.scaleColor(1 - s, c2));
    • summary
  • dojox.gfx3d.lighting.diff2Color

    • type
      Function
    • parameters:
      • c1: (typeof )
      • c2: (typeof )
    • source: [view]
         var r = c1.r - c2.r;
         var g = c1.g - c2.g;
         var b = c1.b - c2.b;
         var a = c1.a - c2.a;
         return r * r + g * g + b * b + a * a;
    • summary
  • dojox.gfx3d.lighting.length2Color

    • type
      Function
    • parameters:
      • c: (typeof )
    • source: [view]
         return c.r * c.r + c.g * c.g + c.b * c.b + c.a * c.a;
    • summary
  • dojox.gfx3d.lighting.dot

    • type
      Function
    • parameters:
      • a: (typeof )
      • b: (typeof )
    • source: [view]
         return a.x * b.x + a.y * b.y + a.z * b.z;
    • summary
  • dojox.gfx3d.lighting.scale

    • type
      Function
    • parameters:
      • s: (typeof )
      • v: (typeof )
    • source: [view]
         return {x: s * v.x, y: s * v.y, z: s * v.z};
    • summary
  • dojox.gfx3d.lighting.add

    • type
      Function
    • parameters:
      • a: (typeof )
      • b: (typeof )
    • source: [view]
         return {x: a.x + b.x, y: a.y + b.y, z: a.z + b.z};
    • summary
  • dojox.gfx3d.lighting.saturate

    • type
      Function
    • parameters:
      • v: (typeof )
    • source: [view]
         return Math.min(Math.max(v, 0), 1);
    • summary
  • dojox.gfx3d.lighting.length

    • type
      Function
    • parameters:
      • v: (typeof )
    • source: [view]
         return Math.sqrt(dojox.gfx3d.lighting.dot(v, v));
    • summary
  • dojox.gfx3d.lighting.normalize

    • type
      Function
    • parameters:
      • v: (typeof )
    • source: [view]
         return lite.scale(1 / lite.length(v), v);
    • summary
  • dojox.gfx3d.lighting.faceforward

    • type
      Function
    • parameters:
      • n: (typeof )
      • i: (typeof )
    • source: [view]
         var p = dojox.gfx3d.lighting;
         var s = p.dot(i, n) < 0 ? 1 : -1;
         return p.scale(s, n);
    • summary
  • dojox.gfx3d.lighting.reflect

    • type
      Function
    • parameters:
      • i: (typeof )
      • n: (typeof )
    • source: [view]
         var p = dojox.gfx3d.lighting;
         return p.add(i, p.scale(-2 * p.dot(i, n), n));
    • summary
  • dojox.gfx3d.lighting.diffuse

    • type
      Function
    • parameters:
      • normal: (typeof )
      • lights: (typeof )
    • source: [view]
         var c = lite.black();
         for(var i = 0; i < lights.length; ++i){
          var l = lights[i],
           d = lite.dot(lite.normalize(l.direction), normal);
          c = lite.addColor(c, lite.scaleColor(d, l.color));
         }
         return lite.saturateColor(c);
    • summary
  • dojox.gfx3d.lighting.specular

    • type
      Function
    • parameters:
      • normal: (typeof )
      • v: (typeof )
      • roughness: (typeof )
      • lights: (typeof )
    • source: [view]
         var c = lite.black();
         for(var i = 0; i < lights.length; ++i){
          var l = lights[i],
           h = lite.normalize(lite.add(lite.normalize(l.direction), v)),
           s = Math.pow(Math.max(0, lite.dot(normal, h)), 1 / roughness);
          c = lite.addColor(c, lite.scaleColor(s, l.color));
         }
         return lite.saturateColor(c);
    • summary
  • dojox.gfx3d.lighting.phong

    • type
      Function
    • parameters:
      • normal: (typeof )
      • v: (typeof )
      • size: (typeof )
      • lights: (typeof )
    • source: [view]
         normal = lite.normalize(normal);
         var c = lite.black();
         for(var i = 0; i < lights.length; ++i){
          var l = lights[i],
           r = lite.reflect(lite.scale(-1, lite.normalize(v)), normal),
           s = Math.pow(Math.max(0, lite.dot(r, lite.normalize(l.direction))), size);
          c = lite.addColor(c, lite.scaleColor(s, l.color));
         }
         return lite.saturateColor(c);
    • summary
  • dojox.gfx3d.lighting

    • type
      Object
    • summary
  • dojox.gfx3d

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary