Draw a flare from inside a solid object.

Is there a way to have a flare show up on your camera if that flare is send from a lightsource inside a gameobject, in my case a sphere.

I've tried setting the culling mask and read docs on lightsources, but I can't find anything on this. I understand this is not the way you're supposed to use flares but it would be a perfect fix for a problem I'm having.

Many thanks in advance!

Edit: Added a bounty because I think the answer might be very relevant to other users as well - even though it's not really important to me anymore atm. Please do only answer if you have an answer, and not just a guess hoping to get the points ;)

4 Answers

4

I might have a good enough answer for you. If the object you have the light within has no collider, the flare works. If you needed a collider on that object then I'm not so sure. This suggestion also works with lens flares attached directly to the object. Hope this helps.

Cheers,

Daniel

You could edit the builtin shader (Internal-Flare.shader) and adjust the rendering order with a queue tag and/or play with the ZTest and ZWrite settings. I will make a test and edit this "answer" and add the results.

I also noticed the "collider-effect" (see Daniel's answer) but for me it seems more like a bug?!

Cool! Can't wait. :-)

I don't think it's a bug. Actually, it makes sense. Terrain and buildings for example, usually have colliders and usually you want flares stopped by these, as sunlight is not passing through either.

You could parent the object emitting the lens flare to the sphere object at it's forward axis point and then script the sphere it lookAt the player. The lens flare would follow the player round the outside of the sphere, effectively.

Whow, intelligent workaround! Thanks!

You can add the flare component to an empty gameobject rather than a point light. Then you’ll have access to a layer mask to control what layers block the flare. See the original answer here: How do I make flares ignore a certain layer of colliders? - solved - Unity Answers