r/Unity3D•
Nyoox

Help with material colors

Question

Hi everyone I need help (again).

I want to change the material color of a 3D mesh gradually using code like a custom filling animation(not the straight one), but I don't know how to do it.

Here is an ugly example: Filling animation

Thank you

Posted May 16, 2017, 9:48 AM UTC

16
Matt3088•

Lets say that the gif you linked has 4 stages of "bubbles" that fill up the screen, the first stage fades in, then the second, then the third and then the fourth and final one.

What you need to do is create a texture, starting from the fourth stage and working backwards, to fill in bubbles in a texture from white and the first stage will be black (sort of like a gradient). Here is what I mean: http://i.imgur.com/7Ovt8rG.png

Think of that texture as a height-map. When you want to change the color, the shader time will start at 0 (need to use a script for this) and the height will start at, say, -0.25. Time will then increase this height slowly, fading in each stage (lerp between 2 colors) depending on how close it is to the current pixel's "height". I may not have described it well, but I hope that can get you started. I can help you with the code/shader, or I can write it myself for you (but not right now)

1
NyooxOPHobbyist•

Hi Matt, it's you again! Thank you for this answer, so it's another shader code problem? I need to apply this effect to a material of a 3D mesh. So I must create a texture at all costs?

It would be extremely helpful if you can help me write it. Thank you again!

1
Matt3088•

It is me again haha. What does the 3d mesh look like and how do you want it to swap the colors? For example, it might be hard to do if it was a human model

2
NyooxOPHobbyist•

No, it's is almost always a flat surface, sometimes it has regular bumps, but nothing complicated. Imagine it as a cube for the sake of simplicity.

I want to start changing the colors gradually starting from the bottom side and way up to the top on the Y axis with a custom "animation"/effect like the one in the gif. But I must change the material color because it's a material shared with other "cubes".

1
Matt3088•

I see. I could help you write the code tomorrow as it is late here. It doesnt seem too complex

2