LERP between two materials?

So I am trying to make a material change from one to the other over time (it’s a skydome object). For the LIFE of me I cannot figure out how to make it fade from Material A to Material B over a timeline. I am positive that this is achievable via blueprint, but I cannot figure it out. Anyone have any advice or pointers?

Yes there is a way to achieve this thought material instances and material instance dynamics (MIDs) controlled via a blueprint.

The requirement is that your two target instances A and B both have the same parent material and use all the same setting names etc (no different static switches or blend mode overrides allowed). You should still easily be able to paramaterize your sky material to handle either extreme.

Then you need to create a blueprint with the skydome mesh (or simply reference it via a BP somehow), and create a Material Instance Dynamic for the sky mesh. Then if you come off of the result pin for the MID, you should be able to find a node called something like ‘Interpolate material instances’. This lets you assign an A and a B input that are both material instances and a timeline input to blend between them.

You can even stagger several of these by making the B of the first the A of the 2nd etc. That can make for some pretty cool custom morphing animations.

1 Like

I’m still having trouble figuring this out. I have SIX materials, that are RANDOMLY chosen based on weather patterns. All I need this to do is lerp between the OLD MATERIAL and the NEW ONE over a timeline.

When i try to SET the NEW SKY material, none of my materials show up in the Select Asset drop down. Seems like MIDs only allow me to control parameters inside a material, not change the material entirely. I’m not sure if I am explaining my problem very well.

Basically, I need it to go from material A to material B over x seconds, not lerp between to values of a parameter inside any one material.

Would it make more sense if I said i need to lerp between two TEXTURES? Say, sunny to cloudy, or cloudy to stormy, or stormy to foggy… whatever?

That is incredibly easy. Sorry I didn’t know you meant this, I thought it was more complicated :slight_smile:

So just place two texture samples in a material. Then place a “linear interpolate” node. You can simply press the “l” key and click anywhere.

Then hook up your two textures into the A and B slot.

Then create a scalar parameter. To do this hold “s” and click and give it a name, maybe something like “alpha” or “blend”.

Then you can change the value of that scalar to blend between the A and B inputs. This doesn’t just work for textures, it works for blending any set of material nodes.

You can control the blend either in the base material, or by creating a material instance to be able to drag the value using a slider. Or you can use a blueprint to create an MID and change the value during the game using the set scalar parameter node on the MID.

I get that, but how do I set WHICH texture to blend in, inside the blueprint for my weather system?

Basically, the system decides which sky to blend to every x minutes in order to match the new weather type (six options). So I need to be able to dynamically change from the CURRENT texture, to a NEW texture, which is being decided dynamically inside the weather blueprint.

Your suggestion would only allow me to blend from one texture to another, based on the two samples in the material. I have six possible textures that are being randomly chosen inside the weather blueprint. Basically, the weather decides which texture is A and B, then lerps between them over a timeline that I use for all the other weather effect.

The skymesh is a component of my weather system, so passing updates to it is not a problem, its setting A and B dynamically that I am hung up on.

It’s not really anything different than what I described to blend more than 2. There are many ways to go about it.

You could either stagger multiple Lerp nodes in the material, such that there would be a layer priority, and then make sure you control the alpha values correctly.

An alternate way to do this would be just use ONE lerp node, and make both textures texture parameters. Then inside the BP you could change the textureparameters by leapfrogging them. What I mean by that is:
You blend between A and B. When B gets to 100% (meaning alpha hit 1), then you swap A to a new texture, and then to continue your fade in reverse, taking the alpha from 1 to 0. Then when it gets to 0 again, this time you change texture B and afterwards ramp from 0 to 1 again. You could do this indefinitely and the blueprint script to do so should be very straightforward.

That second thing might work. I will give that a try!

Any chance you could show me a node network sample of the alternate way you described above?

you mean the blueprint or material? the material is simple:

The blueprint work would be more custom. It sounds like you already have a system that picks which type of storm/texture it wants. All you need is some way to alternate which texture and which direction the fade goes. You could simply use a FlipFlop node or some other flow control method to do this, ie every time you ‘fade’ you switch to backwards alpha fading and swap the opposite texture.

Just wanted to say that your idea did work for me. It may be simple but this is just an alpha build anyways so it’s perfect for my project. Thanks so much for your time !

This needs to be pinned somewhere… or better referenced by search engines. After the whole night of researching incredibly complex ways of achieving this and still failing, I finally stumble on this at 4am.

, I want your babies. This really helped thank you!

Hello RyanB, I got the approach you suggested initially (instanced materials and MIDs…) working, though it seems to not blend different textures in instances A and B. Is there a way I can achieve this? I would really like to blend two different materials as they are, with all their properties.