Search Unity

Showcase [Open source] 200 moving point lights with real time shadows

Discussion in 'General Graphics' started by burningmime, Nov 10, 2022.

  1. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    There's a mentality that ray-tracing is for high-end effects -- basically, doing things rasterization can't, and doing it slowly. For example, Unity HDRP offers 2 options for ray-traced shadows: regular ray-traced shadows and contact shadows. Both of them are waaay slower than using a shadow map. But what about doing things rasterization can, but doing it faster? What about making use of that RT hardware on a 2060 or a newfangled Android device? On opposite day in bizzaro world, can raytracing actually be faster than rasterization?

    upload_2022-11-10_15-38-35.png

    upload_2022-11-10_15-40-20.png

    Runs at about 280 FPS my 3080 @ 2560x1440 with 200 point lights; I also tested it on a 2070 and it was over 120FPS.

    The limit is 32 shadow casting lights per 8x8 tile. So you can easily do a few thousand lights if the lights are small enough. Since it uses ray tracing, it scales w/ the number of pixels, not the number of lights. You could up it to like 64 lights per tile, but that would be overkill.

    There are various ways to soften the shadow edges, either when you sample them or by doing blur passes beforehand. I was doing some Gaussian blurs on the screen space result buffers, but that only works for up to like 8-16 lights, before it gets too expensive. There's also dithering. If I come back to this, I may explore other options. But for now you get pixel-accurate hard-edged shadows.

    I can see this technique being useful...
    • in an RTS or simulation game where you're looking down at 100 cars/tanks who all have headlights. Or a dozen soldiers with flashlights.
    • Large interior environments like a school or hospital, especially if multiple rooms are visible at once (think simulation and design games, eg Two Point Hospital)
    • VR where you want to hit high frame rates and can't afford to draw tons of shadow maps
    • Anime or low-poly games where you want the hard-edged shadows instead of soft shadows.
    Download (Windows + DX12 required): https://drive.proton.me/urls/HSB3P9M7Y0#s5uY60OWjBm9

    Source code: https://gitlab.com/burningmime/lots...ay-traced-shadows/Packages/MimeRenderPipeline

    Uses a custom SRP. There are probably ways to integrate it into the other pipelines (at a small performance cost), but I don't plan on doing that or putting it on the asset store any time soon. This was more for my own amusement.
     
    Last edited: Nov 11, 2022