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

Simplify vertex attributes #228

Merged
merged 3 commits into from
Nov 20, 2021
Merged

Simplify vertex attributes #228

merged 3 commits into from
Nov 20, 2021

Conversation

parasyte
Copy link
Owner

  • Vertex UVs can be computed from the positions, which saves a small
    amount of code and a small amount of bandwidth (both inconsequential).
  • This is mostly for readability.

- Vertex UVs can be computed from the positions, which saves a small
  amount of code and a small amount of bandwidth (both inconsequential).
- This is mostly for readability.
@parasyte
Copy link
Owner Author

Hmm, this PR made me realize that the texture coordinates on the custom shader example were flipped vertically. The pixel buffer is upside down! It's hard to tell when it's just a moving square, but it's supposed to start near the upper-left corner and move to the lower-right.

The problem is that I was doing the texture coordinate correction in the transformation matrix instead of in the UVs themselves. Removing the vertical flip from the transformation matrix means that both shaders can do the same UV computation to correct the vertical axis. This fixes an accidental cancelation effect.

wgpu uses Metal/DirectX normalized coordinates (which can be seen in the wgpu readme) This means our triangle has its right-angle in the lower-left corner and UV (0, 0) starts half-way up the left side and goes down-right to (1, 1) half-way along the bottom of the triangle.

@parasyte parasyte merged commit c2454b0 into main Nov 20, 2021
@parasyte parasyte deleted the simplify-vertex-attributes branch November 20, 2021 22:06
parasyte added a commit that referenced this pull request Dec 1, 2021
- This fixes a regression caused by #228
parasyte added a commit that referenced this pull request Dec 1, 2021
- This fixes a regression caused by #228
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.

None yet

1 participant