@@ -67,6 +67,10 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
6767
6868 //
6969
70+ var invisibleMaterial = new THREE . ShaderMaterial ( ) ;
71+ invisibleMaterial . visible = false ;
72+
73+
7074 var defaultNormalDepthMaterial = new THREE . ShaderMaterial ( {
7175
7276 uniforms : THREE . UniformsUtils . clone ( normalDepthShader . uniforms ) ,
@@ -94,8 +98,17 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
9498
9599 var deferredMaterials = createDeferredMaterials ( materials [ i ] ) ;
96100
97- colorMaterials . push ( deferredMaterials . colorMaterial ) ;
98- normalDepthMaterials . push ( deferredMaterials . normalDepthMaterial ) ;
101+ if ( deferredMaterials . transparent ) {
102+
103+ colorMaterials . push ( invisibleMaterial ) ;
104+ normalDepthMaterials . push ( invisibleMaterial ) ;
105+
106+ } else {
107+
108+ colorMaterials . push ( deferredMaterials . colorMaterial ) ;
109+ normalDepthMaterials . push ( deferredMaterials . normalDepthMaterial ) ;
110+
111+ }
99112
100113 }
101114
@@ -108,6 +121,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
108121
109122 object . properties . colorMaterial = deferredMaterials . colorMaterial ;
110123 object . properties . normalDepthMaterial = deferredMaterials . normalDepthMaterial ;
124+ object . properties . transparent = deferredMaterials . transparent ;
111125
112126 }
113127
@@ -174,7 +188,6 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
174188
175189 material . alphaTest = originalMaterial . alphaTest ;
176190 material . wireframe = originalMaterial . wireframe ;
177- material . transparent = originalMaterial . transparent ;
178191
179192 // uv repeat and offset setting priorities
180193 // 1. color map
@@ -272,7 +285,7 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
272285
273286 }
274287
275- deferredMaterials . normalDepthMaterial . transparent = originalMaterial . transparent ;
288+ deferredMaterials . transparent = originalMaterial . transparent ;
276289
277290 return deferredMaterials ;
278291
@@ -471,8 +484,15 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
471484
472485 if ( object . material ) {
473486
474- object . material = object . properties . colorMaterial ;
475- if ( object . material . transparent ) object . visible = false ;
487+ if ( object . properties . transparent ) {
488+
489+ object . material = invisibleMaterial ;
490+
491+ } else {
492+
493+ object . material = object . properties . colorMaterial ;
494+
495+ }
476496
477497 }
478498
@@ -482,8 +502,15 @@ THREE.WebGLDeferredRenderer = function ( parameters ) {
482502
483503 if ( object . material ) {
484504
485- object . material = object . properties . normalDepthMaterial ;
486- if ( object . material . transparent ) object . visible = false ;
505+ if ( object . properties . transparent ) {
506+
507+ object . material = invisibleMaterial ;
508+
509+ } else {
510+
511+ object . material = object . properties . normalDepthMaterial ;
512+
513+ }
487514
488515 }
489516
0 commit comments