@@ -233,6 +233,12 @@ export class Camera3D extends ComponentBase {
233
233
this . far = far ;
234
234
this . _projectionMatrix . perspective ( this . fov , this . aspect , this . near , this . far ) ;
235
235
this . type = CameraType . perspective ;
236
+
237
+ // update jitter offset
238
+ if ( this . _useJitterProjection ) {
239
+ this . _jitterOffsetX = this . _projectionMatrix . get ( 0 , 2 ) ;
240
+ this . _jitterOffsetY = this . _projectionMatrix . get ( 1 , 2 ) ;
241
+ }
236
242
}
237
243
238
244
/**
@@ -270,6 +276,12 @@ export class Camera3D extends ComponentBase {
270
276
this . bottom = bottom ;
271
277
this . type = CameraType . ortho ;
272
278
this . _projectionMatrix . orthoOffCenter ( this . left , this . right , this . bottom , this . top , this . near , this . far ) ;
279
+
280
+ // update jitter offset
281
+ if ( this . _useJitterProjection ) {
282
+ this . _jitterOffsetX = this . _projectionMatrix . get ( 0 , 2 ) ;
283
+ this . _jitterOffsetY = this . _projectionMatrix . get ( 1 , 2 ) ;
284
+ }
273
285
}
274
286
275
287
/**
@@ -497,13 +509,16 @@ export class Camera3D extends ComponentBase {
497
509
this . enableCSM && this . csm ?. update ( this . _projectionMatrix , this . _pvMatrixInv , this . near , this . far , shadow ) ;
498
510
}
499
511
512
+ // for jitter projection
500
513
private _haltonSeq : HaltonSeq ;
501
514
private _jitterOffsetList : Vector2 [ ] ;
502
515
private _useJitterProjection : boolean = false ;
503
516
private _jitterFrameIndex : number = 0 ;
504
517
private _sampleIndex : number = 0 ;
505
518
private _jitterX : number = 0 ;
506
519
private _jitterY : number = 0 ;
520
+ private _jitterOffsetX : number ;
521
+ private _jitterOffsetY : number ;
507
522
508
523
public get jitterFrameIndex ( ) {
509
524
return this . _jitterFrameIndex ;
@@ -539,21 +554,23 @@ export class Camera3D extends ComponentBase {
539
554
540
555
private getJitteredProjectionMatrix ( ) {
541
556
let setting = Engine3D . setting . render . postProcessing . taa ;
542
- let mat = this . _projectionMatrix ;
543
557
let temporalJitterScale : number = setting . temporalJitterScale ;
544
558
let offsetIndex = this . _jitterFrameIndex % setting . jitterSeedCount ;
545
559
let num1 = this . _jitterOffsetList [ offsetIndex ] . x * temporalJitterScale ;
546
560
let num2 = this . _jitterOffsetList [ offsetIndex ] . y * temporalJitterScale ;
547
561
548
- let jitX = mat . get ( 0 , 2 ) ;
549
- let jitY = mat . get ( 1 , 2 ) ;
550
-
551
562
this . _jitterX = num1 / this . viewPort . width ;
552
563
this . _jitterY = num2 / this . viewPort . height ;
553
- jitX += this . _jitterX ;
554
- jitY += this . _jitterY ;
555
- mat . set ( 0 , 2 , jitX ) ;
556
- mat . set ( 1 , 2 , jitY ) ;
564
+
565
+ // set offset xy if not set
566
+ if ( ! this . _jitterOffsetX || ! this . _jitterOffsetY ) {
567
+ this . _jitterOffsetX = this . _projectionMatrix . get ( 0 , 2 ) ;
568
+ this . _jitterOffsetY = this . _projectionMatrix . get ( 1 , 2 ) ;
569
+ }
570
+ let offsetX = this . _jitterOffsetX + this . _jitterX ;
571
+ let offsetY = this . _jitterOffsetY + this . _jitterY ;
572
+ this . _projectionMatrix . set ( 0 , 2 , offsetX ) ;
573
+ this . _projectionMatrix . set ( 1 , 2 , offsetY ) ;
557
574
558
575
this . _jitterFrameIndex ++ ;
559
576
}
0 commit comments