Heat based material in Unreal Engine 5

Hi. I’m trying to create a material function that visually represent the heat across the surface of an actor in UE5.

Goal:
The material function should so so the actors heat is visually represented in a way that low heat makes the actor look darker, while high heat make the actor look whiter. In addition to this it should simulate heat distribution across the actors surface. For example if the sun is shining on the actors right side the right side of the actor should gradually become lighter in color as it heats up on that side while the left side of the actor should remain the base heat of the actor.

If the actor is turned so that the right side of the actor is now the side facing the sun the left side, which is now in shadow, should retain the heat it gained from its time in the sun, but should now gradually cool down until it reaches the base heat of the actor. The right side, who is now being hit by the sun, should gradually warm up.

Current implementation:
In my current implementation I store variables for base heat, max heat, current heat, heatup speed and cooldown speed of the actor and calculate the heatup of the actor based on the direction of the sunlight (the sun isa directional light in the scene). It uses a material instance to create a individual instance of the material that has the material function applied to it and sends the heatup data as parameters to the material function.

Picture showing the logic of one of the actors:

The material function calculates the direction of the sun and uses scalar parameters to get the heatup information from the actor. It then uses that to color the actor surface based on the sun direction and the heatup values. The result is that the actor is gradually becoming whiter on the side the sun is hitting it and remains darker on the other side.

Picture of the logic in the material function

Picture of an actor in the scene (the sphere). You can see it is lighter on the side the sun is hitting it and the side its not being hit has the lightness determined by the base heat variable of the actor.

The problem:
The problem with the current implementation is that while the actor gradually warms up on the side the sun is hitting, the actor doesn’t actually store any data on where on its body the different heat values should be. So if the actor is warmed up on the left side then turned around so that the left side is now in shadows the material function does not remember that the left side should be warm from the heatup and now needs to gradually cool down and the right side should be cool and now gradually heat up. So when the actor is turned the actor will just always be bright on the side facing the sun and always darker on the side facing away from it.

What are ways I can go about fixing this so that I get the corect result? I’m not in love with my implementation so I’m open to completely changing it if that gets me to where I want to be. I’m also open to making custom nodes in C++. This also does not need to be rendered in 30 or 60 fps so if there are solution that requires processing power, but still gets me where I want to be i’m open to hear them.

Thanks in advance for all help!