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:
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
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:
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:
Unity AssetBundles for VaM 1.xx - Guides -
After some people essentially begged me to do it, I spend several evenings this week and the this entire Saturday on writing a tutorial on Unity AssetBundles. It ended up to be an 13 page PDF of 2700 words. Lots of pictures, obviously. This...
hub.virtamate.com
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