I have a problem. I made a lens flare effect, but it's super laggy

Test photo one

Test photo Two

Test video

So, everything is good when I only have a few lights but after adding example 30 the game lags so bad that it’s about to crash

image

my method uses Ray Casting and World To Viewport Point if some one can find a better method tell me please.

My Other Game: Take Care
My Group: Bad Dev Studios

3 Likes

You can try to use particles instead, they allow things to be rendered over other objects by setting its ZOffset value:
image
(If you decide to use the ZOffset, particles will be clipped when the camera is closer, so it’s probably in good practice to scale it by camera distance as well)

If you want to keep your original script, you have to share what it looks like, or else there’s not much to solve. Raycasting is expensive, and sometimes they’re better when validated in parallel contexts. If it’s not needed 240 times a second (max FPS on a normal Roblox PC client) for 30 objects, you can do it 5 times a second and simply fade them in and out. 5 per second would still look smooth, and you can always increase it if you want it smoother.

3 Likes

That’s a great idea. I will try that and let you know if it works.

1 Like