Hi, I’m new with shader graph and also with shader in general. I’m trying to create a pixelated gradient noise in world space and have it appear with the same pixelated transparent edge. I’ve achieved the pixelated gradient noise but I’m having difficulties in understanding how to get the same world pixelation and apply it to the object’s UV position.
Here’s what my current shader graph with a simple Alpha UV distance.
The short version is it’s doable, but it takes some doing to accomplish. The example in that link snaps world position to match a pixelated UV rather than the other way around, which you could try to reverse engineer. The main issue is UVs are in an arbitrary space unrelated to world space, and it’s not entirely trivial to convert from one to the other, which is what the above linked thread is attempting.
The other option is to not use the UVs at all, but rather use a world position and xy size, which would already be in world space, to calculate the alpha from. For a sprite, you’d have to have a c# script that sets this on the material as you move it around. But if you can use a regular mesh instead you can extract this information from the mesh’s transforms along with knowledge about how big the original mesh’s bounds are to ensure you don’t try to make a circle larger than is visible. But then you loose a lot of the various UI related features which you may want or need.
just to add on to what bgolus said, if you can have the gradient on the same material as the texture you’re trying to apply it to, (only if you can use uv’s for your gradient instead of worldpos) you can just floor/ceil the uv at pixel size to clamp them all to the same position, optionally moving it forward or backward a half texel to sample the center of the pixel. i also highly recommend the link he posted, i’ve used the calculations from there and can help with your implementation if you need.
Thank you for the replies !
I’ve tried to read the aforementioned thread but I didn’t understand any of the content since I have no prior experience with shader scripting.
Also with the second option I’m not sure hot to calculate the alpha but I found that if I Distance the Pixelated World UV with a vector 2 and feed the value manually, the edge transparency pixelation will follow with the world one. Though this would only allow 1 of the patch exist and the shape fixed as a circle because of Distance. What I want to achieve is to have several objects with this shader for patches of water ripple.
I’m sorry if my understanding is too basic. If there are any materials for beginners regarding this/maybe shader in general would also appreciated.
Thanks !
The solution you have above is the “easy” solution. And it doesn’t allow for just one patch, but as many as you want. With the caveat you need to make the object position a material property, and then set it with a c# script on each object.
As for learning what’s going on in the above linked post it’s less a problem of shader code and more one of complex math. You can take some classes on khan academy on linear algebra and differential equations… and then still be confused as you need to understand how the two combine.
(That’s not snark btw, I’ve been doing this for two decades and still have problems wrapping my head around it even though I understand it from a high level.)