How can I make a 'dynamic' headlight lens flare?

As much as the title sounds bland or seems to already have an answer, I have something else in mind:

Figure 1:

I want to have a lens flare texture (not seen, I used an open red circle as an example) emit from a target (the open red square by the headlights) and I’d assume this would be done via a BillboardGui object. As-is, this could work just fine, but the thing is that I want the BillboardGui to grow in size if the player or camera gets farther away from the train (i.e if it’s approaching the player or camera in the distance) and shrink / fade as it gets closer. Refer to Figure 2 for another.

Figure 2:

When viewed from the side, the BillboardGui should shrink / fade - mainly to avoid the original size of the lens flare texture to unsightly clip into the front of the train. Notice in this image, only the target is drawn on. There’s no red circle to indicate the texture is hidden.

Screenshot_2

Possible Alternatives

  • I do know that I can use a SurfaceGui with a lens flare texture on it, but the thing wrong with that is it will not shrink or grow dependent on distance or angle and it will be strictly 2D, which will look ugly after a while.
  • The neon material works fine as-is, but it makes it harder for players with low-end computers to see oncoming trains and whatnot.

I believe @NWSpacek had a concept for this once and I wanted to try it myself, but note this was years ago and I have no idea if it still works.

5 Likes

I’m aware there are three different methods:

Method A:
Apply parts with decals until a volumetric effect is achieved. Too bad it’s impacting performance and probably physics.

Method B:
Magic with the particle emitters! Yes, it’s an amazing object to have to create any cool emission. Try certain textures, you may find the desired effect(oh and this can replace SurfaceGui in one way).

Method C:
A plugin that synthesizes volumetric lighting, I’m not entirely sure how to use it.

If you have another method suggestion, please post it here.

3 Likes

As much as all three (except the first one which is admittedly sketchy) methods sound, I don’t think ParticleEmitters are what I’m looking for. Method C appears to use physical parts for lighting, but even if it didn’t, it’s also not what I’m looking for. I tagged NWSpacek in this thread and hoping he responds, because his concept from years ago is what I’m envisioning.

I remember someone was using a method which I have seen, but never asked about. If someone finds it, I’ll put it for my personal usages. :slight_smile:

1 Like

Is there a specific post you are interested in by NWSpacek? If so, please link it here so we can understand what you are envisioning.

There is no post, as again, this was years ago and if anything, the DevForum didn’t exist or it was in very early stages.

However, I can provide an example from Train Simulator 2019 which uses a similar feature.

Lens flare up close:

Screenshot_3

Lens flare from slightly farther away; note the increase in brightness and size:

Screenshot_4

If you watch any gameplay or preview videos of Train Simulator, it is very similar to a BillboardGui that changes depending on camera angle and distance.

1 Like

That must be BillboardGui, definitely! It is just that you need a decal and a little more thinking about what to do with it when it’s far away.

You might be looking for attachments and beams. This is an example forked from the library but it gets to the point to what you may be looking for:


image
This has been discussed before and you can go to get more information here You can change the intensity of this beam in relation to distance via .Magnitude. When you get closer, you can implement some sort of Billboard Gui with the details.

12 Likes

What you can do is find the magnitude of the Humanoid in relation to the billboard, (you can put a part representing the billboard’s origin/position) and set a certain range in magnitude where a certain client sees the light brighter than other distances. This, of course, is just a concept. As for the actual lightning, I’m not too sure.

1 Like

As @uJordy showed, I would personally go for his method as it takes the least parts and can produce some beautiful results. I tried myself with my steam locomotives lamps and it produced some very nice images.

Would using this method cause lag/use more resources, since (from my understanding of what you wrote) you’d have to keep track of the position of each client?

Copy billboardgui on each client using a local script. Each renderframe, along with any camera stuff you are doing, work out the distance to each train, and set the image’s transparency accordingly.

Size-wise, I’d probably use an offset size for the billboardgui (possibly with a UISizeConstraint on the image to prevent it getting ridiculously big) for the light, to make it automatically appear to get smaller when you get closer (whilst in reality taking up the same number of pixels on the screen).

I can throw together a demo if you want so you can see what I mean.

A beam and some custom implemented logic that manipulates different GuiObjects is the best bet you’re going to have to do this. The only thing you will need to account for is modifying the distance of the endpoint constraint on the client.

Aside from this, you are not going to find peace in another solution. BillboardGuis do not have a plane-lock as you want and they do not disappear on side views - they’re constantly meant to face the camera. ParticleEmitters are the same way, except they don’t dynamically grow in size without developer edits and they aren’t really proper for this use case.

It can be quite expensive, but it honestly depends on how often you are checking it (for instance, checking this using a renderstepped may be expensive) But it shouldn’t affect performance too much to my knowledge.

I think you could probably use a glowing light particle that’s within the part to give it a bit of extra detail, try seeing if that works.