Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reproject fix #5860

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <= 0 || innerHeight <= 0) {
// 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 };