Skip to content

Commit f62b2a8

Browse files
authored
Merge pull request #15500 from Oletus/cleanup-addressing-uniforms-in-examples
Always use strings for uniform names in examples
2 parents a6d7b3e + c3144a2 commit f62b2a8

36 files changed

+312
-312
lines changed

examples/js/objects/Fire.js

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ THREE.Fire = function ( geometry, options ) {
5858

5959
}
6060

61-
this.sourceMaterial.uniforms.sourceMap.value = this.internalSource;
61+
this.sourceMaterial.uniforms[ "sourceMap" ].value = this.internalSource;
6262
this.sourceMaterial.needsUpdate = true;
6363

6464
return this.sourceData;
@@ -121,7 +121,7 @@ THREE.Fire = function ( geometry, options ) {
121121
// (0 -> 127 = 0.0 -> 1.0, 128 -> 255 = -1.0 -> 0.0 )
122122
this.setSourceMap = function ( texture ) {
123123

124-
this.sourceMaterial.uniforms.sourceMap.value = texture;
124+
this.sourceMaterial.uniforms[ "sourceMap" ].value = texture;
125125

126126
};
127127

@@ -190,8 +190,8 @@ THREE.Fire = function ( geometry, options ) {
190190
transparent: false
191191
} );
192192

193-
this.diffuseMaterial.uniforms.oneOverWidth.value = oneOverWidth;
194-
this.diffuseMaterial.uniforms.oneOverHeight.value = oneOverHeight;
193+
this.diffuseMaterial.uniforms[ "oneOverWidth" ].value = oneOverWidth;
194+
this.diffuseMaterial.uniforms[ "oneOverHeight" ].value = oneOverHeight;
195195

196196
this.diffuseMesh = new THREE.Mesh( this.fieldGeometry, this.diffuseMaterial );
197197
this.fieldScene.add( this.diffuseMesh );
@@ -206,8 +206,8 @@ THREE.Fire = function ( geometry, options ) {
206206
transparent: false
207207
} );
208208

209-
this.driftMaterial.uniforms.oneOverWidth.value = oneOverWidth;
210-
this.driftMaterial.uniforms.oneOverHeight.value = oneOverHeight;
209+
this.driftMaterial.uniforms[ "oneOverWidth" ].value = oneOverWidth;
210+
this.driftMaterial.uniforms[ "oneOverHeight" ].value = oneOverHeight;
211211

212212
this.driftMesh = new THREE.Mesh( this.fieldGeometry, this.driftMaterial );
213213
this.fieldScene.add( this.driftMesh );
@@ -222,8 +222,8 @@ THREE.Fire = function ( geometry, options ) {
222222
transparent: false
223223
} );
224224

225-
this.projMaterial1.uniforms.oneOverWidth.value = oneOverWidth;
226-
this.projMaterial1.uniforms.oneOverHeight.value = oneOverHeight;
225+
this.projMaterial1.uniforms[ "oneOverWidth" ].value = oneOverWidth;
226+
this.projMaterial1.uniforms[ "oneOverHeight" ].value = oneOverHeight;
227227

228228
this.projMesh1 = new THREE.Mesh( this.fieldGeometry, this.projMaterial1 );
229229
this.fieldScene.add( this.projMesh1 );
@@ -239,8 +239,8 @@ THREE.Fire = function ( geometry, options ) {
239239
} );
240240

241241

242-
this.projMaterial2.uniforms.oneOverWidth.value = oneOverWidth;
243-
this.projMaterial2.uniforms.oneOverHeight.value = oneOverHeight;
242+
this.projMaterial2.uniforms[ "oneOverWidth" ].value = oneOverWidth;
243+
this.projMaterial2.uniforms[ "oneOverHeight" ].value = oneOverHeight;
244244

245245
this.projMesh2 = new THREE.Mesh( this.fieldGeometry, this.projMaterial2 );
246246
this.fieldScene.add( this.projMesh2 );
@@ -256,8 +256,8 @@ THREE.Fire = function ( geometry, options ) {
256256
} );
257257

258258

259-
this.projMaterial3.uniforms.oneOverWidth.value = oneOverWidth;
260-
this.projMaterial3.uniforms.oneOverHeight.value = oneOverHeight;
259+
this.projMaterial3.uniforms[ "oneOverWidth" ].value = oneOverWidth;
260+
this.projMaterial3.uniforms[ "oneOverHeight" ].value = oneOverHeight;
261261

