-
Notifications
You must be signed in to change notification settings - Fork 420
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
Normalizing coordinates in shaders #341
Comments
Great question, @schiller-manuel - will get back to you soon with a quick example and some pointers! |
256 is the width and height of the documentation examples. when doing pos/256 is equivalent to pos/vec2(width, height), the goal behind to get a value that goes from 0 to 1 |
Another way to solve this which is common when writing shader code is to provide the resolution x/y as uniforms to the shader. |
OK, how can I get the canvas size in case it's not fullscreen? |
There once were intrinsics in skia that provided access to width and height: I tried using the |
Haha thks for pointing us to these commits :)) We do have a useCanvas() hooks that will provide you the width and height. |
I just had a look and it looks like this will need further discussion with @chrfalch so we agree on the final form of this and document it. |
Sounds like a plan! |
Can you please explain why and how coordinates in shaders must be normalized?
I looked at the example here:
https://shopify.github.io/react-native-skia/docs/shaders/overview#simple-shader
It produces the following output:
![Simulator Screen Shot - iPhone 13 - 2022-04-03 at 20 53 08](https://user-images.githubusercontent.com/6340397/161443583-d77a13f1-c94c-4575-a30f-d4488fae7a26.png)
Without normalizing, it produces:
![Simulator Screen Shot - iPhone 13 - 2022-04-03 at 20 53 25](https://user-images.githubusercontent.com/6340397/161443595-d8281ffe-f8bb-4bec-a508-93fc7e9fb518.png)
Where does the
256
come from?If I want to fully fill the screen, should
pos.x
be divided by screen width andpos.y
be divided by screen height?This produces a uniformly distributed gradient:
If my canvas is not fullscreen, where do I get its dimensions from for normalization?
The text was updated successfully, but these errors were encountered: