Search Unity

Question Textures orientation like fresnel

Discussion in 'Shader Graph' started by namynnac, Aug 6, 2020.

  1. namynnac

    namynnac

    Joined:
    Jun 4, 2020
    Posts:
    9
    I have to understand how Fresnel works, but I cannot because of my stupidity.
    I need to reposition the texture on the ball so that it always faces the camera. Tried to understand the code of the fresnel function in the shader graph, but it's clearly not for my brains. 103 lines of clever code with matrix manipulation and various positions.
    Help as much as you can. I understood from the code that it is necessary to use the camera position, world position and all this should be fed to UV textures, but I did not understand what to do with the variety of these positions before.
    For earlier grateful for any help. Sorry for the bad english.
     
  2. namynnac

    namynnac

    Joined:
    Jun 4, 2020
    Posts:
    9
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    At it's base, a Fresnel is the dot product (ie: cosine) of the angle between the surface normal (direction a surface is facing) and the view direction (direction from the camera to that point on the surface). For spheres, this makes the nice round falloff that people are used to seeing when the term Fresnel gets talked about. On blobby round shapes it's pretty common for that Fresnel style falloff to be used to simulate all sorts of other kinds of effects, like subsurface scattering or transmission (like wax or skin), or outlines, etc.

    For more complex shapes the gradient is less useful. A box for example won't nicely fade out on the edges because that's not what Fresnel is calculating. Indeed the above picture the only real effects of Fresnel are on the water itself, which is highly reflective at glancing angles and nearly transparent when viewed from directly above. That's specifically what the Fresnel equations are attempting to calculate is the fact surfaces reflect more light at glancing angles.

    What you're seeing in the above dandelion is diffuse transmission, the effect of light scattering as it passes through several layers of the semi-transparent "hairs" atop each seed pod.

    This tutorial goes into how to implement the technique from a high level, as well as how to do it for a shader written for the built in pipelines.
    https://www.alanzucconi.com/2017/08/30/fast-subsurface-scattering-1/

    You'll have to figure out how to translate that into the shader graph on your own, assuming you're using the URP. You'll want to look at examples of making a "main light node", which isn't something Unity provides by default. Alternatively the HDRP has a more physically correct version of this with their subsurface scattering systems.