From 9cdd94bcb3f9d7c91f1d6a1d43f314997893c124 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 28 Nov 2023 09:55:55 +0000 Subject: [PATCH 1/4] early out if inner width or height is empty --- src/scene/graphics/reproject-texture.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/scene/graphics/reproject-texture.js b/src/scene/graphics/reproject-texture.js index 97712aa3d9f..b90d85f0e43 100644 --- a/src/scene/graphics/reproject-texture.js +++ b/src/scene/graphics/reproject-texture.js @@ -483,6 +483,10 @@ function reprojectTexture(source, target, options = {}) { const innerWidth = w - p * 2; const innerHeight = h - p * 2; + if (innerWidth <= 0 || innerHeight <= 0) { + return false; + } + uvModParam.setValue([ (innerWidth + p * 2) / innerWidth, (innerHeight + p * 2) / innerHeight, @@ -535,6 +539,8 @@ function reprojectTexture(source, target, options = {}) { } DebugGraphics.popGpuMarker(device); + + return true; } export { reprojectTexture }; From f305004d54fdf35bab8f6a9a756d6212592c06eb Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 28 Nov 2023 10:30:27 +0000 Subject: [PATCH 2/4] early out on empty inner --- src/scene/graphics/reproject-texture.js | 30 ++++++++++++------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/scene/graphics/reproject-texture.js b/src/scene/graphics/reproject-texture.js index b90d85f0e43..47a76fab39a 100644 --- a/src/scene/graphics/reproject-texture.js +++ b/src/scene/graphics/reproject-texture.js @@ -414,6 +414,15 @@ function reprojectTexture(source, target, options = {}) { Debug.deprecated('please use the updated pc.reprojectTexture API.'); } + // calculate inner width and height + const seamPixels = options.seamPixels ?? 0; + const innerWidth = (options.rect?.z ?? target.width) - seamPixels * 2; + const innerHeight = (options.rect?.w ?? target.height) - seamPixels * 2; + if (innerWidth <= 0 || innerHeight <= 0) { + // early out if inner space is empty + return false; + } + // table of distribution -> function name const funcNames = { 'none': 'reproject', @@ -475,23 +484,12 @@ function reprojectTexture(source, target, options = {}) { const constantParams2 = device.scope.resolve("params2"); const uvModParam = device.scope.resolve("uvMod"); - if (options?.seamPixels) { - const p = options.seamPixels; - const w = options.rect ? options.rect.z : target.width; - const h = options.rect ? options.rect.w : target.height; - - const innerWidth = w - p * 2; - const innerHeight = h - p * 2; - - if (innerWidth <= 0 || innerHeight <= 0) { - return false; - } - + if (seamPixels > 0) { uvModParam.setValue([ - (innerWidth + p * 2) / innerWidth, - (innerHeight + p * 2) / innerHeight, - -p / innerWidth, - -p / innerHeight + (innerWidth + seamPixels * 2) / innerWidth, + (innerHeight + seamPixels * 2) / innerHeight, + -seamPixels / innerWidth, + -seamPixels / innerHeight ]); } else { uvModParam.setValue([1, 1, 0, 0]); From 6b003e633d9139c5abd50d561115ffd7f4fb495a Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 28 Nov 2023 10:39:22 +0000 Subject: [PATCH 3/4] lint --- src/scene/graphics/reproject-texture.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scene/graphics/reproject-texture.js b/src/scene/graphics/reproject-texture.js index 47a76fab39a..b8a1e8eb53e 100644 --- a/src/scene/graphics/reproject-texture.js +++ b/src/scene/graphics/reproject-texture.js @@ -396,6 +396,7 @@ void main(void) { * 'phong', 'ggx'. Default depends on specularPower. * @param {import('../../core/math/vec4.js').Vec4} [options.rect] - Optional viewport rectangle. * @param {number} [options.seamPixels] - Optional number of seam pixels to render + * @returns {boolean} True if the reprojection was applied and false otherwise (e.g. if rect is empty) */ function reprojectTexture(source, target, options = {}) { // maintain backwards compatibility with previous function signature From 45f16beb63b1f88e32d02ed1ce2e012afd13ad04 Mon Sep 17 00:00:00 2001 From: Donovan Hutchence Date: Tue, 28 Nov 2023 10:52:13 +0000 Subject: [PATCH 4/4] small --- src/scene/graphics/reproject-texture.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scene/graphics/reproject-texture.js b/src/scene/graphics/reproject-texture.js index b8a1e8eb53e..7f412ed62f2 100644 --- a/src/scene/graphics/reproject-texture.js +++ b/src/scene/graphics/reproject-texture.js @@ -419,7 +419,7 @@ function reprojectTexture(source, target, options = {}) { const seamPixels = options.seamPixels ?? 0; const innerWidth = (options.rect?.z ?? target.width) - seamPixels * 2; const innerHeight = (options.rect?.w ?? target.height) - seamPixels * 2; - if (innerWidth <= 0 || innerHeight <= 0) { + if (innerWidth < 1 || innerHeight < 1) { // early out if inner space is empty return false; }