Change material color dynamically, with textures applied

I have already asked for help on dynamically changing the color of a material based on a z-threshold, and I succeeded with a material without textures, by specifying one color for the part of the object above the threshold and another for the part below, and it works. However, I also want to reproduce this in more complex materials, with textures.

If I do as shown in the following figure (“Code” screen), or as I did for materials without textures, my rock looks like the photo below (“Result” screen), which is too black and too white.

The result I would like is for the rock to be its original color at the top, which is achieved by connecting the Input Albedo node directly to the base color. (“Base Color” screen)

And at the bottom I would like it to be a little darker, which is achieved by connecting the output of the Power node directly to the BaseColor.(“Little bit darker” screen)

I don’t understand why the colors change so much when using Lerp… shouldn’t the final color be between the input in A and the input in B? The two inputs, as mentioned and seen from the previous photos, are correct when taken individually and applied to the BaseColor… but maybe I’m doing something wrong.
Maybe there is a better way to create the 2° color (“a little bit darker” screen)?

EDIT
I realized that there is a simple way to create the “Little bit darker” version, by multiply the input albedo with a 3vector. I obtained the same “little bit darker” version, but also the same “result” if i put the output of multiply into Lerp…

1 Like

image

Okay, thanks, but

  • How to decide the color? Darker was only an example, but maybe I will need other gradients

  • How to decide, and make dynamic, the z level that control the color variation?

Like mine example, that I can choose what color add and the z level

1 Like

You can have two of anything, and fade in this way.

Two differnet textures
A texture direct, and multiplied by a color

Anything :slight_smile:

EDIT: I think that the problem is when I use as input of lerp a RGB value without V=1 (V of HSV)… but I think that to have a darker version of a color I need to put V<1… or not? But studying better multiple colors, there is a problems whit some color, also with V=1. I don’t know why, but when I put some couple of color, the result is not the same couple… Bah… If you can help me with a different solution but with my necessity… So, it’s likely that your solution is the winning one, but can it be modified to meet my “needs”?

So, your solution works, but I don’t think I can use it for my purpose. Maybe I didn’t explain myself well, or I’m not able to modify it to fit my needs. I want to achieve a result with a less pronounced gradient, like in figure 3, where I used a cube as an example. However, I still want the gradient to be editable, like in my code (by changing the value in the ‘Add’ function, I can increase or decrease the size of the gradient). Additionally, I can also choose at what z-location to create this gradient, through a parameter (ZLocMax) that can be dynamic. In your solution, the gradient is too wide, and it’s not editable, and it doesn’t depend on the object’s position.

So, to recap, I’m doing it like in image 1, but the colors (in this case, colors; later, I want to do it with textures, but even with simple colors, it doesn’t work) are totally off… in fact, the red color, taken individually after the multiplication with the vector (also potentially dynamic), turns out to be a slightly darker red. Instead, if I use two completely different colors, like in figure 2, the result is correct even though it’s not what I want to achieve, since I want to have a darkening and not a total color change. In figure 3, the cube with 2 different colors, but with the correct idea of what I want to have. In figure 4, what happens if I use two similar input colors, only one darker than the other.




I don’t understand what’s happening… what can I do?

P.S. Just for reference, the rock (which would be one of the final objects) with its original color seen in one of the other photos, if I put the RGB of the texture in one input of the Lerp, and in the other the same but slightly darker, this is what comes out…

What about

gradient

I’m sorry, but no, for several reasons. In particular, with this solution, there’s a bug due to the fact that the gradient occurs on all faces (I think you noticed that). Additionally, it doesn’t meet my crucial requirement for the color change to occur on a global Z-axis, so that (as seen in my previous video) when I move the objects, the gradient changes position on the object based on its height…

1 Like

Or

grad2

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.