Search Unity

How to create a light cone or shaft of light?

Discussion in 'Editor & General Support' started by bigkahuna, Aug 31, 2006.

  1. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    I've been experimenting with this and haven't figured out how to do this yet. Any suggestions? What I'm trying to re-create is the "shaft" of light you can see when looking perpendicular to a flashlight. I tried using "self illuminated" cylinders and cones, but I'm not getting the effect I'm looking for.

    Here's an example of what I'm talking about: http://www.smugmug.com/gallery/167709/7/6279882
     
  2. Mindless_Soul

    Mindless_Soul

    Joined:
    Feb 1, 2006
    Posts:
    128
    I think what you are looking for is volumetric light. I have wondered about this too.
     
    Lopro_ likes this.
  3. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Yes, thanks for that. "Volumetric light" is exactly what I'm looking for.
     
    Lopro_ likes this.
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Something like this maybe? You can walk around and it holds up from pretty much any angle, except from inside the beams. That's done with 4 spotlights for the lighting on the floor, though it actually doesn't look that much worse without them.

    --Eric
     

    Attached Files:

    Remjie, XCO and tapticc like this.
  5. hsparra

    hsparra

    Joined:
    Jul 12, 2005
    Posts:
    750
    Eric, thank you for sharing the example :) It is excellent, even I can understand it. Everything else has been stripped out so it is easy to focus on the important parts.
     
  6. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    I hope non-Unity users pick up on the impressive fact that you can ask a question here, and quickly get not just an answer but a working example!

    Leaving aside how helpful the community is... How often is that rapid turnaround for custom issues even possible in other engines I wonder?
     
    TomOtero likes this.
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    It also helps that I was thinking about this issue myself just recently. :) The main drawback with that example is that the light beams have to be pointing straight down, since they always rotate to face the camera. I'm not really sure how you'd do it if you wanted them at an angle.

    --Eric
     
  8. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    You could still get a normal that pointed at the camera, I would think. You'd just have to accept that the beam went through the floor, but you wouldn't actually see any effect from that anyway.
     
  9. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    The other common solutions is just to do a model of cone-like shape, with many layers (i.e. decreasing radius cones inside). Then map a bit of noise-like texture on it, maybe even scroll it at runtime, all with transparency. I did whatever thing is here this way once.
     
  10. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Looks perfect Eric, thanks very much!
     
  11. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    It's still not the effect I'm looking for, but at least it's a start. I used the cone from Eric's package, rescaled it and changed the texture so it fades in the distance. I also used two cones similar to Aras suggestion. I'm not sure why it's brighter at the edges than in the center. It must be due to the vertex lighting, but I haven't figured that out yet. I'd also like to make the effect relatively invisible when viewed from the vehicle (first image).
     
  12. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    My technique definitely won't work for that sort of thing. I was trying to avoid the nesting objects to get a perfectly soft edge with a texture instead, but that only works if you can rotate the object about the Y axis to always face the player. (Not to mention, it only works with a cone and not any other shape.)

    So I'd say you want something more like this instead...nesting objects seems to be the only way (you need a bunch for something like a soft edge), but it would probably look better with some noise in the texture as Aras said. Also you'd want to use an actual spot light in addition to the objects, with a cookie for non-round shapes.

    As for making it less visible from inside the vehicle, just decrease the opacity of the material in that case.

    --Eric
     

    Attached Files:

  13. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Thanks Eric, I'll give that a try.

    I also thought I'd try playing with the "Halo" effect also. I wonder if I could stack several Halo's of increasing size and decreasing intensity as it moves away from the source of light and in the path of the light. I'm afraid that where the Halos overlap the intensity will be higher, but I'll test it to find out for sure.

    The other thought I had was whether the Halo effect could be edited (easily hopefully) so it is in the shape of a cone instead of a sphere. Anyone know if this is possible?

    Thanks again!
     
  14. Morgan

    Morgan

    Joined:
    May 21, 2006
    Posts:
    1,223
    I think the halos are technically flat discs, not 3D spheres--which is OK for circular effects, but wouldn't be the same for cones.
     
  15. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Thanks Morgan. I ended up using something similar to Eric's last illustration, except I set the opacity to 1% and added 5 scaled cones. The effect is "acceptable", but not nearly as nice as I've seen in other engines.

    Next task is to get "lens flare" working. I think I've set everything correctly, but I'm just not seeing any flares. Off to search the forum posts...
     
  16. NicholasFrancis

    NicholasFrancis

    Joined:
    Apr 8, 2005
    Posts:
    1,587
    Halos are basically textured disks (you can set which texture to use in the RenderSettings), - they are, however, stretched towards the camera at the center to give a better impression of a volume.

    they are not good for spotlight cones, though....
     
  17. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Thanks for that clarification Nicholas.
     
  18. terransage

    terransage

    Joined:
    Jul 17, 2006
    Posts:
    290
    Thanks, Eric and Aras, for your excellent ideas, downloads and illustrations. Like Morgan said, I'm also impressed with the great people in this community and at OTEE. Every day I learn much more than I ever expected.
     
  19. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    There's a bit of a "gotcha" with flares...they are blocked by any colliders at all, whether there's transparency or not, or even a mesh renderer or not. Anything you want flares to show through, put on the TransparentFX layer.

    As for the volumetric lighting, if you use a nicer texture than mine, it will look nicer. :)

    --Eric
     
  20. kevinseligmann

    kevinseligmann

    Joined:
    Mar 23, 2011
    Posts:
    68
    Would it be possible to add some noise to the gradient texture for a more realistic effect?
     
  21. Monkey Balls

    Monkey Balls

    Joined:
    Oct 22, 2013
    Posts:
    10
    Thank you so much, I was looking for that =]
     
  22. MarkD

    MarkD

    Joined:
    Sep 18, 2013
    Posts:
    193
  23. username_unity_of_my

    username_unity_of_my

    Joined:
    Feb 24, 2015
    Posts:
    330
    Or you can use this simple light beams / shaft shader pack from the asset store if you like.
    Asset Store Link.

    Here's short video.


    and another:
     
    Last edited: Feb 9, 2016