Is there some way to set a param within a material so the material can set a variable and the actor can know about? Or so the next frame, the material has the value it set last frame?
I’m working on an effect, a simple FX card that does not write to depth. I do a depth test using the object position WS of the card, and compare it to the scene depth to determine if the center of the card is occluded. Finally I use an IF node to select opacity 1 or 0 depending on if it’s occluded or not.
But I don’t like that it’s a switch.
I would like to fade the card over a fraction of a second when it becomes occluded, but I can’t figure out how to interpolate the opacity over a few frames based on whether a condition in the material is true or not.
You can achieve the fading effect by using the Lerp (Linear Interpolation) node in your material. You can set up a Material Parameter Collection that holds a float value between 0 and 1 representing the fade factor. You can then bind this value to the Alpha input of a Lerp node that interpolates between two values based on the fade factor.
In your Actor Blueprint, you can then expose a function that updates the fade factor over time. This function can be called in the tick event of the Actor, and you can use the delta time value to gradually change the fade factor.
You will need a dynamic material which can be created in a blueprint, in order to access the material features.
If you need to access the parameter inside of a material that is set by the material, then you can use the same method as I mentioned. You will have to use blueprint as an intermediate to change or get the values of a material (A dynamic material). Alternatively you can use shader code, vectors and camera features to calculate such things within the shader. Depending on the complexity a full shader solution would work as well.