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. Dismiss Notice

Bug HDRP Eye Shader Issue

Discussion in 'High Definition Render Pipeline' started by Passeridae, Jan 9, 2021.

  1. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    Okay, here's an example scene that comes with HDRP package samples:


    And here's a default cube. As far as I know, it roughly equals 1 meter inside Unity world.
    Every eyeball in this scene has 1*1*1 scale. Which means they are deliberately created and imported as gigantic 1-meter eyeballs. And it seems Eye Materials and Eye Shader Graph were calibrated for this scene because they have hardcoded and/or constant values that work only for these enormous eyes. If you import an eye that has a real-world size (or, in fact, any size that is considerably larger/smaller than ~1 meter) you'll get a completely broken material. The same goes for the pivot of the eyeball - It's expected in the same place and with the same rotation as in the example. The pivot part is logical, but it should be documented and mentioned inside the scene, anyway. As for the size, it needs fixing. Not really convenient to import an eyeball with 29x scaling factor and then scale it down to 1/29 to make the shader work. Probably someone has forgotten to change units from feet to centimetres in the DCC package where these eyeballs were modelled.
     
    Last edited: Jan 11, 2021
    Win3xploder likes this.
  2. Win3xploder

    Win3xploder

    Joined:
    Dec 5, 2014
    Posts:
    159
    I agree, make the eyeball radius exposed.
     
  3. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,227
  4. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    1306789
     
  5. UnityMaru

    UnityMaru

    Community Engagement Manager Unity Technologies

    Joined:
    Mar 16, 2016
    Posts:
    1,227
    Thank you - i'll escalate this internally for you.
     
  6. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    695
    Got some more info on this one.
    While this can be indeed confusing, this is expected and AFAIK there's nothing wrong with the shader. They are two things at play here
    • If you scale the eye balls to a real world scale you should also change the world scale in the eye diffusion profile accordingly for the SubSurface Scattering to behave properly.
    • Scene contains only one directional light and they don't work well with very small objects, so you can add some punctual lights to avoid some weird lighting when viewing from certain angles.
    Sample scene have been updated with some detail about it to prevent further confusion.
     
  7. Passeridae

    Passeridae

    Joined:
    Jun 16, 2019
    Posts:
    395
    There is nothing wrong with diffusion and sss.

    That wasn't the problem either.

    The problem is that you'll have no retina and pupil if your eyeball is not as big as the ones in the example scene. You'll also can get other issues, like tiling, or a pupil that is so large, that it covers the entire eyeball in other cases of size mismatch. That is the problem. It's controlled not by a diffusion profile, but by a constant inside the shadergraph that is set to 0.22 if I remember correctly. If you tune this value, you could scale retina and pupil to match your eyeball mesh, but it doesn't look exactly right, so the problem might be even deeper. And this is a constant value, not a property, anyway. And the necessity of a very specific pivot placement which is not mentioned anywhere is also somewhat confusing.
     
    Last edited: Jan 22, 2021
  8. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,050
    as it was mentioned, there are hardcoded numbers that work correctly only on the huge scale, not sure why, so you can't just use the material to your existing eye at a normal scale, it will not look correctly

    I've "fixed" this issue for now by doing:

    scaled down the big eyeball to normal human level, noted the scale factor, then calculated the correct "world scale" for the diffusion profiles (both iris and sclera), multiply the existing number of 0.025 to how much you have scaled down the huge eyeball. for normal human was around 0.85

    this fixed the reflections, shadows, lighting. looks great.

    if you want to use your own eyeball, didn't tried, but I assume you need to import it at the same huge size like that eyeball is, and then scale it down.

    now you may find that unfortunately the iris area is too huge for a realistic human. It looks great if you need an anime or pixar type of character but for a realistic look it doesn't look right.

    this is simple to fix, duplicate the the SG_Eye shader and rename it to something else to have a backup if you screw something, assign this new shader to your eye material so you actually use it in the scene, then open the shader in the shader editor

    here, find all references to "Iris radius", and change the number that is assigned there, in my version the number is 0.22, I've change it to a smaller number, I use something between 0.15 to 0.17, see what works best for you.

    make sure you change all the numbers where iris radius is mentioned!!! there are a few. if you don't do it you broke the effect.

    also maybe you already know but you need to save the shader to see the changes in the scene,

    I've gone a bit further and created a new float variable in the Shader Graph input properties and connected it to every occurrence of the Iris Radius. This way I can change the number in real time in the scene to see how it looks. Probably who prepared the example forgot to do this, probably in future versions this will be already implemented.

    Finally you may open the sclera texture in an editing software and play with the luminosity if you think the eye pop up too much comparing with your skin texture.

    hope this helps some lost soul, I've lost weeks last year trying to find/create a good eye shader for my model with no luck.

    While this unity example shader is somehow broken who create it have all my blessings as I finally have decent human in my game with good looking eyes.
     
    Autarkis and sqallpl like this.
  9. pauldrummond

    pauldrummond

    Joined:
    Oct 30, 2014
    Posts:
    145
    I made a copy of the shader and exposed the properties for IrisRadius and IrisPlaneOffset. I used these instead of the hard-coded values in the shader and now the eye material is easier to use. However, something within the shader code still requires the eye mesh to be very large, then scaled down. In this image both meshes are using the edited eye shader. The closest model is from the HDRP samples. This is actually a very large model which is scaled to 0.02437391 in Unity. The other model in the image is a mesh created at actual size, so at scale 1 in Unity. The edited shader allows me to adjust IrisRadius and IrisPlaneOffset, but only the scaled mesh correctly blends the sclera and iris textures. The second eye model seems to lose the sclera texture somewhere in the blending because it doesn't have the same size/scaling ratio as the HDRP sample.



    If the HDRP eye shader could be updated so that IrisRadius and IrisPlaneOffset are exposed, and the shader doesn't rely on the mesh size/scaling it would be much appreciated. At the moment the eye shader isn't really useable.
     
    Deleted User likes this.
  10. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    Another instance where they didn't check the feature with real projects, just controlled tests. :(
     
  11. pauldrummond

    pauldrummond

    Joined:
    Oct 30, 2014
    Posts:
    145
    Will there be any more work done on the eye shader? It looks promising, just not quite ready for production use.
     
    sqallpl and Deleted User like this.
  12. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    695
    Hey, the eye scene shader graph in the HDRP Material Samples is made specifically for this mesh at this specific import scale. Changing its import scale factor or changing the scale in a 3D software will mess with its object position and will produce unwanted results like you said. You already saw some issues that it can cause with iris radius and iris plane offset that needs to be adjusted.

    However, it's totally possible to change its scale in the gameobject transform as long as you ajust the world scale of the diffusion profile accordingly. A quick PR has been made to clear that and avoid further confusion.

    However, It's up to users to modify the graph if they want to use a slightly ajusted scale model or with different UV etc, there's no perfect solution to have a graph that account for every possible mesh, eye types and setup.

    Is there a reason why you need to have the scale of the eye at 1 for a an eye of 25mm in unity world scale ?
     
    Deleted User likes this.
  13. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    If I'm understanding this correctly, then we would need different Diffusion profile for each of the size of eye present in a scene right?

    Also, what if there's a scene where we need to scale the character(along with the eye) in front of the camera, how should we make the eye behave properly in that instance?
     
  14. pauldrummond

    pauldrummond

    Joined:
    Oct 30, 2014
    Posts:
    145
    The diffusion profile doesn't make any difference.The problem seems to be in the shader and its relation to the eye mesh size. At the moment it isn't useable.
     
  15. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    695
    Exactly.

    For this one, unfortunately, this is not possible yet since the diffusion profile API is not exposed to users (it's internal to HDRP). If you want to modify HDRP (change the classes and functions to public), it will work though.

    The two solutions would be to either swap diffusion profile at runtime in your graph or to get a reference to the diffusion profile used and modify the world scale at runtime.

    This is on the road map and will most probably be integrated in Unity 2022 at some point.

    As long as you keep using the same model in the sample (and not change the import scale factor), you can change the local scale of the eye ball and all you need to do is to update the world scale of the profile accordingly.
     
  16. koirat

    koirat

    Joined:
    Jul 7, 2012
    Posts:
    2,008
    Just wanted to say that some months ago I also got this problem with the eyes.

    Now I assume most people will use eyes mostly for human size like characters, so why such a stupid arbitrary size of eyes ?

    I could even understand if those eyeballs were of 1 unit in diameter (especially if scaling was working), but no someone decided to pull the dimension out of their .... .
     
  17. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    927
    Isn't there a way that this function could be transferred over to shader side, to calculate the final diffusion texture(I guess this is what gets calculated on the Diffusion profile asset), is this technically impossible?
    If it's expensive then you could just add an option to use a baked version or to calculate at runtime using shader (or maybe I'm just an idiot who doesn't understand this topic enough :p)
     
  18. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    695
    FYI, related to this discussion, some work has been done recently to support more use cases:
    • A scale parameter has been added to the eye shader so that you can have different import eye scale (more details here)
    • Diffusion Profile API has been exposed so that the worldscale can be changed according to the current scale of the object that use SubSurfaceScattering. (more details here)
     
    douaakh, koirat and Ruchir like this.
  19. pauldrummond

    pauldrummond

    Joined:
    Oct 30, 2014
    Posts:
    145
    This will be very helpful. Thank you.
     
  20. nyudeb

    nyudeb

    Joined:
    Mar 20, 2015
    Posts:
    19
    Hi, i'm trying to make this shader work on our eye mesh with a 'Skinned Mesh Renderer' to be able to make it rotate with bones. But if the material is set on the 'Skinned Mesh Renderer' the pupil is not visible. If I put a 'Mesh Filter' + 'Mesh Renderer' with the same material, it work.

    Maybe someone have a solution for this ? :)
     

    Attached Files:

  21. Remy_Unity

    Remy_Unity

    Unity Technologies

    Joined:
    Oct 3, 2017
    Posts:
    633
    This is maybe a bug, could you make a bug report and send a minimal reproduction project with your assets over ? https://unity3d.com/unity/qa/bug-reporting

    In the meantime, I guess you can use a meshfilter/renderer attached to the bone to make the rotation instead of using skinning ?
     
    nyudeb likes this.
  22. minte131

    minte131

    Joined:
    May 11, 2019
    Posts:
    5
    I'm not sure if it's too late, but I also converted this shader from HDRP to URP with acceptable results for the game (in my opinion). I also had trouble applying the shader to a realistic-scale eye and failed after trying all the suggested fixes here.

    I figured out that they used the position and the mesh scale to create a Mask that was used to lerp the iris and sclera. You can easily fix this by creating a texture that is similar to that Mask and then replacing it.
     
    chap-unity likes this.
  23. minte131

    minte131

    Joined:
    May 11, 2019
    Posts:
    5
    By the way, we can use another way to avoid creating a texture. This way gives us a better gradient than getting information from pixels. Overall, this shader depends on the mesh's UV, where the center of the iris is at the center of the UV.

    forgot to add the function: saturate(distance(UV, float2(.5,.5)) - _Offset)
    replace float osRadius = length(positionOS.xy) by this result inside the ScleraLimbalRing and ScleraIrisBlend. Hope this help hehe
     
    Last edited: Aug 7, 2023
  24. Qleenie

    Qleenie

    Joined:
    Jan 27, 2019
    Posts:
    736
    Sorry for being late here, too. Is the issue that Eye Shader does not work correctly with SMR a Unity Editor bug, or a bug of the digital human package? I'd guess second, shall we still make a regular bug report for this?
     
  25. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    695
    I'd make a regular bug for the UnityEditor indeed ! :)
    Thanks in advance !
     
    Qleenie likes this.