@@ -88,12 +88,16 @@ export class WebGLPathTracer {
88
88
this . _renderer = renderer ;
89
89
this . _generator = null ;
90
90
this . _pathTracer = new PathTracingRenderer ( renderer ) ;
91
+ this . _lowResPathTracer = new PathTracingRenderer ( renderer ) ;
91
92
this . _quad = new FullScreenQuad ( new MeshBasicMaterial ( {
92
93
map : null ,
93
94
blending : CustomBlending ,
94
95
premultipliedAlpha : renderer . getContextAttributes ( ) . premultipliedAlpha ,
95
96
} ) ) ;
96
97
98
+ // options
99
+ this . dynamicLowRes = false ;
100
+ this . lowResScale = 0.15 ;
97
101
this . renderScale = 1 ;
98
102
this . synchronizeRenderSize = true ;
99
103
this . rasterizeScene = true ;
@@ -109,23 +113,45 @@ export class WebGLPathTracer {
109
113
[
110
114
'getPixelRatio' ,
111
115
'setPixelRatio' ,
116
+ 'setDrawingBufferSize' ,
117
+ 'getDrawingBufferSize' ,
112
118
'getSize' ,
113
119
'setSize' ,
120
+ ] . forEach ( key => {
121
+
122
+ this [ key ] = ( ...args ) => {
123
+
124
+ this . _renderer [ key ] ( ...args ) ;
125
+ if ( this . renderToCanvas ) {
126
+
127
+ this . reset ( ) ;
128
+
129
+ }
130
+
131
+ } ;
132
+
133
+ } ) ;
134
+
135
+ // Functions that require always resetting the render
136
+ [
114
137
'setViewport' ,
115
138
'getViewport' ,
116
139
'getScissor' ,
117
140
'setScissor' ,
118
141
'getScissorTest' ,
119
142
'setScissorTest' ,
120
- 'setDrawingBufferSize' ,
121
- 'getDrawingBufferSize' ,
122
143
'getClearAlpha' ,
123
144
'setClearAlpha' ,
124
145
'getClearColor' ,
125
146
'setClearColor' ,
126
147
] . forEach ( key => {
127
148
128
- this [ key ] = ( ...args ) => this . _renderer [ key ] ( ...args ) ;
149
+ this [ key ] = ( ...args ) => {
150
+
151
+ this . _renderer [ key ] ( ...args ) ;
152
+ this . reset ( ) ;
153
+
154
+ } ;
129
155
130
156
} ) ;
131
157
@@ -135,6 +161,7 @@ export class WebGLPathTracer {
135
161
136
162
const renderer = this . _renderer ;
137
163
const pathTracer = this . _pathTracer ;
164
+ const lowResPathTracer = this . _lowResPathTracer ;
138
165
const material = pathTracer . material ;
139
166
140
167
// TODO: adjust this so we don't have to create a new tracer every time and the
@@ -221,7 +248,11 @@ export class WebGLPathTracer {
221
248
}
222
249
223
250
// camera update
251
+ // TODO: these cameras should only be set once so we don't depend on movement
252
+ camera . updateMatrixWorld ( ) ;
224
253
pathTracer . camera = camera ;
254
+ lowResPathTracer . camera = camera ;
255
+ lowResPathTracer . material = pathTracer . material ;
225
256
226
257
// save previously used items
227
258
this . _previousScene = scene ;
@@ -237,23 +268,35 @@ export class WebGLPathTracer {
237
268
238
269
this . _updateScale ( ) ;
239
270
271
+ const lowResPathTracer = this . _lowResPathTracer ;
240
272
const pathTracer = this . _pathTracer ;
241
273
pathTracer . update ( ) ;
242
274
243
275
if ( this . renderToCanvas ) {
244
276
245
- if ( this . samples < 1 && this . rasterizeScene ) {
277
+ const renderer = this . _renderer ;
278
+ const quad = this . _quad ;
279
+ const autoClear = renderer . autoClear ;
280
+ if ( this . dynamicLowRes ) {
281
+
282
+ if ( lowResPathTracer . samples < 1 ) {
283
+
284
+ lowResPathTracer . update ( ) ;
285
+
286
+ }
287
+
288
+ renderer . autoClear = false ;
289
+ quad . material . map = lowResPathTracer . target . texture ;
290
+ quad . render ( renderer ) ;
291
+
292
+ } else if ( this . samples < 1 && this . rasterizeScene ) {
246
293
247
294
this . rasterizeSceneCallback ( ) ;
248
295
249
296
}
250
297
251
- const renderer = this . _renderer ;
252
- const quad = this . _quad ;
253
- quad . material . map = pathTracer . target . texture ;
254
-
255
- const autoClear = renderer . autoClear ;
256
298
renderer . autoClear = false ;
299
+ quad . material . map = pathTracer . target . texture ;
257
300
quad . render ( renderer ) ;
258
301
renderer . autoClear = autoClear ;
259
302
@@ -264,6 +307,7 @@ export class WebGLPathTracer {
264
307
reset ( ) {
265
308
266
309
this . _pathTracer . reset ( ) ;
310
+ this . _lowResPathTracer . reset ( ) ;
267
311
268
312
}
269
313
@@ -293,7 +337,9 @@ export class WebGLPathTracer {
293
337
this . _pathTracer . getSize ( _resolution ) ;
294
338
if ( _resolution . x !== w || _resolution . y !== h ) {
295
339
340
+ const lowResScale = this . lowResScale ;
296
341
this . _pathTracer . setSize ( w , h ) ;
342
+ this . _lowResPathTracer . setSize ( Math . floor ( w * lowResScale ) , Math . floor ( h * lowResScale ) ) ;
297
343
298
344
}
299
345
0 commit comments