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

Fix readTextureToTexelViews for cubemaps #4177

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

greggman
Copy link
Contributor

@greggman greggman commented Feb 5, 2025

The issue was that the code that reads back the texture uses textureGather for cubemaps. It has to use textureGather because it's the only way to load from cubemaps with integer formats. It was computing a texel coord and then doing the common conversion to normalized texture coord

normalizedCoord = (integerTexelCoord + 0.5) / dimension

But, for textureGather, 0.5 is the center of the texel and so it's an edge case. The gather could go in any direction from the center. Moving it off center should fix that issue.

Given coord C in the center of a texel

+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |       |       |
+-------+-------+-------+
|       |       |       |
|       |   C   |       |
|       |       |       |
+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |       |       |
+-------+-------+-------+

textureGather could return any of these 4 results

+-------+-------+-------+      +-------+-------+-------+
|.......|.......|       |      |       |.......|.......|
|.......|.......|       |      |       |.......|.......|
|.......|.......|       |      |       |.......|.......|
+-------+-------+-------+      +-------+-------+-------+
|.......|.......|       |      |       |.......|.......|
|.......|...C...|       |      |       |...C...|.......|
|.......|.......|       |      |       |.......|.......|
+-------+-------+-------+      +-------+-------+-------+
|       |       |       |      |       |       |       |
|       |       |       |      |       |       |       |
|       |       |       |      |       |       |       |
+-------+-------+-------+      +-------+-------+-------+




+-------+-------+-------+      +-------+-------+-------+
|       |       |       |      |       |       |       |
|       |       |       |      |       |       |       |
|       |       |       |      |       |       |       |
+-------+-------+-------+      +-------+-------+-------+
|.......|.......|       |      |       |.......|.......|
|.......|...C...|       |      |       |...C...|.......|
|.......|.......|       |      |       |.......|.......|
+-------+-------+-------+      +-------+-------+-------+
|.......|.......|       |      |       |.......|.......|
|.......|.......|       |      |       |.......|.......|
|.......|.......|       |      |       |.......|.......|
+-------+-------+-------+      +-------+-------+-------+

if we move it off center

+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |       |       |
+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |     C |       |
+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |       |       |
+-------+-------+-------+

Then it will always return the same result

+-------+-------+-------+
|       |       |       |
|       |       |       |
|       |       |       |
+-------+-------+-------+
|       |.......|.......|
|       |.......|.......|
|       |.....c.|.......|
+-------+-------+-------+
|       |.......|.......|
|       |.......|.......|
|       |.......|.......|
+-------+-------+-------+

The issue was that the code that reads back the texture
uses textureGather for cubemaps. It has to use textureGather
because it's the only way to load from cubemaps with integer
formats. It was computing a texel coord and then doing the
common conversion to normalized texture coord

normalizedCoord = (integerTexelCoord + 0.5) / dimension

But, for textureGather, 0.5 is the center of the texel and so
it's an edge case. The gather could go in any direction from
the center. Moving it off center should fix that issue.
@greggman greggman requested a review from shrekshao February 5, 2025 22:43
Copy link
Contributor

@shrekshao shrekshao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@greggman greggman merged commit 9f2c2c0 into gpuweb:main Feb 6, 2025
1 check passed
@greggman greggman deleted the texture-read-issue branch February 6, 2025 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants