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

Pre-Integrated Skin Shader - announcements and feedback

Discussion in 'Assets and Asset Store' started by cician, Feb 26, 2013.

?

What should I focus on for next releases

  1. optimizations and mobile

    43 vote(s)
    24.3%
  2. realism

    82 vote(s)
    46.3%
  3. ease of use

    8 vote(s)
    4.5%
  4. just fixes and compatibility, it's awesome as is and you better make a hair shader...

    44 vote(s)
    24.9%
  1. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    :D Emission is already handled internally and adding support for it should be as easy as adding a texture lookup in the shader. The only reason i haven't yet is that I didn't want to make the shader heavier than it already is. Note that I'm not relying on optional material features because of the infamous keyword limit. I'll try adding it as something you can enable by uncommenting a few lines in the shader.

    ---

    Some of you may have encountered issues with image effects. In particular SSAO and similar effects that rely on normals in the gbuffer. I'm working on a decent workaround, but I'd like if you vote on my feature request here that would fix the problem properly in Unity and at the same time allow me to make the shader much more performant when deferred shading is enabled by implementing it as a hybrid forward-deferred shader without fragile hacks. Of course the pure forward mode will continue being supported. Translation: if you want feasible wrinkle maps, detail maps and [return of] tessellation vote here.
     
    ksam2 likes this.
  2. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    482
    Hello!

    I would need an advice, please.

    I am using 2 different models only (DAZ Genesis 3 male and female). The UV map always stays the same, the morphs don't change the UV map.

    This makes me wonder if I can't automate the process. I mean the ears will always be at the same position, so I can automate the thickness map, and other things might also be automatable.

    I am polypainting the model in ZBrush, and I bake the maps.

    What I get from ZBrush is the following:


    Could you please tell me what else I need to fill all the necessary slots in Pre-Integrated Skin Shader?

    I'm a programmer, and I will write a program that automatically creates the missing maps, and I'm willing to share the tool.
    I think many people would need it.

    Thank you for pointing me at what I actually need to do!
     
  3. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    If the morphs don't differ too dramatically, meaning they don't each have own specific features like big scars or wrinkles then you probably can reuse the same depth map. This texture is OK to be relatively low resolution without too much detail. There are different ways to generate it, but I don't think you can do so directly from zbrush. At this moment we've got a tutorial for 3DSMax + vray/mental ray. Other implementations of Pre-Integrated Skin don't rely on having this texture and instead estimate surface curvature directly from the mesh, but this approach has some flaws.

    Other textures are either optional or pretty much standard PBR textures you'd need for the Standard Shader (specular setup). I hope there are enough resources around on how to author albedo, normal, specular and glossiness maps that we don't have to cover them. The "depth" map is non standard so we probably should extend tutorial coverage to other software packages.

    See here for an overview of required content: https://gitlab.com/jbrothers/pre-in...i/wikis/preparing-necessary-content#depth-map
     
    OfficialHermie likes this.
  4. OfficialHermie

    OfficialHermie

    Joined:
    Oct 12, 2012
    Posts:
    482
    The "Cavity" map isn't the "Depth Map", or is it?

    @K.JBrothers
    Could you perhaps also give me some feedback? I think we are striving to do about the same. Thank you!
     
    Last edited: Jun 19, 2016
  5. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,645
    I don't understand how you did the monochrome sm look up.

    I had implemented a PSS texture look up generator for blitz3D :rolleyes: so I'm familiar with the math, I don't understand what you did exactly. What I caught is that you have a loop in the frag that essentially recompute the scattering with the wight table and a precompute gaussian table varienceSQRT (I think, ie 1/Sqr(2*Pi*v) * Exp(-(r*r)/(2*v)) ). Am I right for the table? But then I don't understand where the diffuse ring integration is since the scattering is essentially in this loop and it's absent ... How did you unroll the integration loop?
     
  6. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    There is a problem with Unity 5.4b22 and this shader, can you please check this out?
     
  7. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    933
    I can confirm this as well. It's a really weird bug too and makes the shader unusable.

    These patches of transparency flicker all over the body, changing shape/position based on the topology of the mesh.
    It only changes if I rotate the camera, but simply translating the camera does not change the pattern. Hope that helps!

    Also, it only happens in Deferred.
     
    Last edited: Jun 24, 2016
  8. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    376
    Lovely and awesome skin, just doesn't work correctly on Unity 5.4 beta 23. can you check for that?
    Thanks.
     
  9. Goldrake

    Goldrake

    Joined:
    Feb 6, 2010
    Posts:
    143
    i confirm too the bug showed by @Invertex on beta 23
    Can you fix it?
     
  10. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
  11. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    These is something else, skin have problem with 2 other assets and I think that would be easy to solve.

    First: When I add HBAO to camera and set "Per pixel Normal" as "G Buffer" skin become totally transparent and objects can be seen through skin.



    And second asset is SEGI. when I use SEGI skin looks like below pic.

     
    Last edited: Jul 3, 2016
  12. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    I started writing an answer with an explenation, but it turned out as a wall of text so I decided I'd rather make a log post out of it (which I'll finish no earlier that in two weeks, when I go back home).
    Reassuming though: 1. Split integration of gaussians components into separate integrals (integral of a sum → sum of integrals). 2. Place the content of the gaussian function into the integral directly and pull out of the integral factors that can be considered constant, which includes variance!
    Actually there's a missing factor in my integration, but it doesn't change much. I'm reluctant to add it as it would change the user's existing materials.
    The ring integration is precomputed into the lookup just like in penner's technique, but instead of integrating the whole diffusion profile, I integrate just the gaussian•clamped cos(theta). Then the shader does multiple lookups at runtime parametrized with variance of each component of the diffusion profile and cos(theta) that comes from the relative blur level (mip) of the normal map. The constant factor pulled out of integration is applied at runtime together with weights.
     
  13. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Regarding bug with beta of unity. I can't test each beta build as my time is limited and I'd rather use it to work on the shadef itself. I do test from time to time of course. I haven't managed to reproduce the issue before taking off for the vacation. Hopefully they'll fix it soon. If not I'll have to pull out the laptop, reproduce the issue and fill a bug report (I'm writing from my tablet on the go).

    I'm aware of the isue and working on a workaround. The problem is that in Unity there's no way to fill the normals in gbuffer from a forward shader and image effects depend on it. See my first post on this page. One user managed to work around this limitation by duplicating the mesh and applying standard shader to one of them. I don't remember right now if that was all or some modification to the shader was necessary. I'll make an update as soon my workaround is ready (which will do something similar, but in a script).
     
    ksam2 likes this.
  14. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    Thanks, two mesh solution can't be good specially if it's a high poly mesh with lots of blend shapes and heavy animations.
     
  15. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    I know this degrades performance, but there's no much of a choice. Note also that in forward shaders the whole mesh is re-rendered for each light anyway so the same applies even without this for complex meshes.
    It is possible to avoid doing so with current features, but that would be way too hackish to supprort properly. For a proper solution the engine needs to be modified. See the feature request in my earlier post, quoted below.
     
    Crossway likes this.
  16. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    I gave all my 10 votes on this.
     
  17. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    933
    Issue appears to be fixed in B25.
     
  18. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    159
    Something wrong with shading, what are you think about? How can I fix that conversion on shadows with SSS
     

    Attached Files:

  19. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Does reducing translucency radius or intensity fix the problem?
    If not, what are your texture quality settings(the thing that says full res/half res/...) and shadow quality?
    Does the same happen if you place the character in an empty scene?
     
  20. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,645
    Just a quick question, I was looking at doing translucency differently and cam out with an idea:
    - hijack the shadow map that compute shadows
    The way I understand it is that:
    1. we do a render from the light perspective into a depth buffer that extend to from light to light range
    2. at fragment time we compute if the position of the fragment is below or above the depth map:
    - by first computing world space of fragment and light
    - turn it into a distance to light vector
    - project the depth map bound to world space position
    - find the position of the fragment on the depth map by projecting the vector onto it
    - compute if the fragment distance is bigger (shadowed) or lower (lit) than the depth point

    What if we compute the relative depth point position and use the distance to the fragment position if shadowed to compute the translucency? The actual question is do someone know if unity allow that out of the box(I only know how to access "atten" for attenuation which lack the distance to depth).

    Now there is some obvious limitation, it only approximate convex shapes and only work for a single volume at a time (no occlusion by other objects), so its expensive.

    I want to experiment with crude afro hair shader with that.
     
  21. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    847
    I can confirm as well. it takes place in 5.4.0 f1 only in deferred but not forward rendering.
     
  22. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    933
    This issue was fixed for me in in B25 and is fine in F1... So, maybe try re-importing the shader?
     
    ksam2 likes this.
  23. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,001
    Is that possible to convert this skin from forward to deferred? it will solve the problem.
     
  24. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    See this paper if you haven't yet: http://www.iryoku.com/translucency/
    They demonstrate that you can just use the depth and it works well. From the paper:
    In Unity it's difficult to do, but kinda possible. What you want for doing it efficiently is to use the shadowmaps themselves. The main problem is that on most platforms the shader can only sample the shadowmap as the attenuation for previously rendered screen space shadows or depth comparison. You can force it in order to access the actual depth of the shadowmap, but to my knowledge it's limited to D3D11.

    I think a combination of shadow attenuation and custom self-shadows would work well, but there are two gotchas:
    1. You really want the shadow attenuation of the fragment on the light-in side as opposed to the light-out side. The latter being the fragment you're normally computing in your shader. You may want to sample it when rendering your custom shadow map and store it alongside the depth.
    2. You need to manually hook a command buffer to each light you want the translucency effect from (ideally all lights).

    For hair I recommend keeping an eye on what Epic is doing in UE4. They'll be showcasing it at Siggraph soon.

    Unfortunately the Unity's graphics pipeline is not flexible enough. I mean, it's currently possible with either some very very ugly hacks or by basically replacing the whole deferred rendering system. Neither would be feasible to sell on the Asset Store and support.
    <rant>In my opinion the real issue here is that Unity Technologies doesn't pay enough attention to the forward shading path and how custom shaders blend into the pipeline. The mix of deferred and forward shading is pretty popular in game engines. Problems like this one and the one above with SSAO are just bugs and omissions in Unity due to things being slapped together without a good thorough plan. Mind you, I love Unity's flexibility, but I think many things like image effects and skin shading should be part of the engine itself, otherwise things often just don't blend well. Both due to not being tested as a whole and due to important details like the order of effects being left to the user. Just one example: the SSS from skin shader should blur the ambient occlusion, but AO is left to a plugin image effect that just darkens the screen pixels, which looks horrible. </rant>
     
    ksam2 likes this.
  25. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,645
    I wonder if U Ewill address specificity of coarse afro hair, which is my end game lol
    Most people think that all hair are similar, that's not quite true, In my experience corase afro hair catch light quite differently (they tend to be subtly sparkly/glittery with some rainbowy iridescence, even when ironed and flatten), the approximation of hair as a cylinder don't strictly apply to coarse afro hair, their curliness come from the fact they are finer and their cross section has a different shape, which add extra complexity (relative to view vector, there is extra tensor that contribute to the light, as the hair rotate on itself along an helicoidal), especially at distance when the details can be assimilated to "microfacet" within a single rendered pixel. Of course the social context behind make it difficult to find study that address these specificity, like with black skin I struggle to find good data :(
    http://www.thenaturalhavenbloom.com/2011/05/curly-vs-kinky-what-is-difference.html
     
  26. imaewyn

    imaewyn

    Joined:
    Apr 23, 2016
    Posts:
    159
    The shader is not adequately responds to the light probes. darkens too quickly at all settings. 28-07-2016 10-29-03.png 28-07-2016 10-29-25.png
     
  27. sgtkoolaid

    sgtkoolaid

    Joined:
    May 11, 2010
    Posts:
    847
    yeah f1 its fixed thanks :)
     
  28. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    I'll look into it. Would you mind sharing this particular scene, if it's not too much of a bother?
     
  29. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    376
    As already mentioned a detail map with second bump (for micro bump) would be cool.
     
    KWaldt likes this.
  30. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    122
    Jup, thumbs up for detail map--or is it hard to implement?
    The shader is really beautiful, I'm just really missing the fine details to sell it.
     
  31. jwilliamsen

    jwilliamsen

    Joined:
    Aug 8, 2010
    Posts:
    56
    Any idea when edge tessellation will be re-introduced? I'm working on a project now that could really use it :)

    Thanks,

    Joe
     
  32. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Things I'm considering for the next minor release:
    - Emission
    - Details. In a limited form. Detail texturing can be tricky in forward rendering and will probably never be enough for everybody's needs unless Unity introduces a material editor or something.
    - I'll re-introduce tessellation, but I'll probably leave it as something you'll need to enable by editing a line in the source code, in order not to downgrade performance for everybody and to avoid shader variant explosion (tessellation cannot even be enabled/disabled with material keywords).

    tl;dr
    For a while now I've been hacking on some internal things of the shader so it's not like I was completely laying idle, despite lack of activity in the repo. Most of you are probably not interested, but to those who are: I've been trying function fitting for a while now to approximate what is now done with the lookup textures. This shifts the shader to be a bit more ALU, instead of bandwidth heavy and frees texture samplers to do other interesting stuff, like detail texturing. So far I've found a precise and relatively simple approximation of the Spherical Harmonics lookup. I'm still experimenting with the direct light lookup, but I'm not yet sure if I'll find something good, yet cheap enough. If I do though, this will fix the problem of the global texture resolution setting affecting (breaking) the shader.
     
    neoshaman and Crossway like this.
  33. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    4,645
    Is the write up about the original texture parameter baking still planned?
     
  34. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Yep.
     
    neoshaman likes this.
  35. agentc0re

    agentc0re

    Joined:
    Feb 28, 2014
    Posts:
    77
    Hello @cician, I am working with UMA 2 and am trying to base a UMA material off your shader. However I think I need shader keywords that define each texture property in the shader, IE: Diffuse, Normal Map, Depth, etc etc. There's only 8.
    Is this already done or would you have to enable it that way?
     
  36. Tmtakala

    Tmtakala

    Joined:
    Mar 12, 2014
    Posts:
    11
    Hi @cician,

    Thanks for creating Pre-integrated skin shader.

    I have a question: Is there a way to reduce shadow darkness in your shader? Looking at the PreIntegratedSkinShaderCore.cginc and other files, I couldn't quickly find any place where to inject a multiplier to reduce the shadow darkness.

    I have a scene with a Directional Light that has soft shadows enabled, where I have adjusted the light's shadow strength so that shadows on objects with Unity's standard shader have appropriate darkness, but with that setting the shadows on objects with Pre-integrated skin shader appear too dark. I'm really hoping to solve this.

    If further developments for the shader are to be done, I would request improving the shadow accuracy or adding parameters for finetuning the shadows.
     
  37. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Thanks for reporting the issue. I made changes to fix the issue, but I'd like some some feedback before submitting to the Asset Store. I've committed the fix to the repository. Would you mind testing it? If you don't have access to the repo yet, you can PM me your email address, or if you already have a gitlab.com account, your account name.

    Note that before the shader was turning off penumbra scattering for lights with less than 100% shadow strength, but wasn't doing it correctly. I changed it so the penumbra scattering is always on, unless you undefine PSS_PENUMBRA_SCATTERING_ON. The caveat is that it may degrade a bit the overall diffuse/SSS appearance contributed from lights with non 100% shadow strength (in shadowed areas). You can notice the difference when moving shadow strength slider between 0 and slightly above zero. This may also be an issue if you want to animate shadow strength for some reason, down to zero, which would result in popping, but I hope it's a rare enough scenario. This can be done better, but with an additional performance cost I didn't want to take.

    ps.: In my opinion shadow strength option doesn't have much sense in a physically based rendering system and proper GI/environment lighting should suffice, unless you're doing stylized NPR rendering.
     
  38. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    I tried to reproduce the issue but there are too many factors.

    My initial guess is that the problem is related to specular lighting and energy conservation.
    Could you test with specular tuned down to zero on both materials and set "Environment Intensity" on skin material to 1?
    Environment Intensity parameter actually leads to energy loss if it's less than 1 (and default is 0.5). I probably should change the default to 1.0 and/or compensate the energy loss somehow. The raison d'être of this parameter is to mitigate light leaking because reflection probes are not occluded, but it's not physically correct.

    If that's not the issue, would you mind sharing some info about the scene (or better, the scene itself)?

    Thank you.
     
  39. Crossway

    Crossway

    Joined:
    May 24, 2016
    Posts:
    376
    Hi, what happened to the new version?
     
  40. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    82
    Hi, I'm currently running in some trouble. I am using a separate head model on top of a character with the neck texture of it fading out with transparency. Does this shader support transparent textures?
     
  41. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Transparency (alpha blending) is not supported, but I think what you're doing is better done with detail texturing. Detail texturing is the number one requested feature and is in the works for next version.
     
  42. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    82
    Hm.. too bad. I really need that overlaying geometry to fade out in some way. Because it just overlaps and clips through the rest of the body model.
     
  43. rdagar_007

    rdagar_007

    Joined:
    Nov 4, 2016
    Posts:
    4
    Can I use this shader in mobile for VR?
     
  44. Alvarezmd90

    Alvarezmd90

    Joined:
    Jul 21, 2016
    Posts:
    82
    The detail texturing is great idea tho. Will it include normal map detail too?
     
    Crossway likes this.
  45. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    933
    Might I suggest that instead of having separate Specular Map (RGB) and Glossiness (R), you simply make it Specular (RGBA)? Standard specular workflow is to have the alpha channel a gloss map, it's what most people would expect. Plus you'll save on a texture sampling operation.
    Code (CSharp):
    1.                 // Sample the spec&gloss with different blur levels as well to reflect the fact that light coming from an area varying in size affects the fragment.
    2.                 // This used both for "bumpiness" of specular itself and energy conservation, so it affects diffuse as well.
    3.                 fixed4 spec = PSS_SAMPLE_BLURRED_IMPL(_SpecularMap, uv, lerp(bumpinesBiasMax, bumpinesBiasMin, blur), i.texMipCnts.y);
    4.                 o.SpecularIntensity = saturate(spec.rgb * _SpecIntensity);
    5.                 o.SpecularRoughness = 1.0-spec.a * _SpecGlossiness;
    Also, dunno if it's been mentioned before, but when an Application.CaptureScreenshot() is done with superSampling set on it, the subsurface color seems to become very intense during the screenshot.
     
    Last edited: Nov 6, 2016
  46. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Thanks for reporting the screenshot issue I'll look into it.
    Try using the "combined" version of the shader. It's all about combining textures for efficiency. The channel setup may be a bit unintuitive and far from standard, but it's combined in a way to optimize the shader by grouping together textures that need to be sampled in similar way (the blurred sampling). It also cuts some non-essential features though.
    I'm looking into introducing use of "shader keywords" to make things somewhat configurable, but arguably the only complete solution is a material editor like Shader Forge/Unreal Engine.
     
  47. cician

    cician

    Joined:
    Dec 10, 2012
    Posts:
    233
    Yes. Normal map is the most important thing to have in the detail.
     
    Alvarezmd90 likes this.
  48. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    933
    Another issue which may be related to the super sampling issue I mentioned, if you lower the "Texture Quality" in your game's QualitySettings, which just forces the game to use a lower mipmap level, the skin material becomes increasingly darker the lower the texture resolution. Are you perhaps generating mipmaps on your lookup textures?
     
  49. nickyoso1

    nickyoso1

    Joined:
    May 2, 2011
    Posts:
    85
    Any plans to support transparency or would there be an easy way for me to implement it myself?
    The reason I'm asking is because I use Morph3D's character solution(MCS). MCS only works with shaders that support transparency because at runtime they use injectionmasks to hide parts of the model that are covered by clothing to prevent skin poking trough clothing.

    Also if I understand correctly from reading this thread this shader only supports forward rendering?
     
  50. MegsTan

    MegsTan

    Joined:
    Oct 19, 2013
    Posts:
    55