Search Unity

  1. Unity 2019.2 is now released.
    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, SiriusRU and Tartiflette like this.
  2. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    287
    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
    SiriusRU and Tartiflette like this.
  3. Onigiri

    Onigiri

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

    SebLagarde

    Unity Technologies

    Joined:
    Dec 30, 2015
    Posts:
    435
    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:
    287
    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:
    287
    So... is there some fix for dx11 on the horizon?
     
    darkydoodle likes this.
  8. darkydoodle

    darkydoodle

    Joined:
    Oct 27, 2018
    Posts:
    42
    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:
    28
    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:
    30
    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:
    42
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    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:
    287
    hippocoder I have last alpha build and HDRP 6.5.etc and still it's not fixed.
     
  14. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    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:
    287
    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
    SiriusRU and darkydoodle like this.
  16. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    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:
    287
    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:
    42
    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 Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    @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:
    42
  21. id0

    id0

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

    hole.jpg
     
  22. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    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.
     
    hippocoder, id0 and Tartiflette like this.
  24. id0

    id0

    Joined:
    Nov 23, 2012
    Posts:
    287
    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:
    632
    Becuase it's not stable, I won't be using it.
     
  26. id0

    id0

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

    konsic

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