262262
this.projMesh3 = new THREE.Mesh( this.fieldGeometry, this.projMaterial3 );
263263
this.fieldScene.add( this.projMesh3 );
@@ -280,31 +280,31 @@ THREE.Fire = function ( geometry, options ) {
280280
transparent: true
281281
} );
282282

283-
this.material.uniforms.densityMap.value = this.field1.texture;
283+
this.material.uniforms[ "densityMap" ].value = this.field1.texture;
284284

285285
this.configShaders = function ( dt ) {
286286

287-
this.diffuseMaterial.uniforms.diffuse.value = dt * 0.05 * this.diffuse;
288-
this.diffuseMaterial.uniforms.viscosity.value = dt * 0.05 * this.viscosity;
289-
this.diffuseMaterial.uniforms.expansion.value = Math.exp( this.expansion * - 1.0 );
290-
this.diffuseMaterial.uniforms.swirl.value = Math.exp( this.swirl * - 0.1 );
291-
this.diffuseMaterial.uniforms.drag.value = Math.exp( this.drag * - 0.1 );
292-
this.diffuseMaterial.uniforms.burnRate.value = this.burnRate * dt * 0.01;
293-
this.driftMaterial.uniforms.windVector.value = this.windVector;
294-
this.driftMaterial.uniforms.airSpeed.value = dt * this.airSpeed * 0.001 * textureHeight;
295-
this.material.uniforms.color1.value = this.color1;
296-
this.material.uniforms.color2.value = this.color2;
297-
this.material.uniforms.color3.value = this.color3;
298-
this.material.uniforms.colorBias.value = this.colorBias;
287+
this.diffuseMaterial.uniforms[ "diffuse" ].value = dt * 0.05 * this.diffuse;
288+
this.diffuseMaterial.uniforms[ "viscosity" ].value = dt * 0.05 * this.viscosity;
289+
this.diffuseMaterial.uniforms[ "expansion" ].value = Math.exp( this.expansion * - 1.0 );
290+
this.diffuseMaterial.uniforms[ "swirl" ].value = Math.exp( this.swirl * - 0.1 );
291+
this.diffuseMaterial.uniforms[ "drag" ].value = Math.exp( this.drag * - 0.1 );
292+
this.diffuseMaterial.uniforms[ "burnRate" ].value = this.burnRate * dt * 0.01;
293+
this.driftMaterial.uniforms[ "windVector" ].value = this.windVector;
294+
this.driftMaterial.uniforms[ "airSpeed" ].value = dt * this.airSpeed * 0.001 * textureHeight;
295+
this.material.uniforms[ "color1" ].value = this.color1;
296+
this.material.uniforms[ "color2" ].value = this.color2;
297+
this.material.uniforms[ "color3" ].value = this.color3;
298+
this.material.uniforms[ "colorBias" ].value = this.colorBias;
299299

300300
};
301301

302302
this.clearDiffuse = function () {
303303

304-
this.diffuseMaterial.uniforms.expansion.value = 1.0;
305-
this.diffuseMaterial.uniforms.swirl.value = 1.0;
306-
this.diffuseMaterial.uniforms.drag.value = 1.0;
307-
this.diffuseMaterial.uniforms.burnRate.value = 0.0;
304+
this.diffuseMaterial.uniforms[ "expansion" ].value = 1.0;
305+
this.diffuseMaterial.uniforms[ "swirl" ].value = 1.0;
306+
this.diffuseMaterial.uniforms[ "drag" ].value = 1.0;
307+
this.diffuseMaterial.uniforms[ "burnRate" ].value = 0.0;
308308

309309
};
310310

