[HELP] Lens flares Created 4 years ago2020-11-12 13:02:44 UTC by Petko Petko

Created 4 years ago2020-11-12 13:02:44 UTC by Petko Petko

Posted 4 years ago2020-11-12 13:02:44 UTC Post #344850
So im trying to make lens flares. I have made a pretty good concept,
but I just dont know how to do the math part of it.
Basicly I just want to copy the lens flares from the unofficial pc port
of Half-Life: Decay (flare effect on maps: dy_uplink, dy_dampen).
Basicly I just need some help with the math part of it, by that I mean
calculating which angle should the lensflare effect be facing, and how
to calculate the distance between sprites/flares. Ive done some testing
and I came to the conclusion that TRI-API is drawing the flares in decay.

Help with these lens flare effects would be much appreciated.
Posted 4 years ago2020-11-13 20:38:50 UTC Post #344853
One simple method, perhaps, is to use TriAPI's "world to screen" projection of coordinates, if your "sun" is somewhere in 3D space and you're performing a traceline every few frames to determine its visibility.

That way, you'll get the 2D coords of the farthest lens flare, which can be the sun sprite itself. Then draw a series of sprites that are offset from each other, going towards a "pivot" (which is the centre of your screen). In other words, world-to-screen projection followed by multiple reflection around the screen centre.
Mistake: It's WtS instead of StWMistake: It's WtS instead of StW
It's quite simple if we treat the pivot as position (0, 0). Let's say if WtS is (-8, 20), its reflected counterpart (let's call it R) would be (8, -20). And then you subdivide the "line" between them and put some more flares.
For example:
FlarePos1 = 0.75*WtS + 0.25*R
FlarePos2 = 0.50*WtS + 0.50*R
FlarePos3 = 0.25*WtS + 0.75*R

The other method is some trigonometry where we do this projection manually, that is, implementing a perspective projection matrix to convert some 3D coordinates into 2D. Then you do the same thing as above.
https://www.scratchapixel.com/lessons/3d-basic-rendering/perspective-and-orthographic-projection-matrix/building-basic-perspective-projection-matrix
Admer456 Admer456If it ain't broken, don't fox it!
Posted 4 years ago2020-11-13 21:54:41 UTC Post #344854
@Admer456 Thanks for your help, I really appreciate it, it helps me by alot. By the way good luck with your programming video tutorials.
Posted 4 years ago2020-11-14 11:16:32 UTC Post #344857
Ay, you're welcome. Speaking of tutorials, I think some basic TriAPI lens flares would be good tutorial material, for example on the TWHL Wiki.
Admer456 Admer456If it ain't broken, don't fox it!
You must be logged in to post a response.