-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathCloud.js
More file actions
47 lines (34 loc) · 1.41 KB
/
Cloud.js
File metadata and controls
47 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* @author mattatz / http://github.com/mattatz
*
* Ray tracing based cloud noise object.
*/
THREE.Cloud = function ( color ) {
var cloudMaterial = new THREE.ShaderMaterial( {
defines : THREE.CloudShader.defines,
uniforms : THREE.UniformsUtils.clone( THREE.CloudShader.uniforms ),
vertexShader : THREE.CloudShader.vertexShader,
fragmentShader : THREE.CloudShader.fragmentShader,
transparent : true,
depthWrite : false,
depthTest : false
} );
// initialize uniforms
cloudMaterial.uniforms.color.value = color || new THREE.Color( 0xeeeeee );
cloudMaterial.uniforms.invModelMatrix.value = new THREE.Matrix4();
cloudMaterial.uniforms.scale.value = new THREE.Vector3( 1, 1, 1 );
cloudMaterial.uniforms.seed.value = Math.random() * 19.19;
THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), cloudMaterial );
};
THREE.Cloud.prototype = Object.create( THREE.Mesh.prototype );
THREE.Cloud.prototype.constructor = THREE.Cloud;
THREE.Cloud.prototype.update = function ( time ) {
var invModelMatrix = this.material.uniforms.invModelMatrix.value;
this.updateMatrix();
invModelMatrix.getInverse( this.matrix );
if( time !== undefined ) {
this.material.uniforms.time.value = time;
}
this.material.uniforms.invModelMatrix.value = invModelMatrix;
this.material.uniforms.scale.value = this.scale;
};