//>>built
define("dojox/gfx3d/lighting",["dojo/_base/lang","dojo/_base/Color","dojo/_base/declare","dojox/gfx/_base","./_base"],function(q,m,n,p,l){var b=l.lighting={black:function(){return{r:0,g:0,b:0,a:1}},white:function(){return{r:1,g:1,b:1,a:1}},toStdColor:function(a){a=p.normalizeColor(a);return{r:a.r/255,g:a.g/255,b:a.b/255,a:a.a}},fromStdColor:function(a){return new m([Math.round(255*a.r),Math.round(255*a.g),Math.round(255*a.b),a.a])},scaleColor:function(a,c){return{r:a*c.r,g:a*c.g,b:a*c.b,a:a*c.a}},
addColor:function(a,c){return{r:a.r+c.r,g:a.g+c.g,b:a.b+c.b,a:a.a+c.a}},multiplyColor:function(a,c){return{r:a.r*c.r,g:a.g*c.g,b:a.b*c.b,a:a.a*c.a}},saturateColor:function(a){return{r:0>a.r?0:1<a.r?1:a.r,g:0>a.g?0:1<a.g?1:a.g,b:0>a.b?0:1<a.b?1:a.b,a:0>a.a?0:1<a.a?1:a.a}},mixColor:function(a,c,d){return b.addColor(b.scaleColor(d,a),b.scaleColor(1-d,c))},diff2Color:function(a,c){var d=a.r-c.r,e=a.g-c.g,f=a.b-c.b,g=a.a-c.a;return d*d+e*e+f*f+g*g},length2Color:function(a){return a.r*a.r+a.g*a.g+a.b*a.b+
a.a*a.a},dot:function(a,c){return a.x*c.x+a.y*c.y+a.z*c.z},scale:function(a,c){return{x:a*c.x,y:a*c.y,z:a*c.z}},add:function(a,c){return{x:a.x+c.x,y:a.y+c.y,z:a.z+c.z}},saturate:function(a){return Math.min(Math.max(a,0),1)},length:function(a){return Math.sqrt(l.lighting.dot(a,a))},normalize:function(a){return b.scale(1/b.length(a),a)},faceforward:function(a,c){var d=l.lighting,e=0>d.dot(c,a)?1:-1;return d.scale(e,a)},reflect:function(a,c){var d=l.lighting;return d.add(a,d.scale(-2*d.dot(a,c),c))},
diffuse:function(a,c){for(var d=b.black(),e=0;e<c.length;++e){var f=c[e],g=b.dot(b.normalize(f.direction),a);d=b.addColor(d,b.scaleColor(g,f.color))}return b.saturateColor(d)},specular:function(a,c,d,e){for(var f=b.black(),g=0;g<e.length;++g){var h=e[g],k=b.normalize(b.add(b.normalize(h.direction),c));k=Math.pow(Math.max(0,b.dot(a,k)),1/d);f=b.addColor(f,b.scaleColor(k,h.color))}return b.saturateColor(f)},phong:function(a,c,d,e){a=b.normalize(a);for(var f=b.black(),g=0;g<e.length;++g){var h=e[g],
k=b.reflect(b.scale(-1,b.normalize(c)),a);k=Math.pow(Math.max(0,b.dot(k,b.normalize(h.direction))),d);f=b.addColor(f,b.scaleColor(k,h.color))}return b.saturateColor(f)}};n("dojox.gfx3d.lighting.Model",null,{constructor:function(a,c,d,e){this.incident=b.normalize(a);this.lights=[];for(a=0;a<c.length;++a){var f=c[a];this.lights.push({direction:b.normalize(f.direction),color:b.toStdColor(f.color)})}this.ambient=b.toStdColor(d.color?d.color:"white");this.ambient=b.scaleColor(d.intensity,this.ambient);
this.ambient=b.scaleColor(this.ambient.a,this.ambient);this.ambient.a=1;this.specular=b.toStdColor(e?e:"white");this.specular=b.scaleColor(this.specular.a,this.specular);this.specular.a=1;this.npr_cool={r:0,g:0,b:.4,a:1};this.npr_warm={r:.4,g:.4,b:.2,a:1};this.npr_alpha=.2;this.npr_scale=this.npr_beta=.6},constant:function(a,c,d){d=b.toStdColor(d);a=d.a;d=b.scaleColor(a,d);d.a=a;return b.fromStdColor(b.saturateColor(d))},matte:function(a,c,d){"string"==typeof c&&(c=b.finish[c]);d=b.toStdColor(d);
a=b.faceforward(b.normalize(a),this.incident);var e=b.scaleColor(c.Ka,this.ambient),f=b.saturate(-4*b.dot(a,this.incident));a=b.scaleColor(f*c.Kd,b.diffuse(a,this.lights));e=b.scaleColor(d.a,b.multiplyColor(d,b.addColor(e,a)));e.a=d.a;return b.fromStdColor(b.saturateColor(e))},metal:function(a,c,d){"string"==typeof c&&(c=b.finish[c]);d=b.toStdColor(d);a=b.faceforward(b.normalize(a),this.incident);var e=b.scale(-1,this.incident);var f=b.scaleColor(c.Ka,this.ambient);var g=b.saturate(-4*b.dot(a,this.incident));
a="phong"in c?b.scaleColor(g*c.Ks*c.phong,b.phong(a,e,c.phong_size,this.lights)):b.scaleColor(g*c.Ks,b.specular(a,e,c.roughness,this.lights));f=b.scaleColor(d.a,b.addColor(b.multiplyColor(d,f),b.multiplyColor(this.specular,a)));f.a=d.a;return b.fromStdColor(b.saturateColor(f))},plastic:function(a,c,d){"string"==typeof c&&(c=b.finish[c]);d=b.toStdColor(d);a=b.faceforward(b.normalize(a),this.incident);var e=b.scale(-1,this.incident);var f=b.scaleColor(c.Ka,this.ambient);var g=b.saturate(-4*b.dot(a,
this.incident)),h=b.scaleColor(g*c.Kd,b.diffuse(a,this.lights));a="phong"in c?b.scaleColor(g*c.Ks*c.phong,b.phong(a,e,c.phong_size,this.lights)):b.scaleColor(g*c.Ks,b.specular(a,e,c.roughness,this.lights));f=b.scaleColor(d.a,b.addColor(b.multiplyColor(d,b.addColor(f,h)),b.multiplyColor(this.specular,a)));f.a=d.a;return b.fromStdColor(b.saturateColor(f))},npr:function(a,c,d){"string"==typeof c&&(c=b.finish[c]);d=b.toStdColor(d);a=b.faceforward(b.normalize(a),this.incident);var e=b.scaleColor(c.Ka,
this.ambient),f=b.saturate(-4*b.dot(a,this.incident));c=b.scaleColor(f*c.Kd,b.diffuse(a,this.lights));e=b.scaleColor(d.a,b.multiplyColor(d,b.addColor(e,c)));c=b.addColor(this.npr_cool,b.scaleColor(this.npr_alpha,e));f=b.addColor(this.npr_warm,b.scaleColor(this.npr_beta,e));a=(1+b.dot(this.incident,a))/2;e=b.scaleColor(this.npr_scale,b.addColor(e,b.mixColor(c,f,a)));e.a=d.a;return b.fromStdColor(b.saturateColor(e))}});l.lighting.finish={defaults:{Ka:.1,Kd:.6,Ks:0,roughness:.05},dull:{Ka:.1,Kd:.6,Ks:.5,
roughness:.15},shiny:{Ka:.1,Kd:.6,Ks:1,roughness:.001},glossy:{Ka:.1,Kd:.6,Ks:1,roughness:1E-4},phong_dull:{Ka:.1,Kd:.6,Ks:.5,phong:.5,phong_size:1},phong_shiny:{Ka:.1,Kd:.6,Ks:1,phong:1,phong_size:200},phong_glossy:{Ka:.1,Kd:.6,Ks:1,phong:1,phong_size:300},luminous:{Ka:1,Kd:0,Ks:0,roughness:.05},metalA:{Ka:.35,Kd:.3,Ks:.8,roughness:.05},metalB:{Ka:.3,Kd:.4,Ks:.7,roughness:1/60},metalC:{Ka:.25,Kd:.5,Ks:.8,roughness:.0125},metalD:{Ka:.15,Kd:.6,Ks:.8,roughness:.01},metalE:{Ka:.1,Kd:.7,Ks:.8,roughness:1/
120}};return b});