Vertex Shader Colliision

I’m making a game that involves an infinite ocean and rain. I’ve already made the rain using Unity’s particle system and a vertex shader for the ocean (that displaces the vertices vertically based on world position so it is infinite/tileable). The problem I’m facing is when I want the rain particles to form raindrop subparticles when they collide with the ocean mesh. Since the vertex shader doesn’t modify the mesh and it only distorts it visually, the rain doesn’t properly collide with the ocean’s surface. How would I go about making the ocean mesh distort with the shader, or alternatively, the rain particles able to collide at distances calculated at runtime?

Unfortunately, there is bo performant and instantaeous way to get the information out of the shader and back to the CPU side so you’re going to have to do one of two things either somehow determine the position of each droplet splash emitter analytically and determinitically in such a way that it can syncronize with the movement of the verticies of the mesh or write a shader just for the splashes that positions effectively does the same thing. Another less accurate but probably much simpler solution would just be to bake the splash effect right into a texture applied over the ocean mesh. I doubt anyone would notice if it doesn’t line up perfectly with each falling rain droplet.

Thanks for your response, it led me in the right direction. At first, I tried using ParticleSystem.GetParticles() and detecting if each raindrop was lower than the surface of the ocean (the ocean waves are deterministic and based on world space). Unfortunately, since the drops were falling so fast, it wasn’t accurate enough. Instead, because the raindrops perfectly form splashes when they hit a collider, I had the idea to generate a small procedural mesh (with collider attached) that follows the player around and conforms to the ocean. Even with a really low quad resolution, the splashes now look really convincing. Solved!

1 Like