Skip to content

Commit 2aa531f

Browse files
committed
fix(taa): resolve persistent camera drift under TAA post-processing
1 parent 8ddd262 commit 2aa531f

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@orillusion/core",
3-
"version": "0.8.5-dev.1",
3+
"version": "0.8.5-dev.3",
44
"author": "Orillusion",
55
"description": "Orillusion WebGPU Engine",
66
"type": "module",

src/core/Camera3D.ts

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ export class Camera3D extends ComponentBase {
233233
this.far = far;
234234
this._projectionMatrix.perspective(this.fov, this.aspect, this.near, this.far);
235235
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+
}
236242
}
237243

238244
/**
@@ -270,6 +276,12 @@ export class Camera3D extends ComponentBase {
270276
this.bottom = bottom;
271277
this.type = CameraType.ortho;
272278
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+
}
273285
}
274286

275287
/**
@@ -497,13 +509,16 @@ export class Camera3D extends ComponentBase {
497509
this.enableCSM && this.csm?.update(this._projectionMatrix, this._pvMatrixInv, this.near, this.far, shadow);
498510
}
499511

512+
// for jitter projection
500513
private _haltonSeq: HaltonSeq;
501514
private _jitterOffsetList: Vector2[];
502515
private _useJitterProjection: boolean = false;
503516
private _jitterFrameIndex: number = 0;
504517
private _sampleIndex: number = 0;
505518
private _jitterX: number = 0;
506519
private _jitterY: number = 0;
520+
private _jitterOffsetX: number;
521+
private _jitterOffsetY: number;
507522

508523
public get jitterFrameIndex() {
509524
return this._jitterFrameIndex;
@@ -539,21 +554,23 @@ export class Camera3D extends ComponentBase {
539554

540555
private getJitteredProjectionMatrix() {
541556
let setting = Engine3D.setting.render.postProcessing.taa;
542-
let mat = this._projectionMatrix;
543557
let temporalJitterScale: number = setting.temporalJitterScale;
544558
let offsetIndex = this._jitterFrameIndex % setting.jitterSeedCount;
545559
let num1 = this._jitterOffsetList[offsetIndex].x * temporalJitterScale;
546560
let num2 = this._jitterOffsetList[offsetIndex].y * temporalJitterScale;
547561

548-
let jitX = mat.get(0, 2);
549-
let jitY = mat.get(1, 2);
550-
551562
this._jitterX = num1 / this.viewPort.width;
552563
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);
557574

558575
this._jitterFrameIndex++;
559576
}

0 commit comments

Comments
 (0)