Skip to content

Commit ebaa0d6

Browse files
bhoustonmrdoob
authored andcommitted
remove ability to set depth formula on MeshDepthMaterial. (mrdoob#8602)
* remove ability to set depth formula on MeshDepthMaterial. * remove depth formulas
1 parent dfaec12 commit ebaa0d6

10 files changed

Lines changed: 24 additions & 123 deletions

File tree

examples/webgl_depth_texture.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
font-weight: bold;
2121
pointer-events: auto;
2222
}
23-
23+
2424
canvas {
2525
position: absolute;
2626
top: 0;
@@ -66,8 +66,8 @@
6666

6767
float readDepth (sampler2D depthSampler, vec2 coord) {
6868
float fragCoordZ = texture2D(depthSampler, coord).x;
69-
float viewZ = invClipZToViewZ( fragCoordZ, cameraNear, cameraFar );
70-
return viewZToLinearClipZ( viewZ, cameraNear, cameraFar );
69+
float viewZ = perspectiveDepthToViewZ( fragCoordZ, cameraNear, cameraFar );
70+
return viewZToOrthoDepth( viewZ, cameraNear, cameraFar );
7171
}
7272

7373
void main() {
@@ -86,11 +86,11 @@
8686
<a href="http://threejs.org" target="_blank">threejs</a> - WebGL - Depth Texture<br/>
8787
Stores render target depth in a texture attachment.<br/>
8888
Created by <a href="http://twitter.com/mattdesl" target="_blank">@mattdesl</a>.
89-
89+
9090
<div id="error" style="display: none;">
9191
Your browser does not support <strong>WEBGL_depth_texture</strong>.<br/><br/>
9292
This demo will not work.
93-
</div>
93+
</div>
9494
</div>
9595

9696
<script src="../build/three.js"></script>
@@ -110,7 +110,7 @@
110110
function init() {
111111

112112
var canvas = document.querySelector('canvas');
113-
var gl;
113+
var gl;
114114
try {
115115

116116
gl = canvas.getContext('webgl2');
@@ -121,7 +121,7 @@
121121

122122
}
123123
var isWebGL2 = Boolean(gl);
124-
124+
125125
renderer = new THREE.WebGLRenderer( {
126126
canvas: canvas,
127127
context: gl
@@ -217,7 +217,7 @@
217217
scene.add(mesh);
218218

219219
}
220-
220+
221221
}
222222

223223
function onWindowResize() {

examples/webgl_materials_channels.html

Lines changed: 8 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
var cameraOrtho, cameraPerspective;
6767
var controlsOrtho, controlsPerspective;
6868

69-
var mesh, materialStandard, materialDepthAuto, materialDepthAutoRGBA, materialDepthLinearClipZ, materialDepthLinearClipZRGBA, materialDepthInvClipZ, materialDepthInvClipZRGBA, materialNormal;
69+
var mesh, materialStandard, materialDepthLinear, materialDepthRGBA, materialNormal;
7070

7171
var pointLight, ambientLight;
7272

@@ -83,7 +83,7 @@
8383
function initGui() {
8484

8585
var gui = new dat.GUI();
86-
gui.add( params, 'material', [ 'standard', 'normal', 'depthAuto', 'depthAutoRGBA', 'depthLinearClipZ', 'depthLinearClipZRGBA', 'depthInvClipZ', 'depthInvClipZRGBA' ] );
86+
gui.add( params, 'material', [ 'standard', 'normal', 'depthLinear', 'depthRGBA' ] );
8787
gui.add( params, 'camera', [ 'perspective', 'ortho' ] );
8888

8989
}
@@ -172,8 +172,7 @@
172172
side: THREE.DoubleSide
173173
} );
174174

175-
materialDepthAuto = new THREE.MeshDepthMaterial( {
176-
depthFormat: THREE.AutoDepthFormat,
175+
materialDepthLinear = new THREE.MeshDepthMaterial( {
177176
depthPacking: THREE.LinearDepthPacking,
178177

179178
displacementMap: displacementMap,
@@ -183,52 +182,7 @@
183182
side: THREE.DoubleSide
184183
} );
185184

186-
materialDepthAutoRGBA = new THREE.MeshDepthMaterial( {
187-
depthFormat: THREE.AutoDepthFormat,
188-
depthPacking: THREE.RGBADepthPacking,
189-
190-
displacementMap: displacementMap,
191-
displacementScale: SCALE,
192-
displacementBias: BIAS,
193-
194-
side: THREE.DoubleSide
195-
} );
196-
197-
materialDepthLinearClipZ = new THREE.MeshDepthMaterial( {
198-
depthFormat: THREE.LinearClipZDepthFormat,
199-
depthPacking: THREE.LinearDepthPacking,
200-
201-
displacementMap: displacementMap,
202-
displacementScale: SCALE,
203-
displacementBias: BIAS,
204-
205-
side: THREE.DoubleSide
206-
} );
207-
208-
materialDepthLinearClipZRGBA = new THREE.MeshDepthMaterial( {
209-
depthFormat: THREE.LinearClipZDepthFormat,
210-
depthPacking: THREE.RGBADepthPacking,
211-
212-
displacementMap: displacementMap,
213-
displacementScale: SCALE,
214-
displacementBias: BIAS,
215-
216-
side: THREE.DoubleSide
217-
} );
218-
219-
materialDepthInvClipZ = new THREE.MeshDepthMaterial( {
220-
depthFormat: THREE.InvClipZDepthFormat,
221-
depthPacking: THREE.LinearDepthPacking,
222-
223-
displacementMap: displacementMap,
224-
displacementScale: SCALE,
225-
displacementBias: BIAS,
226-
227-
side: THREE.DoubleSide
228-
} );
229-
230-
materialDepthInvClipZRGBA = new THREE.MeshDepthMaterial( {
231-
depthFormat: THREE.InvClipZDepthFormat,
185+
materialDepthRGBA = new THREE.MeshDepthMaterial( {
232186
depthPacking: THREE.RGBADepthPacking,
233187

234188
displacementMap: displacementMap,
@@ -307,14 +261,12 @@
307261
var material = mesh.material;
308262

309263
switch ( params.material ) {
264+
310265
case 'standard': material = materialStandard; break;
311-
case 'depthAuto': material = materialDepthAuto; break;
312-
case 'depthAutoRGBA': material = materialDepthAutoRGBA; break;
313-
case 'depthLinearClipZ': material = materialDepthLinearClipZ; break;
314-
case 'depthLinearClipZRGBA': material = materialDepthLinearClipZRGBA; break;
315-
case 'depthInvClipZ': material = materialDepthInvClipZ; break;
316-
case 'depthInvClipZRGBA': material = materialDepthInvClipZRGBA; break;
266+
case 'depthLinear': material = materialDepthLinear; break;
267+
case 'depthRGBA': material = materialDepthRGBA; break;
317268
case 'normal': material = materialNormal; break;
269+
318270
}
319271

320272
mesh.material = material;
@@ -324,7 +276,6 @@
324276
switch ( params.camera ) {
325277

326278
case 'perspective': camera = cameraPerspective; break;
327-
328279
case 'ortho': camera = cameraOrtho; break;
329280

330281
}

src/materials/MeshDepthMaterial.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ THREE.MeshDepthMaterial = function ( parameters ) {
2121

2222
this.type = 'MeshDepthMaterial';
2323

24-
this.depthFormat = THREE.AutoDepthFormat;
2524
this.depthPacking = THREE.LinearDepthPacking;
2625

2726
this.skinning = false;
@@ -45,7 +44,6 @@ THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
4544

4645
THREE.Material.prototype.copy.call( this, source );
4746

48-
this.depthFormat = source.depthFormat;
4947
this.depthPacking = source.depthPacking;
5048

5149
this.skinning = source.skinning;

src/renderers/WebGLRenderer.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,6 @@ THREE.WebGLRenderer = function ( parameters ) {
19941994

19951995
} else if ( material instanceof THREE.MeshDepthMaterial ) {
19961996

1997-
m_uniforms.mNear.value = camera.near;
1998-
m_uniforms.mFar.value = camera.far;
19991997
m_uniforms.opacity.value = material.opacity;
20001998

20011999
if ( material.displacementMap ) {

src/renderers/shaders/ShaderChunk/packing.glsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ float unpackRGBAToLinearUnit( const in vec4 rgba ) {
2121

2222
// NOTE: viewZ/eyeZ is < 0 when in front of the camera per OpenGL conventions
2323

24-
float viewZToLinearClipZ( const in float viewZ, const in float near, const in float far ) {
24+
float viewZToOrthoDepth( const in float viewZ, const in float near, const in float far ) {
2525
return ( viewZ + near ) / ( near - far );
2626
}
27-
float linearClipZToViewZ( const in float linearClipZ, const in float near, const in float far ) {
27+
float OrthoDepthToViewZ( const in float linearClipZ, const in float near, const in float far ) {
2828
return linearClipZ * ( near - far ) - near;
2929
}
3030

31-
float viewZToInvClipZ( const in float viewZ, const in float near, const in float far ) {
31+
float viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {
3232
return (( near + viewZ ) * far ) / (( far - near ) * viewZ );
3333
}
34-
float invClipZToViewZ( const in float invClipZ, const in float near, const in float far ) {
34+
float perspectiveDepthToViewZ( const in float invClipZ, const in float near, const in float far ) {
3535
return ( near * far ) / ( ( far - near ) * invClipZ - far );
3636
}

src/renderers/shaders/ShaderLib/depth_frag.glsl

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
#if DEPTH_FORMAT != 3100
2-
3-
uniform float mNear;
4-
uniform float mFar;
5-
6-
#endif
7-
81
#if DEPTH_PACKING == 3200
92

103
uniform float opacity;
114

125
#endif
136

14-
#if DEPTH_FORMAT != 3100
15-
16-
varying float vViewZDepth;
17-
18-
#endif
19-
207
#include <common>
218
#include <packing>
229
#include <logdepthbuf_pars_fragment>
@@ -27,29 +14,13 @@ void main() {
2714
#include <clipping_planes_fragment>
2815
#include <logdepthbuf_fragment>
2916

30-
float transformedDepth = 0.0;
31-
32-
#if DEPTH_FORMAT == 3100 // AutoDepthFormat
33-
34-
transformedDepth = gl_FragCoord.z;
35-
36-
#elif DEPTH_FORMAT == 3101
37-
38-
transformedDepth = viewZToLinearClipZ( vViewZDepth, mNear, mFar );
39-
40-
#elif DEPTH_FORMAT == 3102
41-
42-
transformedDepth = viewZToInvClipZ( vViewZDepth, mNear, mFar );
43-
44-
#endif
45-
4617
#if DEPTH_PACKING == 3200
4718

48-
gl_FragColor = vec4( vec3( transformedDepth ), opacity );
19+
gl_FragColor = vec4( vec3( gl_FragCoord.z ), opacity );
4920

5021
#elif DEPTH_PACKING == 3201
5122

52-
gl_FragColor = packLinearUnitToRGBA( transformedDepth );
23+
gl_FragColor = packLinearUnitToRGBA( gl_FragCoord.z );
5324

5425
#endif
5526

src/renderers/shaders/ShaderLib/depth_vert.glsl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66
#include <logdepthbuf_pars_vertex>
77
#include <clipping_planes_pars_vertex>
88

9-
#if DEPTH_FORMAT != 3100
10-
11-
varying float vViewZDepth;
12-
13-
#endif
14-
159
void main() {
1610

1711
#include <uv_vertex>
@@ -26,10 +20,4 @@ void main() {
2620
#include <logdepthbuf_vertex>
2721
#include <clipping_planes_vertex>
2822

29-
#if DEPTH_FORMAT != 3100
30-
31-
vViewZDepth = mvPosition.z;
32-
33-
#endif
34-
3523
}

src/renderers/webgl/WebGLProgram.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,6 @@ THREE.WebGLProgram = ( function () {
443443
parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
444444
parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
445445

446-
parameters.depthFormat ? "#define DEPTH_FORMAT " + material.depthFormat : '',
447-
448446
'uniform mat4 modelMatrix;',
449447
'uniform mat4 modelViewMatrix;',
450448
'uniform mat4 projectionMatrix;',
@@ -565,7 +563,6 @@ THREE.WebGLProgram = ( function () {
565563
parameters.outputEncoding ? getTexelEncodingFunction( "linearToOutputTexel", parameters.outputEncoding ) : '',
566564

567565
parameters.depthPacking ? "#define DEPTH_PACKING " + material.depthPacking : '',
568-
parameters.depthFormat ? "#define DEPTH_FORMAT " + material.depthFormat : '',
569566

570567
'\n'
571568

src/renderers/webgl/WebGLPrograms.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
2525
"maxMorphTargets", "maxMorphNormals", "premultipliedAlpha",
2626
"numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
2727
"shadowMapEnabled", "shadowMapType", "toneMapping", 'physicallyCorrectLights',
28-
"alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking", "depthFormat"
28+
"alphaTest", "doubleSided", "flipSided", "numClippingPlanes", "depthPacking"
2929
];
3030

3131

@@ -184,8 +184,7 @@ THREE.WebGLPrograms = function ( renderer, capabilities ) {
184184
doubleSided: material.side === THREE.DoubleSide,
185185
flipSided: material.side === THREE.BackSide,
186186

187-
depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
188-
depthFormat: ( material.depthFormat !== undefined ) ? material.depthFormat : false
187+
depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false
189188

190189
};
191190

src/renderers/webgl/WebGLShadowMap.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
4747
// init
4848

4949
var depthMaterialTemplate = new THREE.MeshDepthMaterial();
50-
depthMaterialTemplate.depthFormat = THREE.AutoDepthFormat;
5150
depthMaterialTemplate.depthPacking = THREE.RGBADepthPacking;
5251
depthMaterialTemplate.clipping = true;
5352

0 commit comments

Comments
 (0)