Search Unity

Question Common techniques to apply multiple instances of the same vertex deformation shader

Discussion in 'Shaders' started by smubi, Sep 30, 2022.

  1. smubi

    smubi

    Joined:
    Mar 1, 2022
    Posts:
    1
    Hi. I am creating water shader for mobile and would like to make a ripple effect at different spots of the mesh at the same time. I already have created ripple effect in shader graph (URP) that deforms vertex of a mesh. Right now, I can control a single spot on the object where ripple happens but I am struggling to find a way to apply multiple instances of the same effect at the same time (e.g. When multiple objects hit the mesh at the same time at the different places, should create unique water ripple effects). I was wondering what are the common techniques to do that without hitting a bottleneck really quick with every new instance, taking into consideration that this is targeted for mobile devices. Thanks.
     
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    How many ripples are we talking? For up to maybe 4, you can just have multiple inputs to the shader (or an array) and loop through all of them. Might be a PITA to do in shader graph instead of manually written, but should be fairly straightforward to do if you got the first one working :)

    For more than that, you'll probably want to grab the vertex buffer and modify them in a compute shader. Most mobile devices should support this, and it's fast but you're looking at a couple days work to do all the integration.
     
    smubi likes this.
  3. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Create an array of ripple values and loop through them in the shader. On the C# side you can adjust time of the ripple effects and update them onto the GPU each frame.

    I can't remember if ShaderGraph has an array input option yet though, so you'll probably have to write it as a property in a Custom Function node, then you'll be able to assign to that property from code using
    mat.SetVectorArray("_Ripples", rippleArray);
     
    smubi likes this.