Gradually change a colour of an object.

Hello board,
I’m looking for some ideas to solve an issue I’ve got. I’m looking into a method of gradually change the colour of an object when it comes in touch with another. The colour should ideally grow out from one of the objects connecting.
I’ve already got control over the colour of the object via a texture mask and a colour swatch. But that is a global change and not directional.

One solution I see is to create a second UV set that will control the masking of the object. On this UV set you can offset a black and white mask, much like a video wipe.
Are there other better solutions to do this? A point sampling of the mesh via a shader so you can wipe from any direction? I’m looking for general ideas and not ready made solutions so all help is very welcome!

Mikael

I just think the simpliest you should use a projector attached to the moving object.

A projector, what is that? Can I create a UV set by just using a projection, much like in Maya/Max? Sorry for the possibly beginner question, I’m just starting to get familiar with the tech side of things in Unity.

What kind of objects those are? Spheres/primitives, more complicated shapes? (screenshot could help also)
Is the view free 3D (can view from any direction)…?

Maybe could use vertex colors, calculate distance from vertices…

I think a projector would be good.

You could also consider colouring vertexes - as mgear says - or volumetric shaders with 3d textures (Texture3D in Unity)

The objects are complex shapes most of the times. Although as a simplification you can see them as cubes. Yes, the camera is a free 3D cam (so many things I forgot to mention!).
Can vertex colours be used to drive the underlying colour of a texture? Or the colour modifier of a mask texture?

The wipe should work like this:
1446913--78029--$wipe.jpg

Just put a projector on the top of left side boxes and you are done.

I had no idea that unity had 3D shaders either. Thanks a lot for the help you two! I think I’ve got enough to continue working now.
Cheers!

This projector component seems to be either ON or OFF. Either the mesh becomes lit or it isn’t. Or am I just missing something obvious where you could have the transition gradual instead?

Import Projector package - did you? - and put Blob Light Projector to the scene. on the top of the left pile. Then you can keep the cone projection or set it to ortographic.

eh… no I didn’t. But now I tried the imported one and it works. Thanks for your patience!

I’ve played around with this for a bit now and it seems to be exactly what I am after apart from one tiny detail. Ideally I’d like the wipe to be between two different textures/materials. Right now I am just colouring the original texture.
Is there a way of sampling this mask in some way so I can choose which material ends up where?

Try to tweak the projector material shader and various shaders on the object subjected to projection.

I have just played with vertex colors and now can add here that you can also do that with use of a script similar to this one from here:

together with vertex color shader from here:
http://wiki.unity3d.com/index.php?title=VertexColor

Interesting! Thanks for letting me know. I’ve also got some nice pointers on achieving this in Shaderforge.

Why not use Color.Lerp to gradually go between colours?

http://docs.unity3d.com/Documentation/ScriptReference/Color.Lerp.html

You can change a material’s colour easily enough:

http://docs.unity3d.com/Documentation/ScriptReference/Material-color.html

You could get the distance between the two object transforms and feed that into the interpolation factor to gradually alter the hue based on object proximity.

It’s not as straightforward as just mixing colours unfortunately. It’s actually a blend between two textures, or rather a wipe. Joachim was talking about Lerps too for the setup in Shaderforge. I’ll have to try it out but I think his solution will do the trick. Thanks for your suggestion though!

I guess you could also manipulate a vertex colour shader by adding the texture to blend and use vertex color as the blending factor.