Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Translucency and Subsurface Scattering

Discussion in 'Works In Progress' started by FPires, Aug 24, 2015.

  1. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Hey guys, recently I started working on Translucency Shader since I didn't find any free solution that suited my needs - namely something that reproduced light scattering inside the object, not just view-dependent light transmission based on depth. So I wanted to write a shader that approximated the light propagation inside the object's volume.

    I tried to approach the subject in a few different ways. First I wrote a custom raytracer to map the light scattering and produce a volume texture.

    Volume3.jpg

    It works fine for simple objects but it takes a long time to calculate for complex objects in order to achieve a good result. Still, it was a good starting point.

    Volume2.jpg

    Then I figured out a way to do it much faster while still retaining most of the quality. It still requires a custom pre-calculation (which unfortunately cannot be done externally on xNormal for example) which I'm trying to improve, but I'm very pleased with the results so far.

    TranslucencyShader_Base.jpg

    Here's a bit of an extreme example, a cylinder with a directional light at noon. There's no light falloff, no light hitting at the sides and the top of the cylinder normals aren't "smoothed".

    TranslucencyCylinderTop.jpg

    Last but not least, some nice transparency with a volumetric feel:

    Translucency_Transparent.jpg
     
    Last edited: Aug 26, 2015
    Aniow, buttmatrix, antislash and 10 others like this.
  2. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,403
    That's the most beautiful green booger I've ever seen. :)
    Does it have to pre-calculate everytime the light direction changes?
     
    SAOTA and theANMATOR2b like this.
  3. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Awsome !!!!!!!! Almost Renderman Quality .:)
     
  4. StarvingIndieDeveloper

    StarvingIndieDeveloper

    Joined:
    Aug 21, 2015
    Posts:
    258
    Very nice. I've wanted to work with translucency shaders, but haven't had time. I could use one for some of the current stuff I'm doing for my game Aeronautica.
     
  5. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    It does look pretty disgusting, right? I modeled something abstract with all the shapes I wanted to test in one model. It ended up looking like that.

    As for your question - No, you can change light at run-time without problem. It's not static lighting.
     
    chingwa likes this.
  6. papibeast

    papibeast

    Joined:
    May 31, 2015
    Posts:
    24
    Great work!
    Will you be releasing this shader on the Asset Store?
     
  7. TheGraficalOne

    TheGraficalOne

    Joined:
    Feb 14, 2014
    Posts:
    50
    This is Gorgeous!!
     
  8. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Thanks!

    I'm not sure yet. They're probably not very friendly with mobile devices and what not, but at least they work with both Forward and Deferred cameras.The problem is that these shaders require some setup, they're not plug-and-play. I'm trying to automate it and make it as simple as possible.
     
  9. krisoll

    krisoll

    Joined:
    Jan 21, 2014
    Posts:
    2
    Whoa, it looks awesome
     
  10. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Here's an exaggerated translucency and scattering applied to a sculpture. Figured it'd show the effect better.

    Translucency_wax.jpg
     
  11. Licarell

    Licarell

    Joined:
    Sep 5, 2012
    Posts:
    434
    I guess you could use this as a skin shader as well?
     
  12. Haagndaaz

    Haagndaaz

    Joined:
    Feb 20, 2013
    Posts:
    222
    This looks amazing!
     
  13. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Thanks!

    Probably. I've added a few things that could help achieve that effect like a subdermal map, though I haven't done a lot of testing yet.

    I've been working on transparency today, made a nice transition from clear to blurred transparency based on depth.

    Translucency_Transparent2.jpg

    I think I've solved the traditional issues with z-writing and depth but I haven't started working on it yet. Hopefully it will work.
     
    antislash, larku and Haagndaaz like this.
  14. SAOTA

    SAOTA

    Joined:
    Feb 9, 2015
    Posts:
    220
    amaze. I was re-watching Jurassic World earlier this week and
    when Chris Prat is first chased by the Indominus Rex, the dino bends down and you can see the flesh stuck on the INSIDE of the teeth, WOW, whoever spent time on that awesome ,
    my jaw drops with some good Sub Surface Scattering.
     
  15. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    2,889
    Good God this is so delicious. I've yet to dive into shaders, but this really makes me want to, now.

    Beautiful work. And please consider releasing to Asset store. :D
     
  16. TheGraficalOne

    TheGraficalOne

    Joined:
    Feb 14, 2014
    Posts:
    50
    I started to get into shaders a while back, but gave up. This is definitely make me want to give it another try.:)
     
  17. TheGraficalOne

    TheGraficalOne

    Joined:
    Feb 14, 2014
    Posts:
    50
    Were you making these shaders for a specific project, or were you just experimenting?
     
  18. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    I'll work on cleaning the code next week and see how it goes, but no promises. If I feel confident that I can deliver something stable and intuitive I'll publish it.

    No specific project but the lack of subsurface scattering shaders in general is something that has bothered me for some years now.

    Here's something a bit caramel-like.

    Translucency_caramel.jpg
     
    ThunderTruck, SAOTA, larku and 3 others like this.
  19. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    I'm in the process of rewriting the shader, which due to my limited spare time might take a while, so no time frame. Basically learning the new stuff that came in 5.0 and how to integrate it. I also hit a bit of a brick wall trying to make one of the variants energy-conserving.

    I think no current asset uses the same method that I do, so I've decided that I'll release it on the Asset Store when I'm done. Again, I can't promise on a time frame, but if I feel like this is gonna take longer than it should I'll release the simpler version used in the first post (the green thing) for a reasonable price.
     
  20. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    amazing, do you compute a thickness map?
     
  21. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    I do compute something similar to a thickness map first, but the final shader uses a different custom map. The problem with a thickness map is that the final result works fine as translucency, but doesn't typically produce the actual scattering effect like the one in the cylinder image in the first post, at least not in any algorithm I know.
     
  22. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    if you get it working it will be awesome
     
  23. Fenixake

    Fenixake

    Joined:
    Jan 25, 2014
    Posts:
    81
    this is the most awesome thing i found this year GJ!
     
  24. NikProductions

    NikProductions

    Joined:
    Oct 29, 2014
    Posts:
    95
    Any updates on this, it's amazing! Also are you going to release it for free, or payed?
     
  25. antislash

    antislash

    Joined:
    Apr 23, 2015
    Posts:
    646
    i dream of a foliage shader with that SSS and shadows
     
  26. TheAlmightyPixel

    TheAlmightyPixel

    Joined:
    Jun 21, 2014
    Posts:
    263
    Any updates regarding the shader? I've been hunting for a good SSS shader for a while now, and this looks really promising!
     
  27. rfcrocha

    rfcrocha

    Joined:
    Jul 18, 2014
    Posts:
    23
    good stuff man, this looks really good indeed. Will keep an eye on this.
     
  28. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Update ?
     
  29. FPires

    FPires

    Joined:
    Jan 5, 2012
    Posts:
    151
    Posted the basic shader here. Both the shader and the script used are free.

    I'll update it with more shaders as soon as I find more time, sorry about the huge delay, had a turbulent last year. Hope the current shader is useful.