Search Unity

Unity Character Surface Shader pack (trailer)

Discussion in 'Shaders' started by panta, Jan 30, 2013.

  1. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Hey guys! I've been hard at work trying to code a set of shaders for rendering characters in Unity 3D. I want to include an eye shader, hair shader, and skin shader in the pack. Here's some images of my progress so far:
    $Eyes2.PNG
    $Eyes.JPG
    $HairAndEyeShaders3.JPG

    And here's a trailer video showing the shaders in action!


    Comments and crit welcome :)
     
    Last edited: Jan 30, 2013
  2. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Wow, that looks really good, love it!
    But whats up with the creepy body texture? : D
     
  3. Mauri

    Mauri

    Joined:
    Dec 9, 2010
    Posts:
    2,664
    Seems to be work in progress :D

    It looks really great. Especially the eye shader!
     
  4. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Thanks for the support, Virror and Mauri.

    Those textures are WIP. When I'm making skin tight suiting for sci fi characters, I trace out the suit topology in zbrush using polypaint. That's what the netting looking texture is. I guess it is a little strange if you don't know what it is!


    Did some research today; I think I've settled on an algorithm for the skin shader I want to make. I'll keep you guys updated! Pack should be posted soon, tutorials soon after that.
     
  5. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Hi Panta, I have a clear and present need of a hair shader :) Is there any chance you might release before May? I kind of need to have it in my game in the next 2-3 weeks :(
     
  6. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Hey anadin,

    It doesn't totally work yet unfortunately :( There's a problem in DX11 mode and I also am having trouble with mip maps. I'll try my best to release it next week when I go on break from university.

    PS: will you be using it on mobile or desktop?
     
  7. msgamedev

    msgamedev

    Joined:
    Dec 24, 2011
    Posts:
    491
    Great work, even now it looks a 1000 times better than the existing shaders that could be used for hair.

    I assume the hair shader is double sided to display polygonal hair correctly?

    Does it support alpha in the diffuse map and spec in the normal map?
     
  8. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71

    You are correct! it is indeed double sided.

    About the alpha - yes, it's stored with the color map (which is actually just black and white - color comes from the shader variables)

    For normal - I'm not sure how much you've played with Unity texture compression, but the method used for Normal maps in shaderlab *does not* support an alpha channel. This is confusing to a lot of people when they wonder why their spec map (in alpha of normal) disappears :p

    Therefore, spec is stored in a 3rd map, and the alpha is used for a noise/jitter pattern taken advantage of by the Kajiya kay lighting model. No wasted channels :)
     
  9. msgamedev

    msgamedev

    Joined:
    Dec 24, 2011
    Posts:
    491
    Alright, have absolutely no plan of programing - just a 3d modeler.

    But good to know about the double sided and that spec maps are supported.

    Will definetively use the shaders.
     
  10. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Yes, thank you for your interest! I should release them next week while on break with an accompanying set of tools (for different eye colors/styles, etc.) and meet anadin's schedule.

    keep a look out!
     
  11. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    Sorry,But what does 'anadin' or 'anadian's schedule' mean?
     
  12. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    "anadin" is the person who requested the hair shader before May, earlier in this thread.
     
  13. Lulucifer

    Lulucifer

    Joined:
    Jul 8, 2012
    Posts:
    358
    ;).............
     
  14. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    Yeah, sorry, that's what I meant by that.
     
  15. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Whoo Hoo! can't wait :)
     
  16. msgamedev

    msgamedev

    Joined:
    Dec 24, 2011
    Posts:
    491
    Any news? Still hoping for this shaders.
     
  17. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Yeah chomping at the bit, how is it going?
     
  18. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Sorry to bug you but is this still coming?
     
  19. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    So sorry guys, I promise I'll release this soon. I'm a senior in university and I'm incredibly stressed with trying to graduate this coming month. All my classes are piling up work. After May 15, I'm taking a 5 month break to work on a bunch of Unity stuff, so I'll be able to finish it then. Also Anadin, huge Cubemen fan! That's awesome that you're interested in this kind of thing
     
  20. anadin

    anadin

    Joined:
    Oct 28, 2005
    Posts:
    98
    Yeah Cubemen was fun to work on, I did the animations but did not have time to work on Cubemen 2 unfortunately - go buy it!!

    In the meantime, is there any chance of buying the hair shader as is now? We are supposed to be final in about a week and I still don't have one - eek!
     
  21. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    I would also love to buy this shader pack, looks great.

    Some questions :
    * Does it work in both Forward and Deferred ?
    * Does it cast shadows ?
    * Does it receive shadows ?
    * Does it Self Shadow ?
    * Is it Shader Model 2.0 compatible?

    In the meantime I really needed a hair shader here is my solution so far:

    I started from : http://wiki.unity3d.com/index.php?title=Anisotropic_Highlight_Shader
    and made some tweaks.

    Negatives ( If anybody knows how to fix some of these, that would be great, thank you):

    * I really don't know how to get it to self shadow
    * the setup is a bit complex with the 3 channel _SpecularTex
    * I removed the normal map, didn't feel necessary for hair ( do your hairs have normal maps ? )
    * I removed the whole _AnisoTex deal, cause I really don't know how to create a proper directional texture. ( the wiki instructions are kinda vague, maybe somebody understood this deal ? )
    * the spec is kinda wild
    * the inside of the hair is as bright as the outside (maybe can be fixed with an if and some maths)

    Positive:

    * removed the #pragma target 3.0 (probably cause I removed all that stuff up there )
    * made it cast receive shadows
    * made it double sided
    * only specular based on light angle ( original shader has specularity on dark areas)
    * added a specular color intensity multiplier

    Code (csharp):
    1.  
    2. Shader "Aniso Shadow"
    3. {
    4.     Properties
    5.     {
    6.          _MainTex ("Diffuse (RGB) Alpha (A)", 2D) = "white" {}
    7.          _SpecularTex ("Specular (R) Gloss (G) Anisotropic Mask (B)", 2D) = "gray" {}
    8.          _SpecularMultiplier ("Specular Multiplier", float) = 1.0
    9.          _SpecularColor ("Specular Color", Color) = (1,1,1,1)
    10.          _AnisoOffset ("Anisotropic Highlight Offset", Range(-1,1)) = 0.0
    11.          _Cutoff ("Alpha Cut-Off Threshold", Range(0,1)) = 0.5
    12.     }
    13.    
    14.     SubShader
    15.     {
    16.         Tags {"Queue"="AlphaTest" "RenderType"="Transparent"}
    17.         Cull Off
    18.  
    19.         CGPROGRAM
    20.         #pragma surface surf Aniso alphatest:_Cutoff addshadow
    21.        
    22.              struct SurfaceOutputAniso
    23.              {
    24.                 fixed3 Albedo;
    25.                 fixed3 Normal;
    26.                 fixed3 Emission;
    27.                 half Specular;
    28.                 fixed Gloss;
    29.                 fixed Alpha;
    30.                 fixed AnisoMask;
    31.              };
    32.                    
    33.              struct Input
    34.              {
    35.                  float2 uv_MainTex;
    36.                  float2 uv_SpecularTex;
    37.              };
    38.              
    39.              sampler2D _MainTex, _SpecularTex;
    40.                  
    41.              void surf (Input IN, inout SurfaceOutputAniso o)
    42.              {
    43.                 fixed4 albedo = tex2D(_MainTex, IN.uv_MainTex);
    44.                 o.Albedo = albedo.rgb;
    45.                 o.Alpha = albedo.a;
    46.                 fixed3 spec = tex2D(_SpecularTex, IN.uv_MainTex).rgb;
    47.                 o.Specular = spec.r;
    48.                 o.Gloss = spec.g;
    49.                 o.AnisoMask = spec.b;
    50.              }
    51.              
    52.              float _AnisoOffset, _SpecularMultiplier;
    53.              fixed4 _SpecularColor;
    54.    
    55.              inline fixed4 LightingAniso (SurfaceOutputAniso s, fixed3 lightDir, fixed3 viewDir, fixed atten)
    56.              {
    57.                 fixed3 h = normalize(normalize(lightDir) + normalize(viewDir));
    58.                 float NdotL = saturate(dot(s.Normal, lightDir));
    59.                
    60.                 fixed HdotA = dot(normalize(s.Normal ), h);
    61.                 float aniso = max(0, sin(radians((HdotA + _AnisoOffset) * 180)));
    62.                
    63.                 float spec = saturate(dot(s.Normal, h));
    64.                 spec = saturate(pow(lerp(spec, aniso, s.AnisoMask), s.Gloss * 128) * s.Specular);
    65.                 spec = spec * _SpecularMultiplier;
    66.                
    67.                 fixed4 c;
    68.                 c.rgb = ((s.Albedo * _LightColor0.rgb * NdotL) + (_LightColor0.rgb * spec * _SpecularColor * NdotL)) * (atten * 2);
    69.                 c.a = 1;
    70.                 return c;
    71.              }
    72.              
    73.         ENDCG
    74.     }
    75.     FallBack "Transparent/Cutout/VertexLit"
    76. }
    77.  
     
    Last edited: May 29, 2013
  22. LNMRae

    LNMRae

    Joined:
    Dec 28, 2012
    Posts:
    48
    Your work looks great so far, I'm especially interested in the hair shader. Trying to deal with sorting issues is driving me crazy. Glad to hear this is still in the works!
     
  23. blackant

    blackant

    Joined:
    Jun 18, 2009
    Posts:
    529
    your shaders looks really impressive, i'm waiting for it.
     
  24. LNMRae

    LNMRae

    Joined:
    Dec 28, 2012
    Posts:
    48
    Any word on this? Is it still in production?
     
  25. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Here is a hair test: ( unity webplayer )
    what do you guys think ?

    I borrowed this head model (just for testing purposes) from a game. See if you can guess which one = ]

    One head is using a fancier version of the shader above lets call it (fakey aniso) and
    the other is using what I believe is a simple Kajiya-Kay specularity.

    Panta's shader still fancier with the added Marschner and all, but I had to make due !
    Panta we want your shader already = O !

    If somebody is really interested you can assemble it together, I'll leave some breadcrumbs:

    1) look at the shader I posted above for fake hair like specs.
    2) http://docs.unity3d.com/Documentation/Components/SL-AlphaTest.html , look at that Vegetation shader closely
    3) read this: http://forum.unity3d.com/threads/96393-Achieving-a-multi-pass-effect-with-a-Surface-Shader
    4) http://answers.unity3d.com/questions/269292/having-an-invisible-object-that-casts-shadows.html get those shadows back
    5) http://forums.odforce.net/index.php?showtopic=2208 , kajiya-kay ; )
    6) take a look at this post for tangents: http://forum.unity3d.com/threads/184441-How-can-I-get-tangent-on-a-surface-shader

    if you cant hack it together I'll trade what I know/have for a nice hair model for testing or
    applicable practical information from any of these papers below:

    Marschner, http://www.cs.cornell.edu/~srm/publications/SG03-hair-abstract.html
    Henrik, http://graphics.ucsd.edu/~henrik/papers/artist_hair.pdf
    Zinke-Yuskel, http://www.cemyuksel.com/research/dualscattering/
    d' Eon, http://onlinelibrary.wiley.com/doi/10.1111/j.1467-8659.2011.01976.x/full


    here is a picture using same kajiya-kay shader as in webplayer example above,
    but using the Scheuermann trick to shift the highlight using a texture as seen in this presentation:
    http://developer.amd.com/wordpress/media/2012/10/Scheuermann_HairRendering.pdf

    $scheueman_shift.png
     
    Last edited: Aug 23, 2013
  26. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
  27. Rammra

    Rammra

    Joined:
    Jul 8, 2012
    Posts:
    54
    Hair shader looks awesome. Too bad they are all surface shaders :(
     
  28. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Why ? Whats the problem with surface shaders?

    In my opinion, making them surface shaders makes them the most flexible to work in all Unity target platforms.
     
  29. Rammra

    Rammra

    Joined:
    Jul 8, 2012
    Posts:
    54
    We decided not using them because of low performance on mobile devices. I also think they suffer from lack of flexibility.
     
  30. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    part of what you get when you purchase, is support, so if you need the shader with a specific something I can make a variation of it for you.

    About them running slow on mobile, anything with alpha test runs crappy on mobile,
    if you want a version with no alpha, just any of the 3 specularities, I can strip it down and
    make a variation that will run faster on mobile.
     
  31. Dolkar

    Dolkar

    Joined:
    Jun 8, 2013
    Posts:
    576
    It's not that hard to convert stuff to vert/frag shaders... do #pragma debug, copy-paste the code and strip down the stuff you don't need. You can throw away half of the computations in the vertex shader in general case and a few bits in fragment as well.
     
  32. Rammra

    Rammra

    Joined:
    Jul 8, 2012
    Posts:
    54
    I remember once I tried this #pragma debug, but the compiled shader was looking like shader assembly. Maybe I should try that again. Anyway, lets not hijack Invadererik's thread. Also it doesn't matter if we can convert these shaders to vert/frag. There are at least few years for such realistic hairs on mobile.
     
    Last edited: Sep 29, 2013
  33. GXMark

    GXMark

    Joined:
    Oct 13, 2012
    Posts:
    514
    I've just purchased your package and looks superb. Reading the thread concerning surface shaders and performance on mobiles. Would you be able to put together some mobile friendly shaders based on these shaders and add them to your asset store Advanced Hair Shaders asset?

    For us guys not very good at converting shaders over to vert/frag would be a big bonus!
     
  34. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    GXMark, I'll look into making a version that is more optimized for mobile, thanks for the purchase !
     
  35. rungy

    rungy

    Joined:
    Oct 25, 2011
    Posts:
    23
    recently purchased as well...happy with the shaders for the information in the lighting mdels...

    1) why am I not getting blend from a diffuse png. that has an alpha? (it is using cutoff...but your screen shot has it using blend?
    2) Are you planning on supporting normal maps? (our own Anisotropic looks really good with normal maps btw...)
    3) Are you still interested in trading knowledge/development for art resources? (... really great girl's head and hair model?)

    (Running 4.2.2 Full Registered Pro)
     
  36. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hi, thanks for the purchase!

    1) The shader uses both alpha cut and alpha blend, you control that using the alpha cutoff value, I recommend using a pretty high value as close to .99 depending on your alpha channel of course. Notice the example material has a pretty high alpha value.

    2) If you want a version with normal maps shoot me an email and I'll be happy to make one, if you send me your invoice number I'll email it back quickly and I'll also include it in the next update along with a couple of other requests/bug fixes from other users
    ( optimized mobile shaders, skyshop support etc. )

    3) Yes ! I still would love to showcase these shaders with some great art. I'm looking for something that's textured and possibly animated. Email me = )
     
  37. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hey just wanted to let people know that I have updated the package to version 1.004 with:

    Better mobile support ( now all 3 versions of the shader can run on shader model 2.0, and are optimized to run on mobile, I have tested the circular version on ipad 2, ipad 3, iphone, ipad mini and it runs pretty well )

    Direct3d 11 support ( previous versions alpha did not work correctly on d3d11 )

    Normal mapped versions ( shader variations with normal maps added )

    Skyshop integration example ( 1 example skyshop shader, shows how you could layer these specularities on top of your regular skyshop shaders) ( only works in forward rendering mode)

    Correct non correct double sided version ( in case you don't want to have double the geometry with flipped faces )

    no-alpha or tube shading support ( in case your hair doesn't need alpha )

    Support for hair with horizontal uv's ( I forgot to mention that the shader technique relies on your hair uv's being layed out vertically, these versions use the the u instead of the v direction )

    Most of these updates are a direct result of user requests, so make sure to email me with your requests!

    Also please take the time to rate the package on the store, I wish to get enough reviews so that it actually shows up.

    So now that I got most of the requests out of the way, I plan to work on the Marschner shader next. Looking forward to
    adding more value to the package in 2014 = ]
     
    OneWayRoad likes this.
  38. OneWayRoad

    OneWayRoad

    Joined:
    Jul 27, 2013
    Posts:
    26
    can your shader get aniso even without lighting?
     
  39. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hi OneWayRoad,

    Currently I have not included versions that require no lighting, but it would be simple enough to add using a map or world normal to simulate the light source. Let me know if you really need this feature, and I can make a version for you if you send me your invoice.
     
  40. OneWayRoad

    OneWayRoad

    Joined:
    Jul 27, 2013
    Posts:
    26
    Your hair shader looks pretty but Im now more interested in PBS.
    are you planning to make a pbs version of your hair shader?:)
     
  41. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Hi OneWayRoad,

    I have a shader for Lux. Which pbs system are you interested in? I havent looked into adapting it to work with unity 5 pbs system yet, but I do plan to look into it.
     
  42. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    By the way, a couple of people have contacted me regarding support for Unity 5 for the Advanced Hair Shader Package, since the alpha is not working the same as in Unity 4.6. I found a temporary fix for this problem and if you need it right now, shoot me an email with your invoice number so I can provide the temporary fix.

    I want to better address the issues and integration with Unity 5 features better to release a Unity 5 package. Hopefully I will have it ready for when Unity 5 is officially released.
     
  43. atmuc

    atmuc

    Joined:
    Feb 28, 2011
    Posts:
    1,162
    Does current version on Asset Store support Unity 5?
     
  44. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    Not yet, sorry. However, if you email me your invoice I can send you the version that I have so far.

    Here is a link to pretty much same demo as I had for 4 running in 5:

    http://www.inversethought.com/Eriks/hair5/
     
  45. OneWayRoad

    OneWayRoad

    Joined:
    Jul 27, 2013
    Posts:
    26
    when will you update your hair shader on Asset Store?
     
  46. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
  47. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    860
    Hello guys,

    Any of you have an idea of why this Unity hair shader doesn't work on Consoles? Any ideas?

    Regards,
    Carlos
     
  48. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148
    I've never had the chance to build Unity for any console so no idea really. Is there a specific
    error that shows on the console or shader warning / error ? Which console are you targeting ?
     
  49. strongbox3d

    strongbox3d

    Joined:
    May 8, 2012
    Posts:
    860
    I am targeting XBOX ONE Erick,

    I will try the update you emailed me and see what happen. thanks so much.

    Regards,
    Carlos
     
  50. invadererik

    invadererik

    Joined:
    Oct 31, 2010
    Posts:
    148