Skip to main content
GameDev.net gamedev.net
🔒 Locked

Proper method for hair with alpha transparency?

Started by Kiiryu Mar 31, 2021 at 10:33 PM 6 replies 10.6k views
Original Post
Kiiryu
Kiiryu

I am trying to achieve hair like this, in Unity. It is just a plane with a texture, and has alpha blending. It's pretty common in PS2 games.

However, if I attempt to use alpha blending in Unity or Blender, the result is always something like this. There is a problem with sorting, and the texture erases itself, or displays in the wrong order, etc. (this is not a matter of backface culling, or double sided, either.)

When asking about this, the response is always that this is a “common problem in 3d”, and yet no answer is really given on how it's actually solved. Yet, given how common it was in PS2 games, surely it is a problem that has been solved multiple times.

So, what modeling practices do I need to adopt in order to make the effect work, and what do I need to do in engine? How is this problem normally solved?

JoeJ
JoeJ

Kiiryu said:
There is a problem with sorting, and the texture erases itself, or displays in the wrong order, etc.

Try to render opaque geometry in first pass, then turn z-write off but keep depth testing on, render sorted alpha geometry in 2nd pass.

Still artifacts, but that's the way you look for i guess.

Kiiryu
Kiiryu

@JoeJ What kind of artifacts?

JoeJ
JoeJ

Works well for convex shapes, but if geometry has multiple overlaps (curly hair), sorting can become too inaccurate.

For example if the bangs had a fold:

The hair mesh has to be cut onto multiple pieces, so every ‘depth layer’ becomes its own mesh. Likely 3 parts in that example.

But if you view the model from the side or certain angles, it still can fail again.

It's no big problem in practice. Because the z write is off the artifact goes mostly unnoticed. Pretty sure the PS2 games you have in mind did just that. The artists are aware and cut stuff accordingly.

IDK how to do this in Unity. If it really is necessary to generate multiple meshes, or multiple materials, just tags per triangle, etc.
And i hope i remember all this correctly.

JoeJ
JoeJ

Oh, i remember it also makes sense to set sorting order manually in some cases. If there are 2 layers of hair - an inner and an outer layer, you want to render the inner layer first. Likely the manual order causes less failures than sorting, but both can be combined as well.

After you figure out how to render it, it becomes clear and intuitive to fix pretty quickly with some trial and error.

Kiiryu
Kiiryu

@JoeJ I don't know that it would be possible this way, since if there are a lot of blades of hair, they are overlapping all over the place.

JoeJ
JoeJ

they are overlapping all over the place.

It's usually fine as long as they don't cross each other.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.