- Home /
Best implementation for spraying water on a surface like in Super Mario Sunshine.
To be clear, I'm not talking about the goop from Mario Sunshine. I'm referring to the fact that when you spray water, it creates puddles on the ground and walls which Mario can slide around in. I currently have an implementation of this which uses a texture to store which pixels on the surface are wet and which are dry. Then a compute shader runs every frame to set any wet pixels which neighbor dry pixels to be dry. While this does work, it needs to be segmented into chunks in order to not hinder performance, and I'm not sure quite how I would add the water to a spot where there is a border between chunks. All the water would go on the chunk where the center of the puddle was. I would need to do some kind of sphere-cast to find all the chunks within range of the puddle, then find a pixel that was on the chunk and the right distance away.
So, I was re thinking it, and I believe the implementation Mario Sunshine uses creates a bunch of spheres that represent wet places. I had thought of this implementation earlier, but had thought that it would look bad unless I used odd capsules, but I'm now thinking spheres would be fine. I can see exactly how to implement this in terms of making the surface slippery to my character, but I'm not quite sure how to render it. I think I would need to generate some kind of screen texture representing all pixels where the exterior of a wetness sphere is visible, and one representing all pixels where the interior of a wetness sphere is visible (or maybe they could be different channels of the same texture). Then I could apply a wet-looking post-processing effect to all pixels for which the exterior of a wetness sphere is visible but not the interior (representing that the pixel that the camera sees is inside a wetness sphere). The issue I believe that I would run into is that if there are multiple spheres overlapping, the camera might see the interior of a wetness sphere that is inside another one. Thus, only the closest wetness sphere would work for a given pixel. This makes me think I would need to count the number of wetness spheres I had entered, and then the number I had exited, so as to know if I was really in one or not. Then I foresee the problem of what would happen if my camera is in a wetness sphere. I would need to know how many I was in at a given time, since the camera wouldn't see the exterior a wetness sphere that it was inside of.
I'm open to other possible implementations, or ideas on how to apply a post-processing shader to pixels only within some bounds.
As of now, I'm thinking the second implementation will be easier to implement and more scalable, but I'm still not quite sure how to do the graphical part of it.