Use object as mask for mixing color

Hi. I was using the material tab of blender. I wanted to use an object as factor for mixing 2 colors. I selected “object” input and I was thinking that the result would have been a mask and where the object touches the surface of the cube there would have been a change of color. Instead I get this result. there is some sort of linear gradient but it moves if I move the diamond.

Is there a way to do this without touching the compositor? I repeat, I do not want to use the compositor.

Immagine 2023-01-21 110905

Color attribute is stored on vertices. So if your model has only couple of them the gradient distribution will look like this. Try to increase geometry subdivisions.

1 Like

Hmm, you can use object’s location (but not its shape) to place a texture on a material. The texture might be something like a spherical gradient, where the location indicates the center of the sphere. Or maybe a flat projected image. Scale of the object will control scale of the texture.

image

But in shading you won’t be able to get the shape of the object. For this, as silex points out, you need a denser (much denser) geometry.

maybe geometry nodes can do it. I will do research but, I ask you in advance if t makes sense or not to start this research. Basically each time I try to learn something new I can take months, and before realizing, the effort becomes a separated project.

You will still need dense geometry - because GN solutions will only produce Vertex Paint (which naturally needs… vertices).
Actually there should be a support thread about this from last year.

2 Likes

In Geometry Nodes you might want to use Geometry Proximity node to detect how close one mesh is to the other.
This however will need more dense geometry too as attributes are written to vertices.

2 Likes

This method works and you were right, you need very dense geometry

Immagine 2023-01-21 185937
Immagine 2023-01-21 190427

Dynamic paint?

I am mixing materials with vertex color as an attribute, I needed this method because I am doing stylized characters that have fixed hilights that I dont want to change. If the world light changes, the specularity too is affected. And at first I used masks but I was unable to predict them, instead if I use objects as “masks” its going to be better, since now I can parent such objects to bones and use them in an animation. The caveat is that I do need a very dense geometry

That’s a pretty huge caveat, especially for animation. Why not just paint the mask?

1 Like

the geometry is not too dense. I will take 10 seconds for each frame to render since most of the resolution can be done with multires modifier.

With animation, it’s not just about render time- playback speed matters as well. You can’t get accurate timing with low FPS, and high density usually lowers FPS

1 Like

I have multiresolution