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

Issue with example stone #11

Open
Vipitis opened this issue Jan 9, 2024 · 12 comments
Open

Issue with example stone #11

Vipitis opened this issue Jan 9, 2024 · 12 comments
Labels
bug Something isn't working

Comments

@Vipitis
Copy link
Collaborator

Vipitis commented Jan 9, 2024

the example shadertoy_stone does not quite match with it's reference on the website:

  1. mouse event stops the rotation Fix mouse events #14
  2. odd lines in the "texture" (will test this on a different system too)
  3. straight cut in the geometry

website:
website reference

wgpu-shadertoy:
snapshot method

@Vipitis Vipitis added the bug Something isn't working label Jan 9, 2024
@Vipitis
Copy link
Collaborator Author

Vipitis commented Jan 24, 2024

checked on my Laptop (nvidia T500) and there is also texture and geometry issues... but they are different. Will try to grab a a screenshot later. Something is wrong in the wgpu math, and I will try to break it down to a minimal example... could take a bit

@Korijn
Copy link
Contributor

Korijn commented Jan 24, 2024

Could be driver or hardware differences relating to precision. Are you comparing against official shadertoy on those devices too?

@Vipitis
Copy link
Collaborator Author

Vipitis commented Jan 24, 2024

The experience on the website is consistent across devices (and good). According to the comments on the website, something might be going on... breaking it down to a minimal example might help.

@Vipitis
Copy link
Collaborator Author

Vipitis commented Feb 14, 2024

I have been encountering other Shadertoys that look vastly different on the website versus with wgpu. At least some of this seems to be down to pow() with negative numbers (but only when there is expressions). In fact, the website even warns you about using negative numbers here.

I produced this minimal example

website:
website screenshot

wgpu-shadertoy:
snapshot_method

This might be one case where we can't really have a solution. Since it is undefined in GLSL so the behavior could really be anything.

I am looking at some other shaders where the behavior is different, and will try to reduce them to something minimal. Then post their differences here as well. Perhaps this Issue could become a "differences between the website and our implementation" thread.

@Korijn
Copy link
Contributor

Korijn commented Feb 14, 2024

Is the behaviour also undefined in WGSL?

@Vipitis
Copy link
Collaborator Author

Vipitis commented Feb 15, 2024

The wgsl spec doesn't mention anything, it could be defined via exp too.
I tried it with a quick translation and it behaves the same as GLSL in wgpu. The hole might go deeper, since hard coding any even number like 2.0 or 4.0 to be y, gives you the yellow, while hardcoding any odd number gives you the green. What happens in between is what differs between wgpu and website

E: it's still an open issue - gpuweb/gpuweb#2765 (comment)

@Vipitis
Copy link
Collaborator Author

Vipitis commented Feb 16, 2024

If you were to replace the implementation of pow() with this macro, you get a matching result for the minimal example. Doesn't seem to fix stone tho. I will have to try some more.

#define pow(base, exponent) (exp2(log2(base) * (exponent)))

The other inconsistency I found was with a shadertoy like this: https://www.shadertoy.com/view/4sySRG and it seems to be down to nested loops. But that might really be a wgpu issue, could be similar to this: gfx-rs/wgpu#5246

@Vipitis
Copy link
Collaborator Author

Vipitis commented Mar 7, 2024

wgpu-py v0.15.0 includes the fix for nested loops. And that fixed quite a lot of visual glitches with shaders like the one linked above.

However the example stone has not been fixed by this. I will have to take some time and dig deeper...

@Vipitis Vipitis changed the title Issue with mouse input for example stone Issue with example stone Mar 13, 2024
@Vipitis
Copy link
Collaborator Author

Vipitis commented Mar 18, 2024

After some hours of trying to deconstruct this shader and find the function at the root of this errors... it seems to be sin which lead to a different rabbit hole. But it seems like using sin with really large numbers behaves differently between GPUs and APIs.

I even got to the point where the website seems to behave more wrong than wgpu... (but that could be due to my Intel graphics card too). One of those examples is here: https://www.shadertoy.com/view/7tV3RV which finally lead me to this investigation: https://danilw.github.io/blog/Hash_Noise_in_GPU_Shaders/

So it seems like there won't be a good solution to this problem.

@Korijn
Copy link
Contributor

Korijn commented Mar 18, 2024

So essentially the shader in this example is relying on a broken noise function?

@Vipitis
Copy link
Collaborator Author

Vipitis commented Mar 18, 2024

it's seems to be a common method for hash and noise functions. But those should just be slightly inconsistent across devices. Not straight up broken. So I believe there is another issue compounding onto it.

I will try to fork the shader and replace the noise functions with something that should be consistent to see if that solves it.

@Vipitis
Copy link
Collaborator Author

Vipitis commented Mar 22, 2024

here is my attempt at a fork with different hash functions. https://www.shadertoy.com/view/M32SR3 however the issue remains. Will have to keep digging when I am back in a week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants