• Advertisement
Sign in to follow this  

Lasers and Lights

This topic is 2909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Swiftcoder's approach would be a quick, and very cheap way to do it, that would give you the results you want.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement