HTML5 Canvas 3D WebGL (TM) js Library
 

lightAmbDiff Library Method

Short Description: Set ambient and diffuse color

Signature: x.lightAmbDiff (ambientColor,diffuseColor,a0,a1)
Class: taccglMaterial Class
 

Defines the ambient and diffuse reflection color and the background transparency. The diffuse color specifies the color of the light coming directly from the light source and reflected by the object. If the object direclty faces the light source, it receives the full diffuse color specified here. If it turns away or if it is shadowed, it gets less or even no diffuse light. The amibient color models the color of the light the object receives from other light sources or via multiple reflections. It always receives the ambient color specified here, regardless of the objects position.

If the ambient color white and diffuse color black are specified, the animated HTML element shows up as is, regardless of its position. If the two colors add up to white and if the light source is in front of the page (which is roughly the default), then the animated HTML element shows up as is but gets darker and more like the ambient color if it is rotated away.

If the sum of ambient and diffuse color is darker than white, then the animated HTML element becomes darker. If the sum of ambient and diffuse color is lighter than white (which is indeed mathematically possible), then the HTML element becomes lighter, however since a screen cannot show lighter colors than white, this does not really look good.

In most cases one specifies a gray scale for both colors. You can however specify any color, e.g. to model a colored light source.

If the method is not used, default values as specified in taccgl.Lighting Parameters are taken.

var m=taccgl.material().lightAmbDiff("black","white",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("white","black",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(65,65,65)","rgb(190,190,190)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(50,50,50)","rgb(190,190,190)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(190,190,190)","rgb(190,190,190)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(50,50,50)","rgb(50,50,50)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(190,190,190)","rgb(65,65,65)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("red","rgb(0,255,255)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(100,100,100)","rgb(160,0,0)",0,0);
taccgl.actor("Layout").material(m).rotateMiddle(0,1,0).dur(7).start();
RUN

The methods color, lightAmbDiff, and lightBgAmbDiff are mutually exclusive, only one of them can be used for a single transition. lightAmbDiff sets the background color to white with the specified alpha value (0 means transparent ... 1 fully visible). If the second alpha value is given, an animation from the first to the second value is performed. Note that the background color is relevant, only if the HTML element is transparent. But if this is the case, it can be important to show some kind of background. Using lightAmbDiff you can only have white as background color. If you need another background color, you need to modify your HTML code to include the background or use lightBgAmbDiff.

Examples

var m=taccgl.material().lightAmbDiff("rgb(65,65,65)","rgb(190,190,190)",0,0); taccgl.texClearAll();
var a=taccgl.actor("para").material(m).rotateMiddle(0,1,0).dur(7); a.position(a.x,a.y-100,0).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(65,65,65)","rgb(190,190,190)",1,1); taccgl.texClearAll();
var a=taccgl.actor("para").material(m).rotateMiddle(0,1,0).dur(7); a.position(a.x,a.y-100,0).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(65,65,65)","rgb(190,190,190)",1,0); taccgl.texClearAll();
var a=taccgl.actor("para").material(m).rotateMiddle(0,1,0).dur(7); a.position(a.x,a.y-100,0).start();
RUN
var m=taccgl.material().lightAmbDiff("rgb(65,65,65)","rgb(190,190,190)",1,0); taccgl.texClearAll();
var a=taccgl.actor("para").rotateMiddle(0,1,0).dur(7); a.position(a.x,a.y-100,0).blend(1,0,0,0).start();
RUN

WebGL™ is a trademark of the Khronos Group Inc.

Next Page:taccglMaterial.lightBgAmbDiff - Set background color, ambient and diffuse factors
Previous Page: taccglMaterial.color - Set background color / color animation