How can I measure the amount of light hitting a mesh?
I want to create a variable that shows the amount of light hitting a mesh (e.g. a small cube that is partitally shadowed) Is there any measurement, how much light hits the mesh? Or, is there a not too complicated way to get create one? Thank you for any answer!
asked Jul 25 '16 at 10:45 AM in Rendering
From what I understand you have a few options:
The easiest is simply to do a line trace from the object to all lights and see if you are visible. This will not be very flexible, but it is cheap and easy to implement. This is just a visible, not visible system. You can not be partially visible. However, what you can do is to use distance between the object and the light to indicate how visible you are. 5 meters away or closer and you are completely visible, 10 meters away or farther and you are invisible.
You can also use a distance based method where all you do is check if the object is close enough to the light. Let us say that you have an object in the world and your light has a range of 5 meters around you. Then you can have a hitbox around the light that triggers on overlap. You can filter the overlap events to only continue if the class of the other object is of a certain type. That way you can select what is being affected and what is not. This can also be combined with a trace.
Another option that will give you more accuracy and more flexibility is to have several locations on the object that all check if they are visible IF they are within range to be effected. That if is needed to not waste resources. You can then have a simple calculation to find out how visible you are by adding the light values of each point by doing an independent line trace for each.
Finally you can write a custom material that goes though all vertices or fragments and calculate how much is actually visible to the lights. This is very expensive and is not easy to do properly. For 99% of all situations where you might want it some version or combination of the methods I outlined above will be preferable.
I hope this helps.
answered Jul 25 '16 at 01:37 PM
If you need it for gameplay purposes, I suggest doing a trace from the object to the light, checking if anything interrupts visibility. For better approximation, you could do this from several points( all corners of the cube), and average the results. This is doable in blueprints. Obviously you can only afford to implement this for 1 object only, for performance reasons.
Rendering side of things looks different. It is possible to approximate this in post process material, but no way nearly accurate. You should inform what are you intending to achieve, since in most cases when such questions arise there already is an elegant solution
Follow this question
Once you sign in you will be able to subscribe for any updates here