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

"Passing Shader Uniforms" example #1021

Open
JetStarBlues opened this issue Apr 22, 2021 · 12 comments · May be fixed by #1022
Open

"Passing Shader Uniforms" example #1021

JetStarBlues opened this issue Apr 22, 2021 · 12 comments · May be fixed by #1022
Labels

Comments

@JetStarBlues
Copy link
Contributor

Actual Behaviour

In the "Passing Shader Uniforms" example, the generated image is off-center.

su_current

Expected Behaviour

Image is centered.

su_intended

I think somewhere along the way, the original values got lost.

Would you like to work on the issue?

Yes

JetStarBlues added a commit to JetStarBlues/p5.js-website that referenced this issue Apr 22, 2021
@aferriss
Copy link

aferriss commented Apr 22, 2021

@JetStarBlues What browser are you using? Everything looks correct on my screen.

Screen Shot 2021-04-22 at 10 21 09 AM

@JetStarBlues
Copy link
Contributor Author

Interesting!

I tried it on Windows 10

  • Chrome Version 90.0.4430.85 (Official Build) (64-bit)
    su_ss_chrome-90 0 4430 85-64bit

  • Firefox 88.0 (64-bit)
    su_ss_firefox-88 0-64bit

I got similar results on Ubuntu 20.04

  • Chrome - Version 90.0.4430.72 (Official Build) (64-bit)
  • Firefox - 87.0 (64-bit)

@JetStarBlues
Copy link
Contributor Author

@aferriss Hey, the screenshot you posted failed to upload... Also curious which browser you were using.

@aferriss
Copy link

@JetStarBlues Oops! Re-uploaded. I was using chrome 90, but I also checked in firefox (v88) and safari (v14.03) and it was looking fine in all of those as well. I'm on OSX 10.15 (Catalina)

@JetStarBlues
Copy link
Contributor Author

(visible confusion)
If you are running on a 64-bit machine, then the only difference is the OS...

I tried opening the site on my phone (Android) on both Chrome and Firefox, and the current code looks slightly off-center...
su_ss_chrome_android

@JetStarBlues
Copy link
Contributor Author

JetStarBlues commented Apr 27, 2021

@aferriss
Curious, how do the following look on you screen (I do not have access to a Mac for testing)

Thanks for your time!

@JetStarBlues
Copy link
Contributor Author

  • the matrix aware version renders properly centered on my phone

@aferriss
Copy link

Hmm, I'm seeing very different things than you are.

Screen Shot 2021-04-27 at 1 49 14 PM

Screen Shot 2021-04-27 at 1 49 07 PM

We can skirt the issue entirely by not relying on the resolution values to calculate the shape's position. Here's an updated example that should work the same on every platform

https://editor.p5js.org/aferriss/sketches/uxphKm8AK

@JetStarBlues
Copy link
Contributor Author

JetStarBlues commented Apr 27, 2021

We can skirt the issue entirely by not relying on the resolution values to calculate the shape's position

Oh, I see! Thank you for pinpointing the problem! 🎉🎉

I'm seeing very different things than you are.

I was expecting the results you got. (The matrix-aware version centers correctly on your screen.) But I was mistaken as to why! (Has nothing to do with use of matrix, but rather use of resolution independent calculations as you have pointed out!)

@JetStarBlues
Copy link
Contributor Author

The new version of the code only works with a 1:1 aspect ratio. Otherwise, the shape is stretched.

su_stretch

  • One possible solution is to change the canvas size used in the example from the default of 710x400 to 400x400.

  • Another possible solution is to tweak the code to consider the canvas's aspect ratio and use it to scale the uv coordinates. This approach however, has the downside of not working well with matrix-aware coordinates.

  // move the coordinates to where we want to draw the shape
  vec2 pos = vec2(x,y) - coord;
  
  // force 1:1 ratio...
  float ax = resolution.x / resolution.y;
  float ay = resolution.y / resolution.x;
  if ( ax > ay )
  {
    pos.x *= ax;
  }
  if ( ay > ax )
  {
    pos.y *= ay;
  }

JetStarBlues added a commit to JetStarBlues/p5.js-website that referenced this issue Apr 28, 2021
@JetStarBlues
Copy link
Contributor Author

I have update the linked PR accordingly.

@aferriss
Copy link

Ah yea, good catch on the scaling!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants