Calculate Object Screen Size in Material

Using blueprint only, I am trying to calculate an Objects Screen Size (Percentage: 0-1) in the material editor to drive a scalar parameter value for an alpha for a linear interpolation node. Basically, I want to adjust the brightness based on the objects screen size. I am using a Dynamic Material Instance, so I would be able to some calculations in the objects blueprint to help drive the value if everything cannot be calculated in the material editor alone. I would also like a value of 100% (or 1) to be black (0) and 0% to be White (1).

I found someones equation in the forums,

approx_screen_percentage = bounding_sphere_radius / (distance_to_object * sin(fov_of_camera))

This seems to work to an extent, however when I try to reverse the LERP, it breaks and does not work and ends up always being white.

Hi there! Can you share all nodes in your material?

It is way too complex of a material to include all the nodes. This is the important part for what I am trying to accomplish, the result of these nodes is being fed into the emissive input. If I add a LERP with a=0 and b=1 and the result of these nodes as the alpha or try to use a 1- node to invert it, it just end up white and not fading.

The actual value for Camera FOV = 37.497356

I figured it out after hours of testing different combinations
This is how to get the screen size of the mesh in screen:

.

And this is the result:

330549-screensize2.png

For those who want to try it, it works, but there is a margin of error of 0.001 only when changing the screen percentage of the viewport. Maybe someone will be interested in posting a fix to that, but for me it wasn’t worth the time. Hope it works for you

2 Likes

They purged all user screenshots when they deleted Unreal Answer.
Can you reupload?