I have a imposter material that works fine with static meshes actors, but not with foliage: it does not rotate based on camera location.
I’m assuming the issue is in the Position input pin of the ImposterUVs node. I tried to use the “TransformPosition - Local Space to Absolute World Space” node and connect it’s output to the input pin, but it doesn’t seem to work. I found many people saying to do that, but only in posts or threads that are a few years old, so maybe it worked in older engine versions.
Fun fact: it works only if the foliage instance is located at 0,0,0 (world location).
If this is the case, how do I get the foliage instance location in a material?
Why did “TransformPosition” returns the position of the foliage instance when plugged in the base color, but appears to be returning the location of the entire foliage actor when plugged in the ImposterUVs?
The issue is caused by the “Transform Position” node. It works fine in vertex shader (uses the transform of the foliage instance), but not in the pixel shader (in which it is using the transform of the whole actor, not the foliage instance). A simple solution for this would be using a “Vertex Interpolator” node between the “Transform Position” and the “Position” input pin of the ImposterUVs function. However, it will lead to a compiler error because the “Position” input is being used by both vertex AND pixel shader, and the “Vertex Interpolator” can only be used in pixel shaders.
So, there are two possible solutions to this issue:
Do not use the ImposterUVs function; instead, create your own custom solution (that’s what I made)
Modify the ImposterUVs function and include the “Vertex Interpolator” inside the function, where the Position input is being used
Here it is. But my implementation is simplier - it only rotates around Z, and don’t allow custom rotation (all billboards will have the same orientation). It uses the SubUV function to get the cell from the textures. Since my shader have some other stuff, I took a printscreen containing only the imposters the part: