• Hi Guest!

    Please be aware that we have released a critical security patch for VaM. We strongly recommend updating to version 1.22.0.7 using the VaM_Updater found in your installation folder.

    Details about the security patch can be found here.
  • Happy Lunar New Year from the VaMHub Team!
    VaMHub 团队祝您蛇年大吉,新春快乐!
Custom Dual Pass Hair Shader for Unity

Toolkits + Templates Custom Dual Pass Hair Shader for Unity

Well I got seriously side tracked when attempting to write a plugin for my next port, and wrote this (with tons of help from ChatGPT lol):

A custom unity shader that gives hair softer edges with alpha blending but maintains opaqueness for major solid part of the hair.


When porting CUA hair with pre-multiplied alpha texture or alpha map, there was usually only two choices: standard unity shader with alpha cutout, or standard shader with fade/transparent.

Each option has its own problem:

with cutout, it is hard to get a smooth nice blended edge since there are no transition between the pixels. You are left with really ugly jagged edges. Also sometimes it is hard to get an optimal cutout value, if too low, you are left with black outlines around the edges, if too high, you lose actual pixels of the hair.

with fade/transparent, the edges are smooth, but the entire mesh is doing alpha blending, which means you can usually see the character's skull through the hair. Plus the color is off and you lose normal/spec details.

This shader basically combines the two options into one: first it does an alpha cut out pass, then an alpha blend pass. Together you get softer edges but solid, detailed hair body.

I added basic lighting in the shader. I think it should handle most VaM situations, although you may see some weird stuff if the lighting setup is complex and too dynamic. The shader gets ambient lighting too. The specular is not that good in my opinion, and sometimes you can see some white artifacts.


Here are the comparison:

1738054311_.png



1738054177_.png


1738054217_.png


1738053996_.png


1738054006_.png

How to use:
This is not something to use directly in VaM. It is for importing CUA from Unity.


If you are not familiar with Unity/CUA import process, refer to Macgruber's guide here:

1. Unzip the file and place the .shader file into Unity's Assets/Shader directory. Refresh and let it compile.
2. In your material inspector, pick Custom/DualPassHair under shader drop down
3. pick hair albedo (color texture) and normal map. For the albedo texture, if your hair texture doesn't come with alpha pre-multiplied, use any graphic software (PS, GIMP etc) to merge it so the color texture has proper alpha applied.
4. adjust alpha cutoff, shininess etc for best look for your hair. (alpha cutout 0.5, shininess 75 is a good starting point, but optimal varies based on texture and mesh)
5. Build assetbundle



Warning:
Only tested on Unity 2018.1.9f2, not guaranteed to work in newer versions
There could be slight performance impact due to the additional passes. I have not done much performance testing so please let me know if the impact is significant.



First time writing a unity shader and sharing it, won't be surprised if there are bugs. Please let me know any issue you run into.

Thanks
Author
regguise
Downloads
223
Views
1,484
Favorites
5
Version
1.3
First release
Last update
Rating
5.00 star(s) 6 ratings

Latest updates

  1. Replaced shininess with specular intensity and smoothness. Fixed a few issues regarding specular

    Changed shininess property to specular intensity. Added Smoothness property Now with smoothness...

Latest reviews

Thank you for your contribution! That's really amazing. I really hope there can be more shaders specifically designed for VAM, like fur effects!
Upvote 0
Magic
Upvote 0
Nice job! Confirming for eyelashes/eyebrows as well. In fact, can be used with other albedo w/alpha cases such as foliage etc.
Upvote 0
Man you don't know for how long i've been looking for a shader like this that actually works in vam like it does in unity, tried a dozens of custom shaders but they all end up looking cooked when inside Vam, thanks a ton for this!
regguise
regguise
Thanks! Yup I was in the same situation as you that's what prompted me to look into this. I'd say it is still primitive so please share feedback for further improvement
Upvote 2
This is awesome!! Thankyou :D Cant wait to try it out
regguise
regguise
Thanks! I imagine there would be bugs and area needed improvement so please kindly provide feedback when you try :)
Upvote 1
amazing job thanks!!
regguise
regguise
Thanks!
Upvote 1
Back
Top Bottom