Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Water drop on camera

Discussion in 'Shaders' started by idurvesh, Sep 24, 2015.

  1. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Hi, How can I create water drops on camera something like we see in Ripitude GP,


    I tried using Unity's default GlassStainedBumpDistort shader though its performance heavy on mobile plus it do not let animate water drops.

    Plz help in,
    Thanks in advance
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,449
    Here is how I implemented this effect in a previous non-unity project. The principle can be applied to Unity though.

    Drops are rendered using particles into a RenderTexture. The particle texture represents a distortion map, which means the textures' red channel encodes the horizontal displacement and the green channel the vertical displacement of a pixel. Particles change transparency over time and alpha is used to modulate the distortion intensity. This allows to change the distortion intensity using the particles alpha.

    Since you need the displacement to happen in both directions left/right and up/down, the distortion texture is interpreted like this:
    • black (0) indicates full distortion to the left/up
    • gray (127) indicates no distortion
    • white (255) indicates full distortion to the right/down
    (due to texture compression, "no distortion" is often not possible but also not really needed)

    You need to render particles additively (see shader blend modes) into the RenderTexture. This makes sure when particles overlap, the distortion gets stronger.

    Once the scene and distortion RenderTexture has been rendered, you compose the final image using these two textures as input.

    Composition works like this. You create a custom image effect shader and pass the current scene/framebuffer and distortion RenderTexture to the image effect. The image effect first reads the distortion RenderTexture. Then it reads the current pixel from the scene/framebuffer, but offsets the texture-cordinates by the value stored in the distortion RenderTexture (you need to transform the distortion value from 0..1 to -1..+1). The final step is simply to output this pixel.

    Hope it helps!
     
    Last edited: Sep 24, 2015
  3. idurvesh

    idurvesh

    Joined:
    Jun 9, 2014
    Posts:
    495
    Thanks for great explanation, I have little question though, wouldn't it get heavy on mobile? I don't have great knowledge of shaders thing could you refer some shaders for same?
     
  4. gwydion1

    gwydion1

    Joined:
    Jan 18, 2019
    Posts:
    3

    just gunna drop this here its not from me but its worth checking out
     
    adamgolden likes this.