there is no easy way for materials to know where light is hitting them. but there may very well be easy solutions to your problem once you tell us a bit more about your specific use-case. for example if your spotlight is in first person, etc.
in that case you could figure out the spotlights position in screenspace (i’m assuming it’s moving around and not just in the center, which would make it even easier) and create a spheremask with that information to mask the mesh’s opacity.
You should be able to solve this analytically using world positions without resorting to screenspace. If you know your flashlight position and direction in the world then you can solve it in your receiver material.
The basis for this will be a spheremask and we will be computing a cone instead of a sphere by calculating a different radius along the length of the line. Just going to off the cuff this so apologies if there are errors.
I would start by making a “Material Parameter Collection” where you add two Vector Params: FlashLightPosition and FlashLightDirection. In your player BP, set these MPC values using the flashlight position and rotation X vector (assuming it points along the X axis, adjust accordingly).
Next place “Absolute World Position” and “Spheremask” into your material for the receiver. Hook WorldPos into the “A” of the Spheremask.
The B of the spheremask will be more of an expression using a line:
Once I fixed that I tested it out and it works perfectly.
Then to make this work for visibility you can change the ‘hardness’ of the spheremask and use it as an opacity mask. Keep in mind this won’t have shadows from the environment and if you need those, you will likely need a much more elaborate features like a scene capture just to get the scene depth as seen from the light. Or you could try to raytrace the scene depth for intersection.
Hello, this is an old post, but I need help. I can’t reproduce this effect, I think the problem is with the rotation of the Flashlight in my case. Coudl somebody give an example of a bp for “set these MPC values using the flashlight position and rotation X vector (assuming it points along the X axis, adjust accordingly).” ?
What did you do to make it work with opacity, could I see the BP if you still have it?
What I have so far is a material called InvisibleMaterial and have everything set up like in RyanB’s example but putting the material on any object just makes the object black and nothing else.
Capture Scene Depth from Flashlight
If distance Flashlight : Pixel > Scene Depth, Mask out.
I have all the math in the blueprint and material right for a spotlight (complete with inverse square falloff, Lambertian diffuse, and various specular models), I just need to figure out how to align the render target to the scene properly. It needs to be aligned as if it was planar mapped from the flashlight onto the environment, and the FOV needs to match the angle of the light.