Skip to content

Commit

Permalink
Reproject fix (#5860)
Browse files Browse the repository at this point in the history
  • Loading branch information
slimbuck authored Nov 28, 2023
1 parent 811de63 commit 02e16c4
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/scene/graphics/reproject-texture.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -414,6 +415,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 < 1 || innerHeight < 1) {
// early out if inner space is empty
return false;
}

// table of distribution -> function name
const funcNames = {
'none': 'reproject',
Expand Down Expand Up @@ -475,19 +485,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 (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]);
Expand Down Expand Up @@ -535,6 +538,8 @@ function reprojectTexture(source, target, options = {}) {
}

DebugGraphics.popGpuMarker(device);

return true;
}

export { reprojectTexture };

0 comments on commit 02e16c4

Please sign in to comment.