Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HDRP + Refraction

Discussion in 'Graphics Experimental Previews' started by FusRoDahh, Jan 24, 2019.

  1. FusRoDahh

    FusRoDahh

    Joined:
    Jan 20, 2015
    Posts:
    21
    Hi,

    I am having hard time achieving refraction using HDRP Lit shader. First for transparent objects, Surface type needs to be "Transparent" & Blending mode "Alpha" based. From "Transparency Inputs" section, there are two ways of achieving refraction.

    1. Refraction Model based (Box / Sphere) way depends on surface properties such as IoR & Thickness value.
    2. Distortion based model is more of a creative way of achieving refraction when provided correct Distortion Vector map.

    It seems that both these modes can work together (not sure) for more creative freedom.

    First of all, transparency works when refraction model is set to "None". However, appearance is that of very thin glass without any distortion. (which probably makes sense)


    When I switch to either Box/Sphere based refraction model, I see complete black object. Playing around with IoR & thickness values does change the appearance slightly but it's not convincing enough to say that it's refracting background objects. I am not absolutely sure if Refraction thickness map has to be there for this technique to work correctly.


    In case of Distortion method, "Add" & "Replace" Blend mode produces pure black output.


    The only mode that seems to work is Multiply. However, not sure what type of map is fine to be used in Distortion vector map. I understand that RG channel should have distortion info & B channel should have blur info, but it would be helpful to have some reference texture which works. When tried using this texture, I don't see any distortion happening even after playing around with the scale values. I have tried using below mentioned texture as distortion vector map.


    Am sure that something very basic could be missing from my end to achieve the desired effect. Any help for how to get distorted refraction/normal refraction working with HDRP will be much appreciated.

    Unity Version: 2018.3.2f1
    HDRP: 4.8.0

    Thanks.
     
    id0, Deleted User and Tartiflette like this.
  2. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    It's some kind of a bug. I have the same s##t since HDRP 4 or later. All refraction and distortion object are black for me in DX11. In Vulcan everythin is fine, but I don't want to use it, it's crashing my project.

    Videocard Geforce gtx 750-ti, last drivers.
     
    Last edited: Jan 26, 2019
    Deleted User and Tartiflette like this.
  3. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    470
    +same for me
     
  4. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    Hi,

    We have currently an issue with color pyramid used for refraction/distortion.

    Short: It will be fix for 2019.1

    Long (technical):
    We are using compute shader for generating the color pyramid used for these effects. But we read/write float format UAW which isn't support in DX11 specification. This is not an issue on modern GPU as they support it (and console support it too). But old GPU (NVidia GPU 680...) or integrated Intel one follow the specification and don't support it. Which cause a NaN to be produce (thus the black area).

    This is why it works for some users and not for others. We plan on changing the algorithm to use regular shader to be compatible.
     
  5. FusRoDahh

    FusRoDahh

    Joined:
    Jan 20, 2015
    Posts:
    21
    Thanks a lot @SebLagarde for technical explanation, that definitely helps, appreciate it :)

    I can confirm that this issue is appearing on my laptop with Nvidia 675MX GPU. I will try it on latest hardware as well. I quickly changed the graphics API to Vulkan & it seems to respect refraction models. Here is the output for Spherical refraction model with same setup.



    I also get editor error during Vulkan run however which says "Attempting to draw with missing UAV bindings". Perhaps it will help you guys more.

    Regards.
     
  6. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Yeah, I get that error too, Don't even know what that mean, Google say nothing about it.
     
  7. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    So... is there some fix for dx11 on the horizon?
     
    darkydoodle likes this.
  8. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    I'm on 2019.2 a8 and it's still not fixed...
     
    SKoptev and Tartiflette like this.
  9. SKoptev

    SKoptev

    Joined:
    Jan 15, 2019
    Posts:
    37
    Confirm that. "Glass-like" materials either broken at all, or it is unclear how to configure them.
    Please, can you provide small test scene with configured glass objects - with refraction model?
     
  10. CosmosBear

    CosmosBear

    Joined:
    Aug 2, 2012
    Posts:
    67
    I'm on 2019.1.0b9 and it's still not fixed. I'm using a geforce 960 gtx ( so I guess it's an old gpu model) and I have this issue since what? December? I think now would be a good time to fix it before 2019.1 first release candidate
     
    id0 and darkydoodle like this.
  11. Tartiflette

    Tartiflette

    Joined:
    Apr 10, 2015
    Posts:
    84
    I had a 960 too and upgraded to a 1070ti since, and I still have the same issue (on 2019.2).
     
  12. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    When seb means 2019.1 he also means you should update HDRP to the version that is newest for 2019.1 - this will be 5.10 +

    It's not enough to simply upgrade editor, need both.
     
  13. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    hippocoder I have last alpha build and HDRP 6.5.etc and still it's not fixed.
     
  14. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    upload_2019-3-28_18-3-53.png

    upload_2019-3-28_18-5-30.png

    Test shows it's working as expected. Alpha is no guarantee things will work though. The specific versions I spoke of are very much working fine.

    I guess it's still bugged in newer versions.
     
  15. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    hippocoder I'm glad it's working fine for you, but for me on gtx-750 and dx11 it's not working, as well as for other people here. This thread is just about that.
     
    Last edited: Mar 28, 2019
    Deleted User and darkydoodle like this.
  16. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I was merely suggesting that later versions don't always work for example alpha has less features than beta that work right now, dude to GDC. Not trying to undermine your problem.
     
  17. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    hippocoder this problem is already six months old, if not more. In older version of HDRP I have refraction just fine.
     
    darkydoodle likes this.
  18. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    64
    What kind of gpu are you using ? refraction never worked for me. I had 2019.1 hdrp 5.10 and now 2019.2 and I never could have refraction. I have a 770gtx.
     
  19. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    @SebLagarde will have the correct answer if he is not busy. I am going to guess it is logged somewhere.

    Meanwhile will bump and tag as bug on forum.
     
    twistms and SKoptev like this.
  20. Tartiflette

    Tartiflette

    Joined:
    Apr 10, 2015
    Posts:
    84
  21. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    Trying hdrp 6.6 and refraction working now, but... not right

    hole.jpg
     
  22. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    this looks like there is not any blending between mips / pyramid
     
  23. fredericv

    fredericv

    Unity Technologies

    Joined:
    Feb 20, 2017
    Posts:
    8
    Hi,

    Here's a quick explanation of what's happening. The issue is that the refraction is based on screen space buffers, thus we can't fetch all information required to perform refraction for objects with high deviation (medium or big ior in material with high curvature meshes, like a sphere made of glass).

    See the image below.

    RefractionBug.png

    So, a few recommendations when using refraction:
    - Avoid scenario involving high deviation objects in foreground, this is hard to render efficiently in realtime.
    - Try using ReflectionProbe(s) as well, the refraction will fallback on these when screen space sampling fails. It won't be perfect, but it can approximate the refraction in those scenarios.
     
  24. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    konsic, you should install new version of hdrp - 6.6.1 (I use it on 2019.2 alpha). It is where refraction is working. But it's not very stable yet.
     
  25. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    Becuase it's not stable, I won't be using it.
     
  26. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    455
    In that case no refraction for you.
     
  27. konsic

    konsic

    Joined:
    Oct 19, 2015
    Posts:
    995
    I think they will refactor all fixed from HDRP 6.7+ for 2019.1 version.
     
  28. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    @fredericv Out of interest, how are you using the reflection probe data to do refractions? There's still almost zero documentation about reflection probes (most of the info about where to place them, why to place them, what they do/don't do, how they are actually sampled, etc only exists in random forum answers from different engineers throughout Unity, or even Joachim). I'm interested to know how/where I could place a reflection probe and have decent refraction results (and where I'll get bad results!)
     
    LooperVFX likes this.
  29. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,291
    Refraction using the color pyramid in my shader misses transparent objects e.g clouds behind the shaded surface

    Is there a way to address that issue ?
     
    Last edited: Jan 10, 2020
  30. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    For anyone else wondering this ... my guess is that they're using:

    1. refract() on the view ray to get the refracted ray
    2. direct lookup into the reflection probe's environment map, as if the refRActed ray were a reflECted ray
    ...in which case: you want your reflection probes to be above the refraction surface, about the same distance away as the camera is going to spend most of its time, but slightly further (because refraction has the side-effect of increasing the effective camera-distance).

    i.e. a reflection probe for refraction does actually need to be in a different position than a reflection probe for reflection. But Unity doesn't let you have both at once - simply not possible with their design.Yet another flaw in the design of reflection probes :(.
     
  31. Nerochoosingname

    Nerochoosingname

    Joined:
    Oct 11, 2020
    Posts:
    5
    Not being able to do your job sure beats working.
    Absolutely eyerolling nonsense. Every other modern engine can get this done easily, what is going on here?
     
  32. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    A year and a half later ... we actually cancelled a graphics-heavy Unity project because of HDRP. It was SO MUCH worse than built-in render pipeline for some basics like this (refractions). I kept watching the release schedule to see if it was able to do what built-in has done for 5+ years, but core things were still unfixed 12 months ago so: gave up, killed it. I hope it can be resurrected maybe next year.
     
    april_4_short likes this.
  33. Onigiri

    Onigiri

    Joined:
    Aug 10, 2014
    Posts:
    470
    Built-in doesnt even have refraction
     
  34. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    It was easy to add. Doing it in HDRP was not.
     
  35. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,068
    Refraction is working in HDRP.
    The problem is refraction of transparent objects that seams to be not possible.
     
  36. SebLagarde

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    934
    >The problem is refraction of transparent objects that seams to be not possible.

    Hi, You can do it but you need to accept the constraint.

    We only perform one gaussian pyramid to support rough refraction during rendering, as it is already an expensive step.
    This gaussian pyramid is perform AFTER the pre-refraction transparent pass. So if you setup your transparent object to be in the pre-refraction rendering pass, then transparent object will appear in refraction effect. The downside is that you force sorting order of transparent object in this case, we may or not be a problem in this case. This feature is available since few years.

    Also note that you can sample this same gaussian pyramid we generate in shader graph for transparent material (use HDScene Color node) and do your own refraction if you want.

    Lastly the distortion pass is done on top of everything (including the object doing the distortion).

    (Note: Buitin wasn't supporting rough refraction with grab pass. To implement grab pass for HDRP, it would have mean we perform a gaussian pyramid for each call which is not sustainable for game. Grab pass was a performance killer for many platforms, thus why it is not supported neither in hdrp or urp).

    hope this help.
     
    FernandoMK likes this.
  37. a436t4ataf

    a436t4ataf

    Joined:
    May 19, 2013
    Posts:
    1,924
    There is some irony that one of the two SRPs - that were supposed to be better AND faster than Built-in - are unable to support core features of BI because SRPs are too slow :).

    By extension ... why not remove all features from HDRP, because ... you know it's going to be too slow on WebGL1.0/OpenGL-ES2, right? That's a platform! One where everything is a performance killer! So no-one should be allowed any features, this makes perfect sense! /s

    (I have pretty much given up explaining to Unity rendering teams that what they consider 'too slow' is often 'more than fast enough to ship a game and thousands of people still do this on built-in with zero complaints', which is what most people actually care about IMHO)
     
    Genebris likes this.