瀏覽代碼

Ocean2: More clean up and optimisations.
Still rendering mad slow though...

Mr.doob 11 年之前
父節點
當前提交
a8f0094dbc
共有 2 個文件被更改,包括 6 次插入11 次删除
  1. 5 9
      examples/js/Ocean.js
  2. 1 2
      examples/webgl_shaders_ocean2.html

+ 5 - 9
examples/js/Ocean.js

@@ -7,7 +7,7 @@
 	this.oceanCamera = new THREE.OrthographicCamera(); //camera.clone();
 	this.oceanCamera.position.z = 1;
 	this.renderer = renderer;
-	this.renderer.clearColor(new THREE.Color(1.0, 1.0, 1.0, 1.0));
+	this.renderer.clearColor( 0xffffff );
 	
 	this.scene = new THREE.Scene();
 
@@ -128,7 +128,7 @@
 		vertexShader: fullscreeenVertexShader.vertexShader,
 		fragmentShader:initialSpectrumShader.fragmentShader
 	});
-	this.materialInitialSpectrum.uniforms.u_wind = { type: "v2", value: null };
+	this.materialInitialSpectrum.uniforms.u_wind = { type: "v2", value: new THREE.Vector2() };
 	this.materialInitialSpectrum.uniforms.u_resolution = { type: "f", value: this.resolution };
 	this.materialInitialSpectrum.depthTest = false;
 	
@@ -183,7 +183,7 @@
 	this.materialOcean.uniforms.u_normalMap = { type: "t", value: this.normalMapFramebuffer }; 
 	this.materialOcean.uniforms.u_oceanColor = { type: "v3", value: this.oceanColor }; 
 	this.materialOcean.uniforms.u_skyColor = { type: "v3", value: this.skyColor };
-	this.materialOcean.uniforms.u_sunDirection = { type: "v3", value: new THREE.Vector3(this.sunDirectionX,this.sunDirectionY,this.sunDirectionZ )};
+	this.materialOcean.uniforms.u_sunDirection = { type: "v3", value: new THREE.Vector3( this.sunDirectionX, this.sunDirectionY, this.sunDirectionZ ) };
 	this.materialOcean.uniforms.u_exposure = { type: "f", value: this.exposure };
 
 	// Disable blending to prevent default premultiplied alpha values
@@ -195,12 +195,8 @@
 	this.materialNormal.blending = 0;
 	this.materialOcean.blending = 0;
 
-	// Seed the simulation
-	var screenGeo = new THREE.PlaneGeometry(2, 2);
-	screenGeo.buffersNeedUpdate = true;
-
 	// Create the simulation plane
-	this.screenQuad = new THREE.Mesh(screenGeo);
+	this.screenQuad = new THREE.Mesh( new THREE.PlaneGeometry( 2, 2 ) );
 	this.scene.add(this.screenQuad);
 
 	// Initialise spectrum data
@@ -256,7 +252,7 @@ THREE.Ocean.prototype.generateSeedPhaseTexture = function() {
 
 THREE.Ocean.prototype.renderInitialSpectrum = function () {
 	this.scene.overrideMaterial = this.materialInitialSpectrum;
-	this.materialInitialSpectrum.uniforms.u_wind.value = new THREE.Vector2(this.windX, this.windY);
+	this.materialInitialSpectrum.uniforms.u_wind.value.set( this.windX, this.windY );
 	this.materialInitialSpectrum.uniforms.u_size.value = this.size;
 	this.renderer.render(this.scene, this.oceanCamera, this.initialSpectrumFramebuffer, true);
 };

+ 1 - 2
examples/webgl_shaders_ocean2.html

@@ -175,7 +175,6 @@
 				},
 
 				Update: function () {
-					this.ms_Renderer.clear();
 					var currentTime = new Date().getTime();
 					this.ms_Ocean.deltaTime = (currentTime - lastTime) / 1000 || 0.0;
 					lastTime = currentTime;
@@ -183,7 +182,7 @@
 					this.ms_Ocean.overrideMaterial = this.ms_Ocean.materialOcean;
 					if (this.ms_Ocean.changed) {
 						this.ms_Ocean.materialOcean.uniforms.u_size.value = this.ms_Ocean.size;
-						this.ms_Ocean.materialOcean.uniforms.u_sunDirection.value = new THREE.Vector3(this.ms_Ocean.sunDirectionX, this.ms_Ocean.sunDirectionY, this.ms_Ocean.sunDirectionZ);
+						this.ms_Ocean.materialOcean.uniforms.u_sunDirection.value.set( this.ms_Ocean.sunDirectionX, this.ms_Ocean.sunDirectionY, this.ms_Ocean.sunDirectionZ );
 						this.ms_Ocean.materialOcean.uniforms.u_exposure.value = this.ms_Ocean.exposure;
 						this.ms_Ocean.changed = false;
 					}