Hi, I’m new to the forum. I made an account cause I can’t take this anymore, maybe someone can help me out on this. The Standard Lens Flares package is totally glitched for me.
1st Issue - I’m using GUI.DrawTexture() to draw a crosshair for my FPS game. Every time the player looks directly at the sun the lens flare disappears because the crosshair is above it. I can’t change the Layer at which the crosshair appears because Unity does not use layers to render GUI…but apparently it does…cause it causes the lens flare to stop as if a collider was on top of it.
2nd Issue - if a collider appears in front of the lens flare, the lens flare completly disappears. I know this is the intended behavior…but if a collider is smaller than the lens flare…it shouldn’t disappear completly right? the light should “go around”. If the lens flare is half occlused by a collider…half of it should be visible.
As for the second issue I could change the layer of the projectile…but that would cause the lens flare to go through it…not around it.
Also…the lens flare disappears on the edges of the camera unless a set the fade speed to about “1000” or “9999”. This is a secundary issue as I solved it by setting the fade speed really high.
Please help me out I’m desesperate…I’ve tried everything. Thank you.
This may or may not be helpful, but the solution is probably to not use GUI.DrawTexture. The GUI.* and GUILayout.* functions are actually pretty bad for in-game UI, for several reasons, including performance, difficulty of making the layout look good, and the weird way they insert themselves into the rendering queue - which is probably the source of your frustration here. I’d probably recommend using a different system for your UI (either hand-built via a separate camera, or through a system like NGUI, or just waiting for 4.6 to come out with uGUI).
That’s not how it works. Whether the lens flare is visible is a binary thing because it determines this by raycasting directly from light source to camera - this means there is no in-between. It fakes an in-between by fading the light source in and out whenever this switch is flipped, but make no mistake, it’s always just on or off.
Pretty much the only way around this would be to code your own lens flare system (which would either have to use multiple raycasts to determine whether it is to be drawn and at what intensity, or possibly do something tricky with the camera’s render queue) or use one from the asset store (though I suspect many of those behave the same way as the built-in one in this respect.
So I’ve decided to go with your advise and I am now using NGUI to display the crosshair, I was really happy to know that my crosshair looks exacly the same as with my previous approach. However the issue remains…the sun disappears whenever the crosshair is on top of it. I may have done something wrong perhaps, I’m somewhat new to ngui.
I now have set the crossHair UI on a new layer called “UI Layer” and set the sun flare to ignore that layer, but it doesn’t seem to help. setting the flare to ignore Everything doesn’t change this either.
Ok I’ve now figured this out now. the crosshair was not the problem, it was due to the camera culling, when I moved the mouse the lens flare got out of range. But this creates me another problem, now I have to extend the culling distance just because of the flare. Is there any way to add it with a special render layer so that it gets rendered all the time despite the distance for the camera like the skybox?
Yes is a gameObject containing a directional light, a lens flare for effect and a script that moves it around the current planet. Problem is the far clip plane is set to 1000 and aparently when I move it in a certain angle the flare seems to be out of range. If I increase the far clip plane solves the problem…but uses more gpu as the terrains are really big and I don’t need that much of a render distance…1000 would be fine.
Hm… a directional light’s lens flare should never be “out of range”. This is beginning to feel like we’re wandering into “Unity bug” territory. Can you create a simple repro case of this problem?
Worst case, a workaround could be to have a second camera whose sole job is to render that flare.
You are right, the direcional lens flare does not disappear…however sometimes it disappears in the editor which appears to be a bug…but not something I am concerned about. However…diretional lens flare do not move. I made an example scene https://dl.dropboxusercontent.com/u/106802374/lensFlare.unitypackage
Steps to recreate this scene:
Add a game object with a light and a directional lens flare,
add a script to move the flare on update()
now if you start the editor you can see the directional lens flare even if out of range, but it does not move. Unchecking the “directional lens flare” and it shows up moving. Ticking back the directional lens flare box and the flare goes back to the default position…even if its position is now changed as it can be seen by the editor. I guess directional lens flares were not meant to be moved.
That issue can be easily seen in my prepared scene posted above.