Unity-Technologies/com.unity.demoteam.hair

How to colour each hair strand differently, depending on another object's colour at a certain vertex?

DanielaAuroch opened this issue · 5 comments

(Please let me know if there is a better place for this, as I wasn't able to find a section in the Unity forum for the Hair System).
Unity version: 2021.3.8f1
Render Pipeline: HDRP

I have a cube with a texture with different colours, like so:
image

To this cube, I am applying a Hair Instance component and I give it a material. I would like to colour the hairs according to the coloured sections of the cube. So: white hair on the white sections, light brown hair on the light brown sections.

I have found solutions online that were on C# and used ray casting, but that doesn't seem like a good approach given the immense amount of hair strands that could exist. Nor was I able to find a way to iterate through said strands.

My idea was to do this in shader graph but I'm not sure how to accomplish that.

Another important note is that the cube colours are changed by a shader. So the cube could be any colour and I'd need to pick the colour of each hair strand based on the colour applied to the cube at a certain vertex.
image

I tried something similar using a texture for the colours and was able to use the rootUV property in Shader Graph. How does your shader work? Is the colour applied to the vertices, or is it generated at the fragment stage? If it's a vertex colour it might be possible to pass it to the fragment stage as a custom interpolator, then use it there.

Screenshot 2022-10-24 at 5 31 45 pm

Thank you, extremely simple and straightforward! This does work for 1 object with 1 material. The final object I'm working with has several materials targeting certain UVs so it doesn't work correctly with this solution.
I'll have a think about how I'm approaching things to see if I really need several materials first. If I do still need them, I'll update here, otherwise this is what I was looking for so thanks again 😄

Glad I could help. The package really needs some documentation and demo scenes. I'm worried it's going to be abandoned.

A hair tutorial has been added to Unity Learn. Hopefully this repository will be updated soon.

Labeling as documentation request. :)