Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Custom Phase Screen-Space Subsurface Scattering (FREE)

Discussion in 'Image Effects' started by customphase, Oct 26, 2016.

  1. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202


    Animated gif: http://imgur.com/Nc8VyDv

    Asset Store link: https://www.assetstore.unity3d.com/en/#!/content/75061
    Github link: https://github.com/CustomPhase/CP_SSSSS


    Tested only in Unity 5.4.2, works with deferred/forward, gamma/linear, HDR/LDR, DX11/DX9.
    Scene view previewing and previewing in edit mode are disabled until i figure out a better way to deal with materials and per-object properties.

    How to use:
    1. Put the files into any folder in your .../Assets/Resources folder
    2. Attach the CP_SSSSS_Main script to your main camera
    3. Attach CP_SSSSS_Object script to any Renderer object that you want to have subsurface scattering on
    4. Start the game to see the effect in action
    Basic idea behind algorithm:
    1. Blur the source image separably, based on the distance from the camera, and attenuate surrounding sample's influence based on the depth difference between this sample and the center sample (Soft Depth Bias parameter controls the maximum depth difference allowed)
    2. Render the scene with replaced shader, using the mask set in CP_SSSSS_Object script multiplied by the subsurface color
    3. Composite the blurred stuff, multiplying it by mask from step 2, and substracting the original based on the Affect Direct parameter
     
    Last edited: Dec 1, 2016
  2. miniduck

    miniduck

    Joined:
    Sep 27, 2012
    Posts:
    117
    Would you happen to have a demo scene?

    Tried putting a simple diffuse texture on an object, add script to camera and object as the description but not seeing any result while in play mode.

    Many thanks!

    Edit:

    Went back to the camera and noticed the script had been automatically disabled. Enabled - voila!
     
    Last edited: Dec 5, 2016
    customphase likes this.
  3. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Yeah, its disables itself when first applied for some reason. Gonna fix that in the next update.
     
  4. punk

    punk

    Joined:
    Jun 28, 2013
    Posts:
    387
    This looks really interesting any chance of getting it working 5.5 and single pass VR
     
  5. Ar7ific1al

    Ar7ific1al

    Joined:
    Jan 21, 2014
    Posts:
    51
    Really appreciate the freeness of this asset. It looks pretty nice, as well. However, there seems to be some sort of bug. Objects to which I apply the CP_SSSSS_Object have their material forced to a material called "Standard" and it cannot be changed. Disabling or removing the component from the object fixes it.
     
  6. SpyChar

    SpyChar

    Joined:
    Jul 15, 2012
    Posts:
    11
    Wow! Such asset for free. Anyways it seems that it doesn't work alongside unity cinematic AO.
     
  7. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    What exactly you mean by "working 5.5"? It works in 5.5 for me. Although it had some weird interaction with some post processing effect, which i hopefully fixed in the new update. And about VR - i know nothing about VR and whats the implications of doing post processing for it, so i would say no. Plus i dont have any devices to actually test it on.
    Thats strange, it shouldnt do that. What platform are you using? And what Unity version? I only tested it for windows and Unity 5.4.3 or higher.
    Next update which that ill publish soon (probably on weekend) should hopefully fix the incorrect interaction with other post effects.
     
  8. Ar7ific1al

    Ar7ific1al

    Joined:
    Jan 21, 2014
    Posts:
    51
    Build target is Windows and OS is Windows 10. Unity version is 5.5.0f3.
    It seems to work for one object, but then it produces this problem for any subsequent objects I wish to apply SSSSS to.
     
  9. jessyOb

    jessyOb

    Joined:
    Feb 1, 2015
    Posts:
    4
    First thing: Thank you!. Second thing: I have a problem. When I add CP_SSSSS_Object to an object and CP_SSSSS_Main to the Camera, all the objects present in the scene, are affected by the blur scattering and there are no color scatter for the CP_SSSSS_Object. Nothing happens.

    P.S.
    I've do a second test... Yes, the first problem is The unity AO. Now I can see the scattering color in the Scene view, but not in Game view.
     
    Last edited: Dec 28, 2016
  10. StimpyPurrpurr

    StimpyPurrpurr

    Joined:
    Jan 12, 2016
    Posts:
    3
    Getting this error... "Assets/Resources/CP_SSSSS/CP_SSSSS_Object.cs(3,27): error CS0234: The type or namespace name `ImageEffects' does not exist in the namespace `UnityStandardAssets'. Are you missing an assembly reference?"

    I'm trying to use it with 5.4.3

    EDIT: Solved.. Had to have standard assets installed. But now I learn this doesn't work for VR. Any chance this will get an update to function with the Vive Camera? Currently it changes the fov and only shows one eye.
     
    Last edited: Jan 3, 2017
  11. thelebaron

    thelebaron

    Joined:
    Jun 2, 2013
    Posts:
    518
    Just wanted to say thanks for sharing this and making it free. Spent the last week tearing my hair out while learning shaders and having some half assed attempts to make my own(as evidenced by the lineup of heads!).

    The one with the body is just the standard shader.
    '
    and off
     
    customphase likes this.
  12. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Hey guys! Really appreciate all the feedback and sorry for being silent all this time. Ive updated the effect on the github, it now uses command buffers, so it should work nicely with all the other post effects and Unity's Post-Processing stack.
    https://github.com/CustomPhase/CP_SSSSS

    Couldnt replicate the issue myself sorry, materials seem to be working fine. Try the new update, see if maybe it helps.

    Try the new update please, it should work better with other post processing effects.

    Fixed that problem in the new update. Regarding the Vive - sorry, as i said above, i have no experience with VR and how post processing works there, nor do i have any VR device to test it on.

    Looks great, but i would lowered the intensity a bit, it makes it a little unrealistic. Plus i usually set "Affect Direct" to somewhere between 0.5-0.8. And 0.001 depth bias is really small, you probably should increase it a bit. To at least 0.003-0.004
     
  13. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Thanks :)

    First tests :

    Cpsss1.jpg
     
  14. Arganth

    Arganth

    Joined:
    Jul 31, 2015
    Posts:
    280
    looks beautifull
    is this a assetstore asset?
     
  15. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Damn, that looks fantastic! Do you mind if i use it on the asset store page as an example image? Can you also post an image with the effect disabled please?
     
  16. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    You can use it , but i do not know if it illustrates only yours image effect ,its mix of SSS shader and yours image effect .
    Its more tailored to showcase all effects combined .
    I can probably swap SSS shader with Refraction shader with POM to simulate cracks inside ice and you image effect - will probably looks better for clear ice .
    Or if i remember correctly there is Translucency shader in Adam demo , and in old Labs demo from Unity .

    No image effect :

    NoSSSS.jpg
     
    Last edited: Feb 4, 2017
    customphase likes this.
  17. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Not for now .

    I am working on some Arctic only landscapes and assets , for my icy moons (Enceladus , Europa ) so SSS is crucial effect .

    Even if i release it , you will need separate SSS shader ( maybe Unity will have it in 5,6 ScriptableRenderLoops ? :) ) and Customphase SSSS probably to look good .
     
  18. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Btw , there is error with Displacement/Tesselation Shaders - Displaced mesh become transparent . You can see original underneath.
    It is not specific to SSS shader , every other Tesselation shader has the same bug .

    BugTess.jpg
     
  19. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    This set illustrates effect better : Snow has standard tesselation shader without SSS .

    ON :
    ON.jpg

    OFF :
    OFF.jpg
     
  20. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Second set with ice crystals : maybe you will find those more useful .
    ON : ON2.jpg

    OFF :
    OFF2.jpg
     
    RomBinDaHouse and customphase like this.
  21. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Last one , i know ........ :)
    ON:
    ON3.jpg
    OFF:
    OFF3.jpg

    ON:
    ON4.jpg

    OFF:
    OFF4.jpg
     
    customphase likes this.
  22. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Yeah, it uses replacement shader to render SSS masks into the buffer, and that replacement shader just uses raw vertices positions of the mesh. It might be possible to copy/mimic tesselation from the base shader into that replacement shader, but if you have other custom vertices modifications in your base shader, then i dont think there is a way to copy those to the replacement shader. Ill try to ask around if theres something i can do.

    Those pics look dope as hell btw.
     
  23. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Thanks .:)
     
  24. pigglet

    pigglet

    Joined:
    Aug 13, 2014
    Posts:
    113
    Thanks for the shader! So clean and powerfull. But is there any chance to make it work with objects that don't have single UV and material? Even in the mode "whole object is translucent" it works only with one UV/Material.

     
    RomBinDaHouse and jdraper3 like this.
  25. RomBinDaHouse

    RomBinDaHouse

    Joined:
    Mar 18, 2015
    Posts:
    13
    +1
     
    jdraper3 likes this.
  26. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Well, ive asked Aras (graphics engineer on Unity) on twitter about this displacement/tesselation issue, and he said that there is no unified general way of dealing with that easily. The only way for end users is to manually create subshaders inside my SSS replacement shader, copy the vertex manipulations code from their custom shader to the replacement, and set matching RenderType tags on both subshader and vertex-mainpulating shaders. Sorry about that :(

    Hm, shouldn't be hard to do, ill look into it tomorrow.
     
    jdraper3 and pigglet like this.
  27. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Hmm , could you just locally make a mask for specific object - extrude mask inward by displacement offset ?

    In this picture , the displacement bug is almost not visible , because there is possible bug when you scale Game window in editor , effect is not updated until you re enable it on the camera , so there is some offset ( the direction depends whether you make window smaller or bigger ) . In this picture , window has been enlarged .
    SnowMask2.jpg
     
    Last edited: Feb 7, 2017
  28. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Hm, i couldnt replicate the bug you're describing on my end. Everything rescales when the game window is rescaled.
    I also dont understand what you mean by extruding the mask inward. The thing on your screenshot i doubt has anything to do with mask. This looks more like a depth check problem to me. Have you tried increasing the soft depth bias setting?
     
  29. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    Maybe some other post effects bugs out . Need to check .
    It only happens with Displacement shader .
    Its Alloy skin shader.
    About mask , never mind :)

    This shader + disp + yours effect (10 blur iterations ) is already overkill .
    But looks nice :)

    Thanks for your work on this :)

    Regards.
     
  30. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Done. Check out the github for new version. The separate texture mask mode doesnt work with multimaterial meshes atm. Will implement it later. But "Main texture from current material" and "whole object is translucent" modes work fine now.
    https://github.com/CustomPhase/CP_SSSSS
     
    RomBinDaHouse and pigglet like this.
  31. pigglet

    pigglet

    Joined:
    Aug 13, 2014
    Posts:
    113
  32. CoolSmek

    CoolSmek

    Joined:
    Jun 3, 2014
    Posts:
    7
    Hi there. I just added my review of your shader on the asset store. I really like it! In my review though, I do detail a few things that I would love to see added/changed. These were just things that I came across while toying around with it. Anyway, I thought I would reply to the thread as well so you can contact me about that here. Thanks!
     
    customphase likes this.
  33. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Hi, thanks for kind words!
    In regards to your first point from the review - i've already added a support for multimaterial meshes, but the asset store version of the asset is a bit old. You can download the newer version from the github link ive posted above.
    And for the second point - i planned to do that, but i didnt find a good way to do that yet, maybe in the future.
     
  34. CoolSmek

    CoolSmek

    Joined:
    Jun 3, 2014
    Posts:
    7
    I tried the 1.4 version from github, and I am not sure if I understand how to specify the material from the multi-material renderer. In the old version, the effect would only be applied to one material (I like this feature) but it could only specify the material in "Element 0" of the material list. I was hoping for a way to specify in the SSSSS object component, which "element" to use. Does that make sense?
     
  35. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Aah, i see what you mean. Im gonna see if that can be arranged a little bit later.
     
  36. sickbattery

    sickbattery

    Joined:
    Jul 13, 2014
    Posts:
    15
    I have a problem with this shader: It shines through hair that use standard/cutout shader. Unity 5.5.3

    SSSSS01.PNG
     
  37. rhw_m

    rhw_m

    Joined:
    May 7, 2017
    Posts:
    1
    Hi,

    I want to use this on a character with the third person controller. The problem is, the shader becomes kind of a shadow and it moves away from my character. It moves off of it. Can you help me with this?
     

    Attached Files:

  38. Kavarox

    Kavarox

    Joined:
    Jun 3, 2014
    Posts:
    2
    Same thing happening to me.
     

    Attached Files:

    • 1bh.jpg
      1bh.jpg
      File size:
      146.8 KB
      Views:
      720
  39. customphase

    customphase

    Joined:
    Aug 19, 2012
    Posts:
    202
    Sorry for delay. Can any of you please upload a demo project where the problem is happening? So i could look into it better
     
  40. looki666

    looki666

    Joined:
    Sep 5, 2013
    Posts:
    79
    I have got same problem with first version , resizing window fixed this .
     
  41. KlutoTek

    KlutoTek

    Joined:
    May 24, 2017
    Posts:
    6
    Hey, this asset looks great from the screenshots and it's so wonderful that it's free! However, I'm having trouble getting it to work. In the editor the effect works fine, but in play mode the main camera's view is upside down and the SSS effect is overlaid rightside up on top of it. I tried it in a fresh scene with no other component's besides the ones in this asset. Strangely, it works perfectly when I turn anti-aliasing off. I think it's because I'm running on DX11, which evidently uses different vertical texture coordinates than OpenGL. I found this link explaining it, but I'm very ignorant when it comes to code so I can't figure out how to implement the fix. Hopefully you can make sense of this and resolve this problem.

    https://docs.unity3d.com/Manual/SL-PlatformDifferences.html
     
  42. Abuthar

    Abuthar

    Joined:
    Jul 12, 2014
    Posts:
    92
    I know nothing about shaders or camera effects, but from extensive use, i can say 2 things that would make this plugin a lot better. I mean, it's amazing, and on top of how amazing it is, it's free, but i've got feedback if anyone wants it :)

    1. Reflections make this effect glitchy and look horrible when working on materials with high reflective. If it's possible to alloy users to disable specular highlights from affecting the SSS look then we would be able to achieve more realistic effects apart from just skin, but also gems and anything that is translucent or has sub surface scattering. Example on high smoothness/specular issue:

    https://imgur.com/a/LFtv4

    First rotation is no smoothness - second is with smoothness. I kind of get how the effect works, but if we were able to exclude specular highlights, it would make it so much better.

    2. Adding per object rules, so that some objects have more scatter or less intensity than others. This would really expand the variety of SSS materials we could replicate, along with some transmission like i am using here, it is virtually perfect!

    I know these will likely be editions that are not actually worked on, but it's my 2 cents for future development if any. Also would be willing to throw a couple bucks towards the original dev - i really appreciate this plugin! :)
     
  43. JenniB

    JenniB

    Joined:
    Feb 15, 2018
    Posts:
    62
    Hello :)
    to get this effect working, the material need some special properties or is working with every material?

    Thanks :)
     
  44. saulooliveira17

    saulooliveira17

    Joined:
    Jul 26, 2018
    Posts:
    1
    wow i love it!!!!
     
unityunity