Search Unity

Translucency and SSS Experiments

Discussion in 'Assets and Asset Store' started by FPires, Mar 8, 2016.

  1. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Some months ago I posted some screenshots of my tests with some translucency shaders. Due to RL stuff I couldn't continue to develop on it further. The original thread is here. I still get some messages asking about it from time to time, so I've decided to release it. I attached to this post a package with a translucency shader and a custom script to bake the required maps.

    First, I'm not sure if this method has been tested before, or if it has a name. I didn't find any research pointing towards this method of simulating translucency - if you know of any, please let me know. My main motivation towards developing this was to create a shader that simulated some light scattering, since most free shaders that mimic translucency seem to be just playing with light wrapping and backlight.

    IMG0.png

    My idea was to use two object-space normal maps, one for the positive and one for the negative axis, to customize how light shines through the object, so instead of rendering a single map that points out which direction light is being reflected, I make two maps instead pointing out how much light is being reflected in regards to each direction. With two of these maps I can overlap the directions in which light is visible, so the same pixel can reflect light both from the positive and negative axes. This means I can bake how translucency looks in a way that takes the light direction in consideration.

    So basically one map renders light reflectance from +XYZ as RGB, and the other map renders -XYZ as RGB. If they were representing a standard object they would be exact opposites of each other.

    The ideal way to render these maps would be to bake the 6 textures with a directional light shining from each direction in a program that can render real translucency, but that can be very time-intensive and I don't know of any readily available program that can do that. As far as I know Maya LT doesn't support SSS bakes very well (correct me if I'm wrong) and xNormal can't bake that kind of map.

    I wrote a quick (and very rough) script that blurs the normal maps through a convolution matrix based on the distance between the texels, using an object space position map for reference to calculate the distance. This way the normal is spread first across thin areas, simulating how light passes through an object.

    IMG1.png

    The script automatically calculates and saves the object space normal and position map, which you can use for other purposes if you want. The position map is NOT normalized on all axes (something which great programs like Substance Painter unfortunately do) which means an object that is very thin on the X axis will have a very small contrast in the R channel, etc.

    What I found is that if you have an object properly unwrapped and a well rendered translucency map, you can get incredible results. Even without View Distance and Depth being used, the baked maps are more than enough to give a sensation of depth, they will also reproduce a nice fresnel effect when seen from the backside at every angle without needing any special calculations.

    IMG2.png

    Again, just making sure you know - the script isn't all that great at the moment, there are artifacts all over and I'm pretty sure it's filled with bugs, so use it at your own risk. I haven't tested it extensively, hence why I'm not releasing it to the Asset Store.

    The method is free for you to do whatever you want. If you want to use it commercially, feel free.

    IMG3.png

    Included in the Package:

    * A Script to generate Object-Space Position and Object-Space Normal Maps.
    * A Script to bake Translucency Maps.

    * A basic Shader with very simple controls.
    * A Shader with some Beer's Law controlling.
    ** Both shaders include metadata for you to play with them in Shaderforge.

    Some issues of which I know:

    * There are probably better ways to decode the light in regards to the direction it's pointing. Right now it looks good for objects standing still and materials with a decent degree of light scattering, but objects with too much or too few scattering will look weird when reflecting light at 45 degrees.
    * The current script will produce lots of artifacts and banding, not sure why exactly. I have since developed a cleaner, better method that I tested on Filterforge that doesn't yield any artifact, I'll try to port it to Unity3D sometime.
    * You might have to adjust your mesh size, if it's too big the position map will be rendered incorrectly, otherwise it's fine.
    * Point Lights don't render correctly, I believe. Directionals only.

    Like I said, this is all very rough. I hope it's useful to someone. If you have any ideas/corrections/changes/improvements feel free to post and when I have the time I'll update the shader.
     

    Attached Files:

    Last edited: Mar 8, 2016
    AnKOu, kosowski, GuitarBro and 3 others like this.
  2. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    awesome thanks a lot
     
  3. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Yes , its cool :)
    More streamlined options to bake translucency maps independant on scale would be cool , and added transparency :)