Skip to content

Commit 0f4acdb

Browse files
fix: WebGLMultipleRenderTargets is removed in r172. (#309)
1 parent f9b4dae commit 0f4acdb

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

src/compat.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import * as THREE from 'three'
2+
3+
const version = /* @__PURE__ */ (() => parseInt(THREE.REVISION.replace(/\D+/g, '')))()
4+
5+
// NOTE: WebGLMultipleRenderTargets is removed since r172, so we implement it ourselves.
6+
// https://github.com/mrdoob/three.js/pull/26427
7+
export const WebGLMultipleRenderTargets =
8+
version >= 162
9+
? class extends THREE.WebGLRenderTarget {
10+
constructor(width = 1, height = 1, count = 1, options = {}) {
11+
super(width, height, { ...options, count })
12+
13+
this.isWebGLMultipleRenderTargets = true
14+
}
15+
16+
get texture() {
17+
return this.textures
18+
}
19+
}
20+
: class extends THREE.WebGLRenderTarget {
21+
constructor(width = 1, height = 1, count = 1, options = {}) {
22+
super(width, height, options)
23+
24+
this.isWebGLMultipleRenderTargets = true
25+
26+
const texture = this.texture
27+
28+
this.texture = []
29+
30+
for (let i = 0; i < count; i++) {
31+
this.texture[i] = texture.clone()
32+
this.texture[i].isRenderTargetTexture = true
33+
}
34+
}
35+
36+
setSize(width, height, depth = 1) {
37+
if (this.width !== width || this.height !== height || this.depth !== depth) {
38+
this.width = width
39+
this.height = height
40+
this.depth = depth
41+
42+
for (let i = 0, il = this.texture.length; i < il; i++) {
43+
this.texture[i].image.width = width
44+
this.texture[i].image.height = height
45+
this.texture[i].image.depth = depth
46+
}
47+
48+
this.dispose()
49+
}
50+
51+
this.viewport.set(0, 0, width, height)
52+
this.scissor.set(0, 0, width, height)
53+
}
54+
55+
copy(source) {
56+
this.dispose()
57+
58+
this.width = source.width
59+
this.height = source.height
60+
this.depth = source.depth
61+
62+
this.scissor.copy(source.scissor)
63+
this.scissorTest = source.scissorTest
64+
65+
this.viewport.copy(source.viewport)
66+
67+
this.depthBuffer = source.depthBuffer
68+
this.stencilBuffer = source.stencilBuffer
69+
70+
if (source.depthTexture !== null) this.depthTexture = source.depthTexture.clone()
71+
72+
this.texture.length = 0
73+
74+
for (let i = 0, il = source.texture.length; i < il; i++) {
75+
this.texture[i] = source.texture[i].clone()
76+
this.texture[i].isRenderTargetTexture = true
77+
}
78+
79+
return this
80+
}
81+
}

src/effects/N8AO/N8AOPostPass.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { EffectCompositer } from './EffectCompositer'
77
import { PoissionBlur } from './PoissionBlur'
88
import { DepthDownSample } from './DepthDownSample'
99
import BlueNoise from './BlueNoise'
10+
import { WebGLMultipleRenderTargets } from '../../compat'
1011

1112
const bluenoiseBits = Buffer.from(BlueNoise, 'base64')
1213

@@ -190,7 +191,7 @@ class N8AOPostPass extends Pass {
190191
format: THREE.RedFormat,
191192
type: THREE.FloatType
192193
});*/
193-
new THREE.WebGLMultipleRenderTargets(this.width / 2, this.height / 2, 2)
194+
new WebGLMultipleRenderTargets(this.width / 2, this.height / 2, 2)
194195
this.depthDownsampleTarget.texture[0].format = THREE.RedFormat
195196
this.depthDownsampleTarget.texture[0].type = THREE.FloatType
196197
this.depthDownsampleTarget.texture[0].minFilter = THREE.NearestFilter

src/effects/SSR/screen-space-reflections.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
WebGLRenderTarget,
1313
LinearFilter,
1414
HalfFloatType,
15-
WebGLMultipleRenderTargets,
1615
ShaderChunk,
1716
Color,
1817
Quaternion,
@@ -27,6 +26,7 @@ import {
2726
PMREMGenerator,
2827
Texture,
2928
} from 'three'
29+
import { WebGLMultipleRenderTargets } from '../../compat'
3030

3131
const boxBlur = /* glsl */ `
3232
uniform float blur;

0 commit comments

Comments
 (0)