The weather is more and more cold, people are more and more indolence, more and more like staying in the warm bedroom to read novels or play games, but also a long time did not see Three.js source. It's a nice day, keep looking!
This time from the light part: The illumination model, from the angle of light itself, includes ambient light, parallel light, point light source, from the object surface material angle also includes diffuse reflection and specular reflection.
Lights:light
Copy Code code as follows:
THREE. Light = function (hex) {
THREE. Object3d.call (this);
This.color = new THREE. Color (hex);
};
The object is a prototype/base class for other lighting objects and itself inherits from the Object3d object/type. It is very understandable that it has only one three.color type of color attribute.
In Three.js, illumination as a Object3d object is added to the scene by Scene.add () method, and the renderer automatically renders the added illumination effect.
Light::ambientlight
Copy Code code as follows:
THREE. Ambientlight = function (hex) {
THREE. Light.call (this, hex);
};
No directional ambient light, and there is no more than light type of a property or method, but only for semantic inheritance to inherit from light, it is not even necessary to be Object3d objects.
Light::D irectionallight
Copy Code code as follows:
THREE. DirectionalLight = function (hex, intensity) {
THREE. Light.call (this, hex);
This.position = new THREE. Vector3 (0, 1, 0);
This.target = new THREE. Object3d ();
This.intensity = (intensity!== undefined)? Intensity:1;
This.castshadow = false;
This.onlyshadow = false;
More Settings about Shadow ...
};
Parallel light (with directional light), the new operator is used to construct the function by passing in the color hex and the "density" intensity of the light. This class has some properties:
Position: a position in which the origin is the starting point, and the direction of the destination is the direction of the light.
Intensity: The density of the light, the default is 1. Because RGB three values are between 0~255, can not reflect the intensity of light changes, the stronger the light, the surface of the object is brighter.
Distance: Attenuation distance, the default value is 0, the illumination does not decay, if it is not 0, the illumination will start to decay from the position position (actually the plane where position is located), and after the distance distance, the illumination intensity intensity 0.
Castshadow: Boolean value that controls whether a shadow is generated and false by default. If set to true, a pixel-by-pixel calculation is used for all surfaces to see if they are obscured in the light direction, which consumes a lot of computation.
Onlyshadow: Boolean value that controls whether only shadows are generated instead of "illuminating" objects, the default is False. This model may have some special applications.
Shadowcameraleft,shadowcameraright ... Series, with position points as the center of control to create a shaded range?
Shadowbias: Shadow bias, defaults to 0.
Shadowdarkness: The effect of shadows on the brightness of an object, between 0~1, defaults to 0.5.
There are a lot of properties can not guess the meaning of the moment (really should go to repair computer graphics Ah, the bullet-stick to continue to see it).
Light::P ointlight
Copy Code code as follows:
THREE. Pointlight = function (hex, intensity, distance) {
THREE. Light.call (this, hex);
This.position = new THREE. Vector3 (0, 0, 0);
This.intensity = (intensity!== undefined)? Intensity:1;
This.distance = (distance!== undefined)? distance:0;
};
Point Light source, position that must be the light point. Note the difference between the position of the point light source and the position of the parallel light, which defaults at the origin and the latter by default at the point (0,1,1), which makes the default parallel light direction consistent with the camera's default orientation.
The other two properties are the same as in the parallel light. The pointlight point Light does not have a setting for how to create shadows.
Light::spotlight
Copy Code code as follows:
THREE. SpotLight = function (hex, intensity, distance, angle, exponent) {
THREE. Light.call (this, hex);
This.position = new THREE. Vector3 (0, 1, 0);
This.target = new THREE. Object3d ();
This.intensity = (intensity!== undefined)? Intensity:1;
This.distance = (distance!== undefined)? distance:0;
This.angle = (angle!== undefined)? ANGLE:MATH.PI/2;
This.exponent = (exponent!== undefined)? Exponent:10; More Settings about Shadow ...
};
A point light that can create a shadow in a direction that affects the surface of the meshlambermaterial and meshphongmaterial type material. The settings for how the shadow is handled are consistent with the directionlight.
In short, the lighting object does not assume the task of rendering illumination, but merely defines how the illumination is rendered.
Object::P artical
Copy Code code as follows:
THREE. particle = function (material) {
THREE. Object3d.call (this);
this.material = material;
};
The particle is a object3d of material, which is well understood. The Object3d object provides a coordinate (the coordinates of the particles) that is responsible for the movement of the particles, and the particles only need to specify the material to represent it.
Object::P articalsystem
Copy Code code as follows:
THREE. Particlesystem = function (geometry, material) {
THREE. Object3d.call (this);
This.geometry = geometry;
this.material = (material!== undefined)? Material:new THREE. Particlebasicmaterial ({color:Math.random () * 0xffffff});
This.sortparticles = false;
if (this.geometry) {
if (This.geometry.boundingSphere = = null) {
This.geometry.computeBoundingSphere ();
}
This.boundradius = Geometry.boundingSphere.radius;
}
this.frustumculled = false;
};
Particle systems represent the motions of multiple particles, and the particle system itself inherits naturally Object3d objects. There are several properties:
Geometry property, each node is a particle that shares a material.
Material properties, that is, the material of these nodes.
The frustumculled attribute, Boolean, if set to true, will be kicked out of the camera horizon, but it is not clear whether the center coordinates of the particle system kick out of the entire particle system outside the event horizon or whether a single particle goes out, presumably the latter.
In fact, these are involved in how to define the scene, as to how to render the scene is difficult to have in-depth. I'm going to look at the demo's code, and the combination of the Webglrenderer class source (Thousands of line OMG).