Skip to content

Commit

Permalink
renames
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Valigursky committed Mar 7, 2024
1 parent 9dadaf7 commit d650672
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions extras/render-passes/render-pass-camera-frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class RenderPassCameraFrame extends RenderPass {
let sceneTextureWithTaa = sceneTexture;
if (options.taaEnabled) {
this.taaPass = new RenderPassTAA(device, sceneTexture, cameraComponent);
sceneTextureWithTaa = this.taaPass.accumulationTexture;
sceneTextureWithTaa = this.taaPass.historyTexture;
}

// ------ BLOOM GENERATION ------
Expand Down Expand Up @@ -254,7 +254,7 @@ class RenderPassCameraFrame extends RenderPass {
// scene texture is either output of taa pass or the scene render target
const sceneTexture = this.taaPass?.update() ?? this._rt.colorBuffer;

// TAA accumulation buffer is double buffered, assign the current one to the follow up passes.
// TAA history buffer is double buffered, assign the current one to the follow up passes.
this.composePass.sceneTexture = sceneTexture;
if (this.bloomEnabled) {
this.bloomPass.sourceTexture = sceneTexture;
Expand Down
47 changes: 25 additions & 22 deletions extras/render-passes/render-pass-taa.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
const fs = /* glsl */ `
uniform highp sampler2D uSceneDepthMap;
uniform sampler2D sourceTexture;
uniform sampler2D accumulationTexture;
uniform sampler2D historyTexture;
uniform mat4 matrix_viewProjectionPrevious;
uniform mat4 matrix_viewProjectionInverse;
uniform vec4 jitters; // xy: current frame, zw: previous frame
Expand Down Expand Up @@ -84,12 +84,12 @@ const fs = /* glsl */ `
#ifdef QUALITY_HIGH
// high quality history, sharper result
vec4 historyColor = SampleTextureCatmullRom(TEXTURE_PASS(accumulationTexture), historyUv, textureSize);
vec4 historyColor = SampleTextureCatmullRom(TEXTURE_PASS(historyTexture), historyUv, textureSize);
#else
// single sample history, more blurry result
vec4 historyColor = texture2D(accumulationTexture, historyUv);
vec4 historyColor = texture2D(historyTexture, historyUv);
#endif
Expand All @@ -106,23 +106,26 @@ const fs = /* glsl */ `

class RenderPassTAA extends RenderPassShaderQuad {
/**
* The index of the accumulation texture to render to.
* The index of the history texture to render to.
*
* @type {number}
*/
accumulationIndex = 0;
historyIndex = 0;

accumulationTexture = null;
/**
* @type {Texture}
*/
historyTexture = null;

/**
* @type {Texture[]}
*/
accumulationTextures = [];
historyTextures = [];

/**
* @type {RenderTarget[]}
*/
accumulationRenderTargets = [];
historyRenderTargets = [];

constructor(device, sourceTexture, cameraComponent) {
super(device);
Expand All @@ -139,7 +142,7 @@ class RenderPassTAA extends RenderPassShaderQuad {
this.sourceTextureId = scope.resolve('sourceTexture');
this.textureSizeId = scope.resolve('textureSize');
this.textureSize = new Float32Array(2);
this.accumulationTextureId = scope.resolve('accumulationTexture');
this.historyTextureId = scope.resolve('historyTexture');
this.viewProjPrevId = scope.resolve('matrix_viewProjectionPrevious');
this.viewProjInvId = scope.resolve('matrix_viewProjectionInverse');
this.jittersId = scope.resolve('jitters');
Expand All @@ -157,10 +160,10 @@ class RenderPassTAA extends RenderPassShaderQuad {

setup() {

// double buffered accumulation render target
// double buffered history render target
for (let i = 0; i < 2; ++i) {
this.accumulationTextures[i] = new Texture(this.device, {
name: `TAA-Accumulation-${i}`,
this.historyTextures[i] = new Texture(this.device, {
name: `TAA-History-${i}`,
width: 4,
height: 4,
format: this.sourceTexture.format,
Expand All @@ -171,21 +174,21 @@ class RenderPassTAA extends RenderPassShaderQuad {
addressV: ADDRESS_CLAMP_TO_EDGE
});

this.accumulationRenderTargets[i] = new RenderTarget({
colorBuffer: this.accumulationTextures[i],
this.historyRenderTargets[i] = new RenderTarget({
colorBuffer: this.historyTextures[i],
depth: false
});
}

this.accumulationTexture = this.accumulationTextures[0];
this.init(this.accumulationRenderTargets[0], {
this.historyTexture = this.historyTextures[0];
this.init(this.historyRenderTargets[0], {
resizeSource: this.sourceTexture
});
}

before() {
this.sourceTextureId.setValue(this.sourceTexture);
this.accumulationTextureId.setValue(this.accumulationTextures[1 - this.accumulationIndex]);
this.historyTextureId.setValue(this.historyTextures[1 - this.historyIndex]);

this.textureSize[0] = this.sourceTexture.width;
this.textureSize[1] = this.sourceTexture.height;
Expand All @@ -200,12 +203,12 @@ class RenderPassTAA extends RenderPassShaderQuad {
// called when the parent render pass gets added to the frame graph
update() {

// swap source and destination accumulation texture
this.accumulationIndex = 1 - this.accumulationIndex;
this.accumulationTexture = this.accumulationTextures[this.accumulationIndex];
this.renderTarget = this.accumulationRenderTargets[this.accumulationIndex];
// swap source and destination history texture
this.historyIndex = 1 - this.historyIndex;
this.historyTexture = this.historyTextures[this.historyIndex];
this.renderTarget = this.historyRenderTargets[this.historyIndex];

return this.accumulationTexture;
return this.historyTexture;
}
}

Expand Down

0 comments on commit d650672

Please sign in to comment.