Archive 17/01/2023.

Is it possbile to use one billboard for a lens flare?

GodMan

I need to create a single quad that faces the camera for a lens flare effect. All I see is just possibly billboards. Is it possible to use the billboard system for just one quad that is static and always faces the camera?

Not use it for an actual particle system.

Modanung

Yes, that’s perfectly possible. :+1:

Besides, you might run into multiple bright light sources later. Maybe you could subclass the BillboardSet as a LensFlareSet to which you can add Lights (similar to adding Nodes to a StaticModelGroup). This would be generalized for varying colours, brightness and light types while checking the visibility of each with a screen ray cast.

GodMan

Okay I’ll see what I can come up with.

Modanung

You could also use a Sprite, btw. The main difference being that it’s a UIElement.

GodMan

It’s not really for a lens flare. This is what halo calls them. I just need a quad that faces the camera like the particle system does.

I’m trying to make the sentinel lights.

Modanung

That is what I think of when I hear the term “lens flare” in a game development context.

GodMan

okay. I’m gonna try this with the billboard system.

GodMan

Okay I got it. Thanks @Modanung . Going to add the other lights.

Modanung

If you’d like to get rid of the flare intersecting with the model - which I imagine you would - simply add depthtest="always" to the technique of the flare’s material.

GodMan

Fixed the flare colors to be more accurate. Added the depthtest to the technique.

SirNate0

With the “always” setting for depth testing I think you’ll also need to make sure that it’s only visible when it should be, i.e. walls and such need to occlude it in software and/or you need to check whether the flare should be shown with a raycast to the center point or something. Otherwise I’m pretty sure you’ll see it through the walls even though the turret itself isn’t visible.

GodMan

Yeah I’m aware of this. I’ll have to think of a simple approach for this though.

Modanung

I’d do an octree raycast and then quickly fade the flare in or out - with a little scaling - using a ValueAnimation, when the visibility should change. You might want to disable occlusion to make sure the fade out finishes, preventing the flare from suddenly disappearing.

GodMan

I have no idea how to do the octree raycast.

Modanung

Have a look at the Raycast function from the Decals sample; 08.
Where you would of course replace NormalizedScreenPos with WorldToScreenPos. Apart from that change, you basically have your (in)visibility check right there. You might even do without the parameterization, use the distance from the light to the camera as maxDistance and disregard the hit position and drawable. Maybe send it just a const Vector3& worldPos.

Modanung

I guess you would at least want to check the Drawable's type to prevent other BillboardSets (or the same) from hiding the flares. Which also means you’d need to use the Octree's non-single raycast, as these may be the first hit drawable.

GodMan

Great post @Modanung I will look into this when I get a chance.