Three.js Source Note (44) light/directionallight.js

Source: Internet
Author: User

Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


I was just beginning to learn, a lot of things are definitely wrong and please forgive me.

The following code is a comment for the light/directionallight.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode


/** * @author mrdoob/http://mrdoob.com/* @author alteredq/http://alteredqualia.com/*//*///directionallight method According to the setting of the light Yan attribute color, strength attribute intensity creates a parallel light source. The function function of the///directionallight object is implemented by the function prototype object that defines the construct.///Note:spotlight type light to achieve a shadow, But you need to use meshlambertmaterial in the scene or meshphongmaterial///the following comments directly from: HTTP://WWW.CNBLOGS.COM/YIYEZHAI/ARCHIVE/2012/12 /24/2829991.html///example:///var light = new three. SpotLight (0xff0000,1,100,math.pi/2,5);//Create light object///Light.position.set (50,50,30);//Set Position///light.castshadow = true;/ /Turn on Shadow///light.shadowmapwidth = 1024; The shadow map width is set to 1024 pixels///light.shadowmapheight = 1024; Shadow map height is set to 1024 pixels///light.shadowcameranear = 500;//shadow of the flat head body area near Property///light.shadowcamerafar = 4000;//Shadow of the flat head body area far property Light.shadowcamerafov = 30;//Shadow of the flat head body area of the FoV property///scene.add (LIGNT);//Join Scene *////<summary>directionallight< /summary>///<param name = "Color" type= "three. Color > Light </param>///<param name = "Intensity" type= "number" > the intensity of the light, the default is 1</param>///< Returns type= "DirectioNallight "> Return directionallight, Parallel light source. </returns>three. DirectionalLight = function (color, intensity) {three. Light.call (this, color);//Call method of the light object is called, the method that originally belongs to light is given to the current object directionallight to use. This.position.set (0, 1, 0);// The Location property of the light is initialized to 0,1,0this.target = new three. Object3d ();//Create a target point object, the target point object is a Object3d object. this.intensity = (intensity!== undefined)? intensity:1;//the Color property of the light, if not specified, is initialized to 1. (The density of the light, the default is 1.) Because the RGB three values are between 0~255, does not reflect the intensity of the light changes, the stronger the light, the surface of the object is brighter. This.castshadow = false;//Boolean, default is False, and if set to true, all surfaces are calculated on a cell-by-pixel basis whether they are obscured in the light direction, which consumes a lot of computation. This.onlyshadow = false;//Boolean, which controls whether only shadows are generated without "illuminating" the object, which defaults to false. This model may have some special application. this.shadowcameranear = 50;//shadowcameranear attribute, orthogonal projection cube proximal end, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, Near by default is the 50this.shadowcamerafar = 5000;//shadowcamerafar property, orthogonal projection cube distal end, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, Far by default is the 5000this.shadowcameraleft =-500;//shadowcameraleft attribute, orthogonal projection cube left end, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, Left default is 500this.shadowcameraright = 500;//shadowcameraright property, orthogonal projection cube right end, defines a range (orthogonal projection cube), not calculated outside the rangeThe shadow of the object, right by default is the 500this.shadowcameratop = 500;//shadowcameratop attribute, the upper end of the orthogonal projection cube, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, The top default is the 500this.shadowcamerabottom =-500;//shadowcamerabottom attribute, the lower end of the orthogonal projection cube, defines a range (orthogonal projection cube), does not calculate the shadow of objects outside the range, Bottom default is 500this.shadowcameravisible = False;//shadowcameravisible set to True to display the light frame in the scene for easy debugging This.shadowbias = 0;// The offset of the shadow map, this.shadowdarkness = 0.5;//The effect of the shadow on the object brightness, the default is 0.5this.shadowmapwidth = 512; Shadow map width, per pixel, default 512this.shadowmapheight = 512; Shadow map height, per pixel, default 512/* for parallel lights, WebGL can use a cascading shadow map (or become a parallel split shadow map) to have good shadow quality, especially for long-distance viewing. Cascading shadows are progressively partially larger by dividing the viewable area, and use the same size in each shadow map. As a result, objects closer to the viewer will get more shadow-pasted images than objects farther away. For the quality and performance of the shadow of the parallel light, the distance of the shadow is very important. Just like the shadow Cascade, the shadow distance can be set in the quality settings, and it is easy to reduce the shadow range to reduce hardware performance consumption. At the end of the shadow distance, the shadows fade away, and farther objects will have no shadows. In most cases the shadows in the scene farther away will not be noticeable! */this.shadowcascade = false;//Shadow Cascade This.shadowcascadeoffset = new three. Vector3 (0, 0,-1000);//shadow cascade offset distance this.shadowcascadecount = 2;//When 2 shadow Cascade is used, the entire shadow distance is divided by default into two blocks, The smaller blocks near the viewer and the larger blocks in the distance This.shadowcascadebias = [0, 0, 0];//Shadow cascade offset Array this.shadowcascadewidth = [512, 512, 512];//shadow cascade width array this. ShadowcAscadeheight = [512, 512, 512];//shadow cascade height Array this.shadowcascadenearz = [-1.000, 0.990, 0.998];//shadow Cascade near This.shadowcascadef ArZ = [0.990, 0.998, 1.000];//shadow cascade distance This.shadowcascadearray = [];//shadow cascade array//todo: These are completely not understood, then fill in the detailed comments This.shadowmap = null;//Specify the shadow map, Webglrendertarget object, here seems very complex, completely do not understand, later to fill in the detailed comments. This.shadowmapsize = null;//the size of the shadow map, note that This should conform to the requirements for textures in OpenGL (2 N-square +2n) This.shadowcamera = null;//Shadow Map camera, three. Perspectivecamera object, This.shadowmatrix = null;//Shadow map Matrix};/******************************************************** The following is the definition of the functional function provided by the DirectionalLight object, partially inherited from the light method by prototype ********************* /three. Directionallight.prototype = Object.create (three. Light.prototype);//directionallight object inherits all property methods from Three.light's prototype/*clone method///clone method Clone DirectionalLight Object *////< Summary>clone</summary>///<returns type= "SpotLight" > returns the cloned DirectionalLight object </returns>three . Directionallight.prototYpe.clone = function () {var light = new three. DirectionalLight (); Three. Light.prototype.clone.call (this, light);//Call the THREE.Light.clone method, clone a parallel Optical object//Copy the properties of the current light object light.target = This.target.clone (); light.intensity = This.intensity;light.castshadow = This.castshadow;light.onlyshadow = This.onlyshadow;//light.shadowcameranear = This.shadowcameranear;light.shadowcamerafar = This.shadowCameraFar; Light.shadowcameraleft = This.shadowcameraleft;light.shadowcameraright = This.shadowcameraright; Light.shadowcameratop = This.shadowcameratop;light.shadowcamerabottom = This.shadowcamerabottom; light.shadowcameravisible = This.shadowcameravisible;light.shadowbias = This.shadowbias;light.shadowdarkness = This.shadowdarkness;light.shadowmapwidth = This.shadowmapwidth;light.shadowmapheight = this.shadowMapHeight;// Light.shadowcascade = This.shadowcascade;light.shadowcascadeoffset.copy (This.shadowcascadeoffset); Light.shadowcascadecount = This.shadowcascadecount;light.shadowcascadebias = This.shadowcascadebiAs.slice (0); light.shadowcascadewidth = This.shadowCascadeWidth.slice (0); light.shadowcascadeheight = This.shadowCascadeHeight.slice (0); Light.shadowcascadenearz = This.shadowCascadeNearZ.slice (0); Light.shadowcascadefarz = This.shadowCascadeFarZ.slice (0); return light;//returns the object of the cloned parallel light};


Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


The following code is a comment for the light/directionallight.js file in the three.js source file.

More updates in: Https://github.com/omni360/three.js.sourcecode

Three.js Source Note (44) light/directionallight.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.