@@ -340,7 +340,7 @@ THREE.Fire = function ( geometry, options ) {
340340

341341
this.sourceMesh.visible = true;
342342

343-
this.sourceMaterial.uniforms.densityMap.value = this.field0.texture;
343+
this.sourceMaterial.uniforms[ "densityMap" ].value = this.field0.texture;
344344

345345
renderer.render( this.fieldScene, this.orthoCamera, this.field1 );
346346

@@ -354,7 +354,7 @@ THREE.Fire = function ( geometry, options ) {
354354

355355
this.diffuseMesh.visible = true;
356356

357-
this.diffuseMaterial.uniforms.densityMap.value = this.field0.texture;
357+
this.diffuseMaterial.uniforms[ "densityMap" ].value = this.field0.texture;
358358

359359
renderer.render( this.fieldScene, this.orthoCamera, this.field1 );
360360

@@ -368,7 +368,7 @@ THREE.Fire = function ( geometry, options ) {
368368

369369
this.driftMesh.visible = true;
370370

371-
this.driftMaterial.uniforms.densityMap.value = this.field0.texture;
371+
this.driftMaterial.uniforms[ "densityMap" ].value = this.field0.texture;
372372

373373
renderer.render( this.fieldScene, this.orthoCamera, this.field1 );
374374

@@ -384,13 +384,13 @@ THREE.Fire = function ( geometry, options ) {
384384

385385
this.projMesh1.visible = true;
386386

387-
this.projMaterial1.uniforms.densityMap.value = this.field0.texture;
387+
this.projMaterial1.uniforms[ "densityMap" ].value = this.field0.texture;
388388

389389
renderer.render( this.fieldScene, this.orthoCamera, this.fieldProj );
390390

391391
this.projMesh1.visible = false;
392392

393-
this.projMaterial2.uniforms.densityMap.value = this.fieldProj.texture;
393+
this.projMaterial2.uniforms[ "densityMap" ].value = this.fieldProj.texture;
394394

395395
// Projection pass 2
396396

@@ -404,14 +404,14 @@ THREE.Fire = function ( geometry, options ) {
404404
this.field1 = this.fieldProj;
405405
this.fieldProj = temp;
406406

407-
this.projMaterial2.uniforms.densityMap.value = this.fieldProj.texture;
407+
this.projMaterial2.uniforms[ "densityMap" ].value = this.fieldProj.texture;
408408

409409
}
410410

411411
this.projMesh2.visible = false;
412412

413-
this.projMaterial3.uniforms.densityMap.value = this.field0.texture;
414-
this.projMaterial3.uniforms.projMap.value = this.fieldProj.texture;
413+
this.projMaterial3.uniforms[ "densityMap" ].value = this.field0.texture;
414+
this.projMaterial3.uniforms[ "projMap" ].value = this.fieldProj.texture;
415415

416416
// Projection pass 3
417417

examples/js/objects/Lensflare.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ THREE.Lensflare = function () {
199199
// render pink quad
200200

201201
var uniforms = material1a.uniforms;
202-
uniforms.scale.value = scale;
203-
uniforms.screenPosition.value = positionScreen;
202+
uniforms[ "scale" ].value = scale;
203+
uniforms[ "screenPosition" ].value = positionScreen;
204204

205205
renderer.renderBufferDirect( camera, null, geometry, material1a, mesh1, null );
206206

@@ -211,8 +211,8 @@ THREE.Lensflare = function () {
211211
// restore graphics
212212

213213
var uniforms = material1b.uniforms;
214-
uniforms.scale.value = scale;
215-
uniforms.screenPosition.value = positionScreen;
214+
uniforms[ "scale" ].value = scale;
215+
uniforms[ "screenPosition" ].value = positionScreen;
216216

217217
renderer.renderBufferDirect( camera, null, geometry, material1b, mesh1, null );
218218

@@ -227,15 +227,15 @@ THREE.Lensflare = function () {
227227

228228
var uniforms = material2.uniforms;
229229

230-
uniforms.color.value.copy( element.color );
231-
uniforms.map.value = element.texture;
232-
uniforms.screenPosition.value.x = positionScreen.x + vecX * element.distance;
233-
uniforms.screenPosition.value.y = positionScreen.y + vecY * element.distance;
230+
uniforms[ "color" ].value.copy( element.color );
231+
uniforms[ "map" ].value = element.texture;
232+
uniforms[ "screenPosition" ].value.x = positionScreen.x + vecX * element.distance;
233+
uniforms[ "screenPosition" ].value.y = positionScreen.y + vecY * element.distance;
234234

235235
var size = element.size / viewport.w;
236236
var invAspect = viewport.w / viewport.z;
237237

238-
uniforms.scale.value.set( size * invAspect, size );
238+
uniforms[ "scale" ].value.set( size * invAspect, size );
239239

240240
material2.uniformsNeedUpdate = true;
241241

examples/js/objects/Reflector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ THREE.Reflector = function ( geometry, options ) {
5858
vertexShader: shader.vertexShader
5959
} );
6060

61-
material.uniforms.tDiffuse.value = renderTarget.texture;
62-
material.uniforms.color.value = color;
63-
material.uniforms.textureMatrix.value = textureMatrix;
61+
material.uniforms[ "tDiffuse" ].value = renderTarget.texture;
62+
material.uniforms[ "color" ].value = color;
63+
material.uniforms[ "textureMatrix" ].value = textureMatrix;
6464

6565
this.material = material;
6666
this.renderOrder = - Infinity; // render first

examples/js/objects/Refractor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ THREE.Refractor = function ( geometry, options ) {
5656
transparent: true // ensures, refractors are drawn from farthest to closest
5757
} );
5858

59-
this.material.uniforms.color.value = color;
60-
this.material.uniforms.tDiffuse.value = renderTarget.texture;
61-
this.material.uniforms.textureMatrix.value = textureMatrix;
59+
this.material.uniforms[ "color" ].value = color;
60+
this.material.uniforms[ "tDiffuse" ].value = renderTarget.texture;
61+
this.material.uniforms[ "textureMatrix" ].value = textureMatrix;
6262

6363
// functions
6464

examples/js/objects/Sky.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ THREE.Sky.prototype = Object.create( THREE.Mesh.prototype );
3434
THREE.Sky.SkyShader = {
3535

3636
uniforms: {
37-
luminance: { value: 1 },
38-
turbidity: { value: 2 },
39-
rayleigh: { value: 1 },
40-
mieCoefficient: { value: 0.005 },
41-
mieDirectionalG: { value: 0.8 },
42-
sunPosition: { value: new THREE.Vector3() }
37+
"luminance": { value: 1 },
38+
"turbidity": { value: 2 },
39+
"rayleigh": { value: 1 },
40+
"mieCoefficient": { value: 0.005 },
41+
"mieDirectionalG": { value: 0.8 },
42+
"sunPosition": { value: new THREE.Vector3() }
4343
},
4444

4545
vertexShader: [

examples/js/objects/Water.js

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ THREE.Water = function ( geometry, options ) {
6969
THREE.UniformsLib[ 'fog' ],
7070
THREE.UniformsLib[ 'lights' ],
7171
{
72-
normalSampler: { value: null },
73-
mirrorSampler: { value: null },
74-
alpha: { value: 1.0 },
75-
time: { value: 0.0 },
76-
size: { value: 1.0 },
77-
distortionScale: { value: 20.0 },
78-
textureMatrix: { value: new THREE.Matrix4() },
79-
sunColor: { value: new THREE.Color( 0x7F7F7F ) },
80-
sunDirection: { value: new THREE.Vector3( 0.70707, 0.70707, 0 ) },
81-
eye: { value: new THREE.Vector3() },
82-
waterColor: { value: new THREE.Color( 0x555555 ) }
72+
"normalSampler": { value: null },
73+
"mirrorSampler": { value: null },
74+
"alpha": { value: 1.0 },
75+
"time": { value: 0.0 },
76+
"size": { value: 1.0 },
77+
"distortionScale": { value: 20.0 },
78+
"textureMatrix": { value: new THREE.Matrix4() },
79+
"sunColor": { value: new THREE.Color( 0x7F7F7F ) },
80+
"sunDirection": { value: new THREE.Vector3( 0.70707, 0.70707, 0 ) },
81+
"eye": { value: new THREE.Vector3() },
82+
"waterColor": { value: new THREE.Color( 0x555555 ) }
8383
}
8484
] ),
8585

@@ -190,17 +190,17 @@ THREE.Water = function ( geometry, options ) {
190190
fog: fog
191191
} );
192192

193-
material.uniforms.mirrorSampler.value = renderTarget.texture;
194-
material.uniforms.textureMatrix.value = textureMatrix;
195-
material.uniforms.alpha.value = alpha;
196-
material.uniforms.time.value = time;
197-
material.uniforms.normalSampler.value = normalSampler;
198-
material.uniforms.sunColor.value = sunColor;
199-
material.uniforms.waterColor.value = waterColor;
200-
material.uniforms.sunDirection.value = sunDirection;
201-
material.uniforms.distortionScale.value = distortionScale;
202-
203-
material.uniforms.eye.value = eye;
193+
material.uniforms[ "mirrorSampler" ].value = renderTarget.texture;
194+
material.uniforms[ "textureMatrix" ].value = textureMatrix;
195+
material.uniforms[ "alpha" ].value = alpha;
196+
material.uniforms[ "time" ].value = time;
197+
material.uniforms[ "normalSampler" ].value = normalSampler;
198+
material.uniforms[ "sunColor" ].value = sunColor;
199+
material.uniforms[ "waterColor" ].value = waterColor;
200+
material.uniforms[ "sunDirection" ].value = sunDirection;
201+
material.uniforms[ "distortionScale" ].value = distortionScale;
202+
203+
material.uniforms[ "eye" ].value = eye;
204204

205205
scope.material = material;
206206

examples/js/objects/Water2.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ THREE.Water = function ( geometry, options ) {
8585
if ( flowMap !== undefined ) {
8686

8787
this.material.defines.USE_FLOWMAP = '';
88-
this.material.uniforms.tFlowMap = {
88+
this.material.uniforms[ "tFlowMap" ] = {
8989
type: 't',
9090
value: flowMap
9191
};
9292

9393
} else {
9494

95-
this.material.uniforms.flowDirection = {
95+
this.material.uniforms[ "flowDirection" ] = {
9696
type: 'v2',
9797
value: flowDirection
9898
};
@@ -104,23 +104,23 @@ THREE.Water = function ( geometry, options ) {
104104
normalMap0.wrapS = normalMap0.wrapT = THREE.RepeatWrapping;
105105
normalMap1.wrapS = normalMap1.wrapT = THREE.RepeatWrapping;
106106

107-
this.material.uniforms.tReflectionMap.value = reflector.getRenderTarget().texture;
108-
this.material.uniforms.tRefractionMap.value = refractor.getRenderTarget().texture;
109-
this.material.uniforms.tNormalMap0.value = normalMap0;
110-
this.material.uniforms.tNormalMap1.value = normalMap1;
107+
this.material.uniforms[ "tReflectionMap" ].value = reflector.getRenderTarget().texture;
108+
this.material.uniforms[ "tRefractionMap" ].value = refractor.getRenderTarget().texture;
109+
this.material.uniforms[ "tNormalMap0" ].value = normalMap0;
110+
this.material.uniforms[ "tNormalMap1" ].value = normalMap1;
111111

112112
// water
113113

114-
this.material.uniforms.color.value = color;
115-
this.material.uniforms.reflectivity.value = reflectivity;
116-
this.material.uniforms.textureMatrix.value = textureMatrix;
114+
this.material.uniforms[ "color" ].value = color;
115+
this.material.uniforms[ "reflectivity" ].value = reflectivity;
116+
this.material.uniforms[ "textureMatrix" ].value = textureMatrix;
117117

118118
// inital values
119119

120-
this.material.uniforms.config.value.x = 0; // flowMapOffset0
121-
this.material.uniforms.config.value.y = halfCycle; // flowMapOffset1
122-
this.material.uniforms.config.value.z = halfCycle; // halfCycle
123-
this.material.uniforms.config.value.w = scale; // scale
120+
this.material.uniforms[ "config" ].value.x = 0; // flowMapOffset0
121+
this.material.uniforms[ "config" ].value.y = halfCycle; // flowMapOffset1
122+
this.material.uniforms[ "config" ].value.z = halfCycle; // halfCycle
123+
this.material.uniforms[ "config" ].value.w = scale; // scale
124124

125125
// functions
126126

@@ -142,7 +142,7 @@ THREE.Water = function ( geometry, options ) {
142142
function updateFlow() {
143143

144144
var delta = clock.getDelta();
145-
var config = scope.material.uniforms.config;
145+
var config = scope.material.uniforms[ "config" ];
146146

147147
config.value.x += flowSpeed * delta; // flowMapOffset0
148148
config.value.y = config.value.x + halfCycle; // flowMapOffset1

0 commit comments

Comments
 (0)