Search Unity

Question Refraction Effect

Discussion in 'Shaders' started by MatheusMarkies, Oct 1, 2020.

  1. MatheusMarkies

    MatheusMarkies

    Joined:
    Apr 16, 2017
    Posts:
    67
    Good afternoon.
    I would like to know how I can create a refractive effect.
    (I'm not using HDRP or URP)
    I intend to use the camera's backbuffer as a refractive image, but I don't know if that is the best way. translucent_01.png
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,343
    It's not really that simple. Most refraction in games is faked with simple screen space UV distortion rather than actually attempting a real refraction. Other games abuse reflection probes, which means refractions can see things off screen, and it also mean you just need to calculate the refraction ray direction in world space and "you're done". Of course the refractions won't be accurate still, just like reflections aren't, and don't show anything in the scene.

    I know of a small number of games that have abused their screen space reflection system to also do screen space refractions, since to do "real" refractions requires the same raymarching against the scene depth to get the appropriate hit location. And like screen space reflections, there are lots of cases where the refraction ends up hitting nothing or "seeing" something that's occluded on screen.

    And it ends up being a lot of work for something that humans can't really tell if it's wrong most of the time. Hence why just naively offsetting the screen space UV by the view normal ends up being what people use most of the time.
     
    MatheusMarkies likes this.