Skip to content

Commit 1dd9f2a

Browse files
committed
Fixed dirtiness logic in WebGLRenderer and the automatically detected errors
Also improved the example and added a thumbnail for it.
1 parent 2075f87 commit 1dd9f2a

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

examples/files.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"webgl_geometry_spline_editor",
4040
"webgl_geometry_teapot",
4141
"webgl_geometry_terrain",
42+
"webgl_geometry_terrain_fog_types",
4243
"webgl_geometry_terrain_raycast",
4344
"webgl_geometry_text",
4445
"webgl_geometry_text_shapes",
14.8 KB
Loading

examples/webgl_geometry_terrain_fog_types.html

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
background-color: #efd1b5;
1111
color: #61443e;
1212
}
13+
body, #container {
14+
overflow: hidden;
15+
}
1316
a {
1417
color: #a06851;
1518
}
@@ -40,6 +43,7 @@
4043
import Stats from 'three/addons/libs/stats.module.js';
4144
import { GUI } from './jsm/libs/lil-gui.module.min.js';
4245

46+
import { FirstPersonControls } from 'three/addons/controls/FirstPersonControls.js';
4347
import { ImprovedNoise } from 'three/addons/math/ImprovedNoise.js';
4448

4549
let container, stats;
@@ -53,7 +57,7 @@
5357

5458
var params = {
5559
"Fog type": "DensityFog",
56-
"Fog color": "#efd1b5",
60+
"Fog color": "#b7dc50",
5761
}
5862

5963
init();
@@ -63,21 +67,21 @@
6367

6468
container = document.getElementById( 'container' );
6569

66-
camera = new THREE.PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 1, 10000 );
70+
camera = new THREE.PerspectiveCamera( 40, window.innerWidth / window.innerHeight, 1, 10000 );
6771

6872
scene = new THREE.Scene();
6973
scene.background = new THREE.Color();
7074

7175
fogs = {
7276
"RangeFog": new THREE.RangeFog(),
73-
"DensityFog": new THREE.DensityFog(),
74-
}
77+
"DensityFog": new THREE.DensityFog(undefined, 0.001, false),
78+
};
7579

7680
setFogColor( params[ "Fog color" ] );
7781

7882
var data = generateHeight( worldWidth, worldDepth );
7983

80-
camera.position.y = data[ 0.5 * worldWidth + 0.5 * worldDepth * worldWidth ] * 10 + 500;
84+
camera.position.y = data[ 0.5 * worldWidth + 0.5 * worldDepth * worldWidth ] * 10 + 300;
8185

8286
var geometry = new THREE.PlaneGeometry( 7500, 7500, worldWidth - 1, worldDepth - 1 );
8387
geometry.rotateX( - Math.PI / 2 );
@@ -102,6 +106,10 @@
102106
renderer.setSize( window.innerWidth, window.innerHeight );
103107
container.appendChild( renderer.domElement );
104108

109+
controls = new FirstPersonControls( camera, renderer.domElement );
110+
controls.movementSpeed = 100;
111+
controls.lookSpeed = 0.03;
112+
105113
stats = new Stats();
106114
container.appendChild( stats.dom );
107115

@@ -121,7 +129,7 @@
121129
fogGuis = {
122130
"RangeFog": gui.addFolder( "RangeFog" ),
123131
"DensityFog": gui.addFolder( "DensityFog" )
124-
}
132+
};
125133

126134
setFogType( params[ "Fog type" ] );
127135

@@ -167,6 +175,8 @@
167175

168176
renderer.setSize( window.innerWidth, window.innerHeight );
169177

178+
controls.handleResize();
179+
170180
}
171181

172182
function generateHeight( width, height ) {
@@ -271,6 +281,7 @@
271281

272282
function render() {
273283

284+
controls.update( clock.getDelta() );
274285
renderer.render( scene, camera );
275286

276287
}

src/renderers/WebGLRenderer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ class WebGLRenderer {
13941394

13951395
materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
13961396
materialProperties.fog = scene.fog;
1397-
materialProperties.fogSquared = scene.fog.squared || null;
1397+
materialProperties.fogSquared = ( scene.fog && scene.fog.squared ) || null;
13981398
materialProperties.envMap = ( material.isMeshStandardMaterial ? cubeuvmaps : cubemaps ).get( material.envMap || materialProperties.environment );
13991399

14001400
if ( programs === undefined ) {
@@ -1583,7 +1583,7 @@ class WebGLRenderer {
15831583

15841584
needsProgramChange = true;
15851585

1586-
} else if ( material.fog === true && ( materialProperties.fog !== fog || materialProperties.fogSquared !== fog.squared ) ) {
1586+
} else if ( material.fog === true && ( materialProperties.fog !== fog || ( fog && ( materialProperties.fogSquared !== fog.squared ) ) ) ) {
15871587

15881588
needsProgramChange = true;
15891589

test/unit/src/scenes/DensityFog.tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export default QUnit.module( 'Scenes', () => {
2020
assert.ok( object_color, 'Can instantiate a DensityFog with color.' );
2121

2222
// color, density
23-
const object_all = new DensityFog( 0xffffff, 0.00030 );
24-
assert.ok( object_all, 'Can instantiate a DensityFog with color, density.' );
23+
const object_color_density = new DensityFog( 0xffffff, 0.00030 );
24+
assert.ok( object_color_density, 'Can instantiate a DensityFog with color, density.' );
2525

26-
// color, density
26+
// color, density, squared
2727
const object_all = new DensityFog( 0xffffff, 0.00030, false );
2828
assert.ok( object_all, 'Can instantiate a DensityFog with color, density, squared == false.' );
2929

0 commit comments

Comments
 (0)