Lasers and Lights

Started by
7 comments, last by Enalis 14 years, 1 month ago
Hi! I'm coding my own 3D space shooter, I have laser fire set up, collision detection is also working. One thing I noticed though is that the laser fire *should* also illuminate the objects it hits or passes nearby. Any suggestions on how to handle that? Do I have to dynamically create a point light and place it somewhere on the beam's path for every object that the beam passes close enough? For every beam/nearby object in view? That sounds expensive... Alex
Advertisement
I'm guessing the easier way is to mess with the ambient lighting of the objects it passes trough/by but that would light up the entire object. For better looking results I think you're going to need a shader.
One approach to this would be to implement deferred shading in your game, which would allow you to render many, many lights at relatively little cost. Obviously this is considerable work to implement, however.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

Unless there is a scattering medium like fog, laser shouldn't illuminate the objects it passes nearby but if you want to have the effect you can implement a line light in shader. Check minimal distance to the beam and calculate the illumination using some falloff function (~ 1/r).

I fear I am going to need to do it in the shader then... :-)

Deferred lighting would be an option but I don't want to make such a significant change to the rendering pipeline at this point.

As for line lighting, the question would be then to choose the angle at which the light should fall in. Orthogonal projection onto the beam doesn't strike me as right as the light would come from the side. I figure I would have to calculate the orthogonal projection point and then move a bit along the beam towards the camera for a point of origination in order to have some satisfying result.

And fortunately I have no shadowing implemented... :-)

thanks,
Alex
At that point, I would just render a soft, largely transparent, additively blended cylinder, centered on the laser bolt/beam.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

A google search will show you how to find the closest point on a line to a given point - it's not hard and easily doable in a vertex shader. (The given point being the centre of your object). Move back along it a bit (about the radius of your object) to get a better visual.

When you have this magic point, just light the object using the same code as for a point light that's at that position. If you want to do it per pixel, just pass up the calculated point as you would pass up other geometry "normally".
------------------------------Great Little War Game
Quote:Original post by ak-73

I fear I am going to need to do it in the shader then... :-)

Deferred lighting would be an option but I don't want to make such a significant change to the rendering pipeline at this point.

As for line lighting, the question would be then to choose the angle at which the light should fall in. Orthogonal projection onto the beam doesn't strike me as right as the light would come from the side. I figure I would have to calculate the orthogonal projection point and then move a bit along the beam towards the camera for a point of origination in order to have some satisfying result.

And fortunately I have no shadowing implemented... :-)

thanks,
Alex


point lights would work well enough if you place them appropriatly (you only need to place lights on points that are close to an an object and you only need to have lights that are close to the recieving object active. (so one light per beam that you move around as you render the recieving objects should be enough)

It really depends on what quality you're aiming for though, If you're allready using shaders its not that hard to get a line light working.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
Swiftcoder's approach would be a quick, and very cheap way to do it, that would give you the results you want.
Douglas Eugene Reisinger II
Projects/Profile Site

This topic is closed to new replies.

Advertisement