Search Unity

Bug Refraction Box Model doesn't work

Discussion in 'High Definition Render Pipeline' started by Darkgaze, Jan 7, 2022.

  1. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Hi all.

    I'm trying to create a default Lit Material with reflection and refraction for a simple water material.

    To use refraction, you need to create a Transparent material. Then enable Refraction choosing a model. Since a water volume is a box, I choose the box model... but Refraction box model doesn't do anything. Only the color changes.

    upload_2022-1-7_12-6-33.png

    The official video is outrageous. It talks about changing parameters and it is absolutely obvious nothing is changing at all...




    The thickness "should be set to the thickness of the object in meters". But the parameter can only be 0 to 1. And does nothing.

    The IOR doesn't change the refraction index, or it is not physically correct. It is obvious in the video. This is mentioned in other thread here:
    https://forum.unity.com/threads/cur...-physically-realistic-enough-in-hdrp.1192681/


    The sphere model works but is not useful, obviously for a water volume.


    I was recommended to use a distortion effect instead. But with distortion enabled you need to use an unlit material, and get no reflection, so not useful for water either.

    I'm thinking on adding my own distortion by hand on Shader Graph.
     
    Last edited: Jan 7, 2022
    RobotFlow likes this.
  2. HIBIKI_entertainment

    HIBIKI_entertainment

    Joined:
    Dec 4, 2018
    Posts:
    595
    Now you're the good spotter @Darkgaze

    This actually seems to bring an error up as well


    A multisampled texture being bound to a non-multisampled sampler. Disabling in order to avoid undefined behavior. Please use Texture2DMS in the shader.
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)



    regarding @xiaoxiaoxh124's input on this. the back culling also appears to be due to the fact it's still treated as a solid object for screen space rendering, this would make sense as that would mean it can see around the solid in front of it.

    A puzzling one indeed.
     
  3. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    I think I'll send a report, no bugs related to Refraction are in the Issue Tracker currently.
     
    HIBIKI_entertainment likes this.
  4. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Hey, we are actually working towards improving that and your feedback actually confirms that the workflow is far from great.
    In the meantime, here's what's I think is happening with box model in your scene.

    By default, when there's no reflection probe, the refraction fallbacks to Sky with an infinite projection and that's what actually causing the box model to not be so shiny by default.
    What you need to do in order to make the box refraction works as you expect to:
    • Create a reflection probe in your hierarchy
    • Create a proxy volume in your hierarchy with a shape different than infinite
    • Feed the proxy to the proxy volume variable in your reflection probe.
    • Bake your reflection probe.
    Now the refraction is working properly and the thickness has actually an influence in the refraction.

    You can also do without the proxy volume and tick the box called "Use influence volume as Proxy volume" on your reflection probe settings to simulate a proxy volume from the reflection probe shape.

    Hope this helps.
     

    Attached Files:

  5. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Thanks for the heads up!

    Well. I already had a planar reflection probe and proxy volume set to infinite. Funny thing is that a sphere model works with infinite too.

    I've been trying to make it work without success, mainly because I have no idea how to use the proxy volume, I don't know how the algorithm works, but here's what I've done:

    My surface is a flat surface on the floor of a building, with 0.5y offset from the ground.

    upload_2022-1-13_9-49-1.png

    - I have a Planar reflection probe. The mirror is set up exactly where the surface of the water is. The box space that it holds (influence volume) is set up so that it holds the water plane inside as seen in the previous picture.

    - I have a Proxy Volume set to box. The size of the box holds the whole building. No idea if I have to do that, or not... nothing is stated in the documentation, neither here (https://docs.unity3d.com/Packages/c...tion@12.1/manual/Reflection-Proxy-Volume.html) nor here (https://docs.unity3d.com/Packages/c...efinition@12.1/manual/Reflection-in-HDRP.html) about the meaning of the box size. So I changed the size until I got a perfect reflection, that meant making the box bigger on the bottom. No idea why.

    upload_2022-1-13_9-50-38.png

    - The material set on the water surface is a HDRP/Lit transparent, with Base Map with alpha 4 (out of 255). The transparency iput refraction model set to Box, IOR 1.5, thickness 0.5, and a little transmittance color.

    No refraction happening in all cases. I'm still confused. I'm probably doing something wrong here.

    I uploaded a video to show what's going on, specifically on the column and vase. As you can see, refraction doesn't work in certain angles of the camera towards the plane (beginning and ending). It works for a fraction (middle of the video). Also , some flickering in the reflection is visible as I turn the camera up and down.



    I managed to make it work by hand using Shader Graph and ugly UV displacements using the water normals, but I would love to make this work too!
     
  6. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Qleenie and HIBIKI_entertainment like this.
  7. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
  8. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Let me expand a little about refraction because It's a bit more complicated than "box model is broken".

    Basically, our refraction models, for the most parts, technically works but how they work is not explained very well. This creates misunderstanding about what to expect when using those different models.
    We are currently actively auditing what can be done to explain it better to be able to improve that transparent experience overall.

    That being said, here's a quick recap on what to expect with Box refraction model:

    By default, box refraction will modify the view vector to sample the color pyramid to create screen space refraction.
    The refracted vector is paralel to the input view vector because box refraction model assumes that the output normal is basically -"input normal" (i.e both sides of the glass are also paralel).

    HDRP will cast this refracted ray to a proxy volume to be able to find the hit point (basically where the refracted light will hit) in the environement.
    Finally, if this "hit" is outside screen-space information, it will use the regular sample hierarchy (Reflection probe then sky) the fetch the color of the pixels.

    upload_2022-3-17_16-33-16.png

    Now how and where this proxy volume is defined is the tricky bit.
    By default, if your object is not within the bounds of a reflection probe, the default proxy volume is "infinite" meaning you will get very little refraction. (i.e you will think the refraction isn't working).
    Otherwise it will take the shape of influence volume setup in your reflection probe:
    • Either infinite (default)
    • Use influence volume as proxy volume (so box or sphere depending on what you have setup)
    • Or use any proxy volume already defined (which is box / sphere or infinite anyway)
    This proxy volume is almost always an approximation since it's very simple primitives.

    Now, after this recent "fix", the new default for box refraction is not infinite anymore. The shape used for the default proxy volume is the bounding box of the object itself which is still not perfect but gives a result that is more expected by users out of the box.

    Also, for what it's worth, thin refraction model, is just box model with fixed thickness of 0.005m (5mm)

    So to answer the questions, This fix (about refraction) has not been backported because it relies on being able to retrieve the bounding box of an object which is only available on recent engine versions.

    However, this fix (about your XR issue) has indeed been backported up to 10.x.x (and 12.x.x) and will be available when thoses packages are updated.

    Hope this helps clears some of the confusions.
     
    Last edited: Mar 17, 2022
    Darkgaze and Qleenie like this.
  9. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    So if I want to use refraction e.g. for the Cornea of a human eye, would be the best approach to have a narrow reflection probe at the character head in order to get (thin) refraction? I am using reflection probes already, but in room size.

     
  10. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    PS: just did a test, and indeed it seems refraction starts working as exepected with the reflection probe! This is somehow very counterintuitive, also this reflection probe would need to be realtime to provide accurate lighting. However, I can reduce the weight to near 0, and the refraction still works, with the reflection probe not providing inaccurate lighting anymore.

    A very bad workaround, but I guess this kind of information should be as a warning in the documentation.


     
  11. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Yep, this is why we are trying to improve here.

    Technically, the reflection probe is just here to provide a "shape". If your refracted ray still falls within the bounds of screen space refraction (the pixel that we need to fetch is not outside the screen), only the color pyramid will be sampled (i.e the background of the scene containing opaque objects).

    The actual data of the reflection probe is used ONLY when the refraction is so high that the refracted view vector hit outside the screen (happens more with sphere refraction models because of its implementation).
     
  12. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    868
    would it not be better then to offer an own component to provide the shape ? as so I'll have now the overhead of reflection probe, without using it really besides offering the shape.

     
    Darkgaze likes this.
  13. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    766
    Technically yes, it would be interesting, and it can make sense in some scenario, but in a common correct lighting scenario, you technically already have reflection probes setup so in a way, it's kind of an optimisation to use them not only for reflection but for refraction as well.
    It's already painful to setup many reflection probes in larges scenes, imagine having to do twice the work..

    By putting the the weight of the probe to 0.001, you are essentially still fully using the shape without using its data. So yeah it works and it's the downside of using the same object for reflection and refraction.

    Also, keep in mind that eventhough for refraction the data of the reflection probe (wether it's baked, custom or realtime) won't necessarly be used, it needs to have some data, (even a black 1x1 texture in a custom imported as cube), otherwise HDRP will discard it, same if weight equals zero.