I tried your code, and first, it seems I didn’t explain the use of sprite_get_width
and sprite_get_height
correctly. Actually, you need to either divide sprite_width
by image_xscale
or use sprite_get_width(sprite_index)
. I just didn’t expect you to have image_xscale
applied in your case. So, when using sprite_get_width
, there’s no need to divide by scale.
As for the code: it’s correct, and the issue could come from two things—either the "separate texture page" option isn’t enabled for the sprite/noise, or it’s related to scaling, which I didn’t mention earlier. The thing is, if you scale the object that uses the shader, it will only display correctly at whole number scales. Using non-integer scaling will make the shader behave inaccurately, not pixel-perfect.
I was aware of this issue before, but honestly, I don’t know exactly why it happens or how to fix it—or if it even needs fixing, since pixel art rarely scales at non-integer values. If scaling is the issue, I’m afraid I can’t help much for now. As I mentioned, the only solution is to use whole numbers for scaling.
If the problem isn’t with the "separate texture page" setting and you aren’t using non-integer scaling, I’m not sure what else it could be, since everything works fine on my end with your code. Please send me the dimensions of the sprite you’re using with the shader. When I initially created the shader, I noticed some issues with specific dimensions and fixed them, but it’s possible your case wasn’t covered. However, I’m fairly certain the issue is either related to scaling or the "separate texture page" setting.
EDIT:
Right after I sent that message, I found a solution, though I don’t fully understand why it works. It seems that the fix I mentioned earlier—one I made during the shader’s development—might be causing this issue. So, it looks like you can either fix that issue or this one, but not both. It’s... strange.
Basically, in the fragment shader code, on lines 22 and 23, you can remove the +0.000001
part, and from what I can tell, the scaling issue will go away. However, I’d recommend to wait for the update with actual fix.
EDIT2:
I also forgot to mention that you can actually use non-integer scaling, as long as it's a multiple of 2—like 0.2, 3.6, 10.8, and so on. That’s exactly how it works in the demo.
EDIT3:
Okay, after some quick testing: the solution from the EDIT works, but I wouldn’t recommend using it, as it might cause other issues—there’s a reason the original fix exists. Instead, I’d suggest following what I mentioned in EDIT2: if you want to use non-integer scaling, stick to multiples of 2. I don’t have any other ideas on how to handle this for now.