Ocean.js 15.0 KB
Newer Older
M
r72  
Mr.doob 已提交
1 2
THREE.Ocean = function ( renderer, camera, scene, options ) {

M
r67  
Mr.doob 已提交
3 4 5
	// flag used to trigger parameter changes
	this.changed = true;
	this.initial = true;
M
r72  
Mr.doob 已提交
6

M
r67  
Mr.doob 已提交
7 8 9 10 11
	// Assign required parameters as object properties
	this.oceanCamera = new THREE.OrthographicCamera(); //camera.clone();
	this.oceanCamera.position.z = 1;
	this.renderer = renderer;
	this.renderer.clearColor( 0xffffff );
M
r72  
Mr.doob 已提交
12

M
r67  
Mr.doob 已提交
13
	this.scene = new THREE.Scene();
M
r72  
Mr.doob 已提交
14

M
r67  
Mr.doob 已提交
15
	// Assign optional parameters as variables and object properties
M
r72  
Mr.doob 已提交
16 17
	function optionalParameter( value, defaultValue ) {

M
r67  
Mr.doob 已提交
18
		return value !== undefined ? value : defaultValue;
M
r72  
Mr.doob 已提交
19 20

	}
M
r67  
Mr.doob 已提交
21
	options = options || {};
M
r72  
Mr.doob 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	this.clearColor = optionalParameter( options.CLEAR_COLOR, [ 1.0, 1.0, 1.0, 0.0 ] );
	this.geometryOrigin = optionalParameter( options.GEOMETRY_ORIGIN, [ - 1000.0, - 1000.0 ] );
	this.sunDirectionX = optionalParameter( options.SUN_DIRECTION[ 0 ], - 1.0 );
	this.sunDirectionY = optionalParameter( options.SUN_DIRECTION[ 1 ], 1.0 );
	this.sunDirectionZ = optionalParameter( options.SUN_DIRECTION[ 2 ], 1.0 );
	this.oceanColor = optionalParameter( options.OCEAN_COLOR, new THREE.Vector3( 0.004, 0.016, 0.047 ) );
	this.skyColor = optionalParameter( options.SKY_COLOR, new THREE.Vector3( 3.2, 9.6, 12.8 ) );
	this.exposure = optionalParameter( options.EXPOSURE, 0.35 );
	this.geometryResolution = optionalParameter( options.GEOMETRY_RESOLUTION, 32 );
	this.geometrySize = optionalParameter( options.GEOMETRY_SIZE, 2000 );
	this.resolution = optionalParameter( options.RESOLUTION, 64 );
	this.floatSize = optionalParameter( options.SIZE_OF_FLOAT, 4 );
	this.windX = optionalParameter( options.INITIAL_WIND[ 0 ], 10.0 ),
	this.windY = optionalParameter( options.INITIAL_WIND[ 1 ], 10.0 ),
	this.size = optionalParameter( options.INITIAL_SIZE, 250.0 ),
	this.choppiness = optionalParameter( options.INITIAL_CHOPPINESS, 1.5 );

	//
M
r67  
Mr.doob 已提交
40
	this.matrixNeedsUpdate = false;
M
r72  
Mr.doob 已提交
41

M
r67  
Mr.doob 已提交
42
	// Setup framebuffer pipeline
M
r72  
Mr.doob 已提交
43
	var renderTargetType = optionalParameter( options.USE_HALF_FLOAT, false ) ? THREE.HalfFloatType : THREE.FloatType;
M
r67  
Mr.doob 已提交
44 45 46 47 48 49 50 51 52
	var LinearClampParams = {
		minFilter: THREE.LinearFilter,
		magFilter: THREE.LinearFilter,
		wrapS: THREE.ClampToEdgeWrapping,
		wrapT: THREE.ClampToEdgeWrapping,
		format: THREE.RGBAFormat,
		stencilBuffer: false,
		depthBuffer: false,
		premultiplyAlpha: false,
M
r71  
Mr.doob 已提交
53
		type: renderTargetType
M
r67  
Mr.doob 已提交
54 55 56 57 58 59 60 61 62
	};
	var NearestClampParams = {
		minFilter: THREE.NearestFilter,
		magFilter: THREE.NearestFilter,
		wrapS: THREE.ClampToEdgeWrapping,
		wrapT: THREE.ClampToEdgeWrapping,
		format: THREE.RGBAFormat,
		stencilBuffer: false,
		depthBuffer: false,
M
r72  
Mr.doob 已提交
63
		premultiplyAlpha: false,
M
r71  
Mr.doob 已提交
64
		type: renderTargetType
M
r67  
Mr.doob 已提交
65 66 67 68 69 70 71 72 73 74
	};
	var NearestRepeatParams = {
		minFilter: THREE.NearestFilter,
		magFilter: THREE.NearestFilter,
		wrapS: THREE.RepeatWrapping,
		wrapT: THREE.RepeatWrapping,
		format: THREE.RGBAFormat,
		stencilBuffer: false,
		depthBuffer: false,
		premultiplyAlpha: false,
M
r71  
Mr.doob 已提交
75
		type: renderTargetType
M
r67  
Mr.doob 已提交
76
	};
M
r72  
Mr.doob 已提交
77 78 79 80 81 82 83 84 85
	this.initialSpectrumFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestRepeatParams );
	this.spectrumFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
	this.pingPhaseFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
	this.pongPhaseFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
	this.pingTransformFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
	this.pongTransformFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, NearestClampParams );
	this.displacementMapFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, LinearClampParams );
	this.normalMapFramebuffer = new THREE.WebGLRenderTarget( this.resolution, this.resolution, LinearClampParams );

M
r67  
Mr.doob 已提交
86 87
	// Define shaders and constant uniforms
	////////////////////////////////////////
M
r72  
Mr.doob 已提交
88

M
r67  
Mr.doob 已提交
89
	// 0 - The vertex shader used in all of the simulation steps
M
r72  
Mr.doob 已提交
90 91
	var fullscreeenVertexShader = THREE.ShaderLib[ "ocean_sim_vertex" ];

M
r67  
Mr.doob 已提交
92
	// 1 - Horizontal wave vertices used for FFT
M
r72  
Mr.doob 已提交
93 94 95
	var oceanHorizontalShader = THREE.ShaderLib[ "ocean_subtransform" ];
	var oceanHorizontalUniforms = THREE.UniformsUtils.clone( oceanHorizontalShader.uniforms );
	this.materialOceanHorizontal = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
96 97 98
		uniforms: oceanHorizontalUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
		fragmentShader: "#define HORIZONTAL \n" + oceanHorizontalShader.fragmentShader
M
r72  
Mr.doob 已提交
99
	} );
M
r67  
Mr.doob 已提交
100 101 102 103
	this.materialOceanHorizontal.uniforms.u_transformSize = { type: "f", value: this.resolution };
	this.materialOceanHorizontal.uniforms.u_subtransformSize = { type: "f", value: null };
	this.materialOceanHorizontal.uniforms.u_input = { type: "t", value: null };
	this.materialOceanHorizontal.depthTest = false;
M
r72  
Mr.doob 已提交
104

M
r67  
Mr.doob 已提交
105
	// 2 - Vertical wave vertices used for FFT
M
r72  
Mr.doob 已提交
106 107 108
	var oceanVerticalShader = THREE.ShaderLib[ "ocean_subtransform" ];
	var oceanVerticalUniforms = THREE.UniformsUtils.clone( oceanVerticalShader.uniforms );
	this.materialOceanVertical = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
109 110 111
		uniforms: oceanVerticalUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
		fragmentShader: oceanVerticalShader.fragmentShader
M
r72  
Mr.doob 已提交
112
	} );
M
r67  
Mr.doob 已提交
113 114 115 116
	this.materialOceanVertical.uniforms.u_transformSize = { type: "f", value: this.resolution };
	this.materialOceanVertical.uniforms.u_subtransformSize = { type: "f", value: null };
	this.materialOceanVertical.uniforms.u_input = { type: "t", value: null };
	this.materialOceanVertical.depthTest = false;
M
r72  
Mr.doob 已提交
117

M
r67  
Mr.doob 已提交
118
	// 3 - Initial spectrum used to generate height map
M
r72  
Mr.doob 已提交
119 120 121
	var initialSpectrumShader = THREE.ShaderLib[ "ocean_initial_spectrum" ];
	var initialSpectrumUniforms = THREE.UniformsUtils.clone( initialSpectrumShader.uniforms );
	this.materialInitialSpectrum = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
122 123
		uniforms: initialSpectrumUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
M
r72  
Mr.doob 已提交
124 125
		fragmentShader: initialSpectrumShader.fragmentShader
	} );
M
r67  
Mr.doob 已提交
126 127 128
	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;
M
r72  
Mr.doob 已提交
129

M
r67  
Mr.doob 已提交
130
	// 4 - Phases used to animate heightmap
M
r72  
Mr.doob 已提交
131 132 133
	var phaseShader = THREE.ShaderLib[ "ocean_phase" ];
	var phaseUniforms = THREE.UniformsUtils.clone( phaseShader.uniforms );
	this.materialPhase = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
134 135 136
		uniforms: phaseUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
		fragmentShader: phaseShader.fragmentShader
M
r72  
Mr.doob 已提交
137
	} );
M
r67  
Mr.doob 已提交
138 139
	this.materialPhase.uniforms.u_resolution = { type: "f", value: this.resolution };
	this.materialPhase.depthTest = false;
M
r72  
Mr.doob 已提交
140

M
r67  
Mr.doob 已提交
141
	// 5 - Shader used to update spectrum
M
r72  
Mr.doob 已提交
142 143 144
	var spectrumShader = THREE.ShaderLib[ "ocean_spectrum" ];
	var spectrumUniforms = THREE.UniformsUtils.clone( spectrumShader.uniforms );
	this.materialSpectrum = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
145 146 147
		uniforms: spectrumUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
		fragmentShader: spectrumShader.fragmentShader
M
r72  
Mr.doob 已提交
148
	} );
M
r67  
Mr.doob 已提交
149 150 151 152 153
	this.materialSpectrum.uniforms.u_initialSpectrum = { type: "t", value: null };
	this.materialSpectrum.uniforms.u_resolution = { type: "f", value: this.resolution };
	this.materialSpectrum.depthTest = false;

	// 6 - Shader used to update spectrum normals
M
r72  
Mr.doob 已提交
154 155 156
	var normalShader = THREE.ShaderLib[ "ocean_normals" ];
	var normalUniforms = THREE.UniformsUtils.clone( normalShader.uniforms );
	this.materialNormal = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
157 158 159
		uniforms: normalUniforms,
		vertexShader: fullscreeenVertexShader.vertexShader,
		fragmentShader: normalShader.fragmentShader
M
r72  
Mr.doob 已提交
160
	} );
M
r67  
Mr.doob 已提交
161 162 163 164 165
	this.materialNormal.uniforms.u_displacementMap = { type: "t", value: null };
	this.materialNormal.uniforms.u_resolution = { type: "f", value: this.resolution };
	this.materialNormal.depthTest = false;

	// 7 - Shader used to update normals
M
r72  
Mr.doob 已提交
166 167 168
	var oceanShader = THREE.ShaderLib[ "ocean_main" ];
	var oceanUniforms = THREE.UniformsUtils.clone( oceanShader.uniforms );
	this.materialOcean = new THREE.ShaderMaterial( {
M
r67  
Mr.doob 已提交
169 170 171
		uniforms: oceanUniforms,
		vertexShader: oceanShader.vertexShader,
		fragmentShader: oceanShader.fragmentShader
M
r72  
Mr.doob 已提交
172
	} );
M
r67  
Mr.doob 已提交
173 174
	// this.materialOcean.wireframe = true;
	this.materialOcean.uniforms.u_geometrySize = { type: "f", value: this.resolution };
M
r77  
Mr.doob 已提交
175 176
	this.materialOcean.uniforms.u_displacementMap = { type: "t", value: this.displacementMapFramebuffer.texture };
	this.materialOcean.uniforms.u_normalMap = { type: "t", value: this.normalMapFramebuffer.texture };
M
r72  
Mr.doob 已提交
177
	this.materialOcean.uniforms.u_oceanColor = { type: "v3", value: this.oceanColor };
M
r67  
Mr.doob 已提交
178 179 180 181 182 183 184 185 186 187 188 189 190 191
	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_exposure = { type: "f", value: this.exposure };

	// Disable blending to prevent default premultiplied alpha values
	this.materialOceanHorizontal.blending = 0;
	this.materialOceanVertical.blending = 0;
	this.materialInitialSpectrum.blending = 0;
	this.materialPhase.blending = 0;
	this.materialSpectrum.blending = 0;
	this.materialNormal.blending = 0;
	this.materialOcean.blending = 0;

	// Create the simulation plane
M
r69  
Mr.doob 已提交
192
	this.screenQuad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ) );
M
r72  
Mr.doob 已提交
193
	this.scene.add( this.screenQuad );
M
r67  
Mr.doob 已提交
194 195 196 197 198 199

	// Initialise spectrum data
	this.generateSeedPhaseTexture();

	// Generate the ocean mesh
	this.generateMesh();
M
r72  
Mr.doob 已提交
200

M
r67  
Mr.doob 已提交
201 202 203 204
};

THREE.Ocean.prototype.generateMesh = function () {

M
r69  
Mr.doob 已提交
205
	var geometry = new THREE.PlaneBufferGeometry( this.geometrySize, this.geometrySize, this.geometryResolution, this.geometryResolution );
M
r67  
Mr.doob 已提交
206

M
r72  
Mr.doob 已提交
207
	geometry.rotateX( - Math.PI / 2 );
M
r67  
Mr.doob 已提交
208 209

	this.oceanMesh = new THREE.Mesh( geometry, this.materialOcean );
M
r72  
Mr.doob 已提交
210

M
r67  
Mr.doob 已提交
211 212 213
};

THREE.Ocean.prototype.render = function () {
M
r72  
Mr.doob 已提交
214

M
r67  
Mr.doob 已提交
215
	this.scene.overrideMaterial = null;
M
r72  
Mr.doob 已提交
216 217

	if ( this.changed )
M
r67  
Mr.doob 已提交
218
		this.renderInitialSpectrum();
M
r72  
Mr.doob 已提交
219

M
r67  
Mr.doob 已提交
220 221 222 223 224
	this.renderWavePhase();
	this.renderSpectrum();
	this.renderSpectrumFFT();
	this.renderNormalMap();
	this.scene.overrideMaterial = null;
M
r72  
Mr.doob 已提交
225

M
r67  
Mr.doob 已提交
226 227 228
};

THREE.Ocean.prototype.generateSeedPhaseTexture = function() {
M
r72  
Mr.doob 已提交
229

M
r67  
Mr.doob 已提交
230 231
	// Setup the seed texture
	this.pingPhase = true;
M
r72  
Mr.doob 已提交
232 233 234 235 236 237 238 239 240 241
	var phaseArray = new window.Float32Array( this.resolution * this.resolution * 4 );
	for ( var i = 0; i < this.resolution; i ++ ) {

		for ( var j = 0; j < this.resolution; j ++ ) {

			phaseArray[ i * this.resolution * 4 + j * 4 ] =  Math.random() * 2.0 * Math.PI;
			phaseArray[ i * this.resolution * 4 + j * 4 + 1 ] = 0.0;
			phaseArray[ i * this.resolution * 4 + j * 4 + 2 ] = 0.0;
			phaseArray[ i * this.resolution * 4 + j * 4 + 3 ] = 0.0;

M
r67  
Mr.doob 已提交
242
		}
M
r72  
Mr.doob 已提交
243

M
r67  
Mr.doob 已提交
244
	}
M
r72  
Mr.doob 已提交
245 246

	this.pingPhaseTexture = new THREE.DataTexture( phaseArray, this.resolution, this.resolution, THREE.RGBAFormat );
M
r67  
Mr.doob 已提交
247 248 249 250
	this.pingPhaseTexture.wrapS = THREE.ClampToEdgeWrapping;
	this.pingPhaseTexture.wrapT = THREE.ClampToEdgeWrapping;
	this.pingPhaseTexture.type = THREE.FloatType;
	this.pingPhaseTexture.needsUpdate = true;
M
r72  
Mr.doob 已提交
251

M
r67  
Mr.doob 已提交
252 253 254
};

THREE.Ocean.prototype.renderInitialSpectrum = function () {
M
r72  
Mr.doob 已提交
255

M
r67  
Mr.doob 已提交
256 257 258
	this.scene.overrideMaterial = this.materialInitialSpectrum;
	this.materialInitialSpectrum.uniforms.u_wind.value.set( this.windX, this.windY );
	this.materialInitialSpectrum.uniforms.u_size.value = this.size;
M
r72  
Mr.doob 已提交
259 260
	this.renderer.render( this.scene, this.oceanCamera, this.initialSpectrumFramebuffer, true );

M
r67  
Mr.doob 已提交
261 262 263
};

THREE.Ocean.prototype.renderWavePhase = function () {
M
r72  
Mr.doob 已提交
264

M
r67  
Mr.doob 已提交
265 266
	this.scene.overrideMaterial = this.materialPhase;
	this.screenQuad.material = this.materialPhase;
M
r72  
Mr.doob 已提交
267 268
	if ( this.initial ) {

M
r67  
Mr.doob 已提交
269 270
		this.materialPhase.uniforms.u_phases.value = this.pingPhaseTexture;
		this.initial = false;
M
r72  
Mr.doob 已提交
271

M
r67  
Mr.doob 已提交
272
	}else {
M
r72  
Mr.doob 已提交
273

M
r77  
Mr.doob 已提交
274
		this.materialPhase.uniforms.u_phases.value = this.pingPhase ? this.pingPhaseFramebuffer.texture : this.pongPhaseFramebuffer.texture;
M
r72  
Mr.doob 已提交
275

M
r67  
Mr.doob 已提交
276 277 278
	}
	this.materialPhase.uniforms.u_deltaTime.value = this.deltaTime;
	this.materialPhase.uniforms.u_size.value = this.size;
M
r72  
Mr.doob 已提交
279 280 281
	this.renderer.render( this.scene, this.oceanCamera, this.pingPhase ? this.pongPhaseFramebuffer : this.pingPhaseFramebuffer );
	this.pingPhase = ! this.pingPhase;

M
r67  
Mr.doob 已提交
282 283 284
};

THREE.Ocean.prototype.renderSpectrum = function () {
M
r72  
Mr.doob 已提交
285

M
r67  
Mr.doob 已提交
286
	this.scene.overrideMaterial = this.materialSpectrum;
M
r77  
Mr.doob 已提交
287 288 289 290
	this.materialSpectrum.uniforms.u_initialSpectrum.value = this.initialSpectrumFramebuffer.texture;
	this.materialSpectrum.uniforms.u_phases.value = this.pingPhase ? this.pingPhaseFramebuffer.texture : this.pongPhaseFramebuffer.texture;
	this.materialSpectrum.uniforms.u_choppiness.value = this.choppiness;
	this.materialSpectrum.uniforms.u_size.value = this.size;
M
r72  
Mr.doob 已提交
291 292
	this.renderer.render( this.scene, this.oceanCamera, this.spectrumFramebuffer );

M
r67  
Mr.doob 已提交
293 294 295
};

THREE.Ocean.prototype.renderSpectrumFFT = function() {
M
r72  
Mr.doob 已提交
296

M
r67  
Mr.doob 已提交
297
	// GPU FFT using Stockham formulation
M
r72  
Mr.doob 已提交
298 299
	var iterations = Math.log( this.resolution ) / Math.log( 2 ); // log2

M
r67  
Mr.doob 已提交
300 301
	this.scene.overrideMaterial = this.materialOceanHorizontal;

M
r72  
Mr.doob 已提交
302 303 304 305
	for ( var i = 0; i < iterations; i ++ ) {

		if ( i === 0 ) {

M
r77  
Mr.doob 已提交
306
			this.materialOceanHorizontal.uniforms.u_input.value = this.spectrumFramebuffer.texture;
M
r72  
Mr.doob 已提交
307 308 309 310 311
			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );

		} else if ( i % 2 === 1 ) {

M
r77  
Mr.doob 已提交
312
			this.materialOceanHorizontal.uniforms.u_input.value = this.pingTransformFramebuffer.texture;
M
r72  
Mr.doob 已提交
313 314 315 316 317
			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.pongTransformFramebuffer );

		} else {

M
r77  
Mr.doob 已提交
318
			this.materialOceanHorizontal.uniforms.u_input.value = this.pongTransformFramebuffer.texture;
M
r72  
Mr.doob 已提交
319 320 321
			this.materialOceanHorizontal.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );

M
r67  
Mr.doob 已提交
322
		}
M
r72  
Mr.doob 已提交
323

M
r67  
Mr.doob 已提交
324 325
	}
	this.scene.overrideMaterial = this.materialOceanVertical;
M
r72  
Mr.doob 已提交
326 327 328 329
	for ( var i = iterations; i < iterations * 2; i ++ ) {

		if ( i === iterations * 2 - 1 ) {

M
r77  
Mr.doob 已提交
330
			this.materialOceanVertical.uniforms.u_input.value = ( iterations % 2 === 0 ) ? this.pingTransformFramebuffer.texture : this.pongTransformFramebuffer.texture;
M
r72  
Mr.doob 已提交
331 332 333 334 335
			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.displacementMapFramebuffer );

		} else if ( i % 2 === 1 ) {

M
r77  
Mr.doob 已提交
336
			this.materialOceanVertical.uniforms.u_input.value = this.pingTransformFramebuffer.texture;
M
r72  
Mr.doob 已提交
337 338 339 340 341
			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.pongTransformFramebuffer );

		} else {

M
r77  
Mr.doob 已提交
342
			this.materialOceanVertical.uniforms.u_input.value = this.pongTransformFramebuffer.texture;
M
r72  
Mr.doob 已提交
343 344 345
			this.materialOceanVertical.uniforms.u_subtransformSize.value = Math.pow( 2, ( i % ( iterations ) ) + 1 );
			this.renderer.render( this.scene, this.oceanCamera, this.pingTransformFramebuffer );

M
r67  
Mr.doob 已提交
346
		}
M
r72  
Mr.doob 已提交
347

M
r67  
Mr.doob 已提交
348
	}
M
r72  
Mr.doob 已提交
349

M
r67  
Mr.doob 已提交
350 351 352
};

THREE.Ocean.prototype.renderNormalMap = function () {
M
r72  
Mr.doob 已提交
353

M
r67  
Mr.doob 已提交
354
	this.scene.overrideMaterial = this.materialNormal;
M
r72  
Mr.doob 已提交
355
	if ( this.changed ) this.materialNormal.uniforms.u_size.value = this.size;
M
r77  
Mr.doob 已提交
356
	this.materialNormal.uniforms.u_displacementMap.value = this.displacementMapFramebuffer.texture;
M
r72  
Mr.doob 已提交
357 358
	this.renderer.render( this.scene, this.oceanCamera, this.normalMapFramebuffer, true );

M
r69  
Mr.doob 已提交
359
};