#Baking lightmaps for tons of room prefabs?

1 messages · Page 1 of 1 (latest)

cyan sphinx
#

hey there, sorry if this isn't the best place to put this question, but i haven't been able to find a good solution for this.

basically, i have a system that procedurally spawns prefabs (rooms) using WFC and that part works fine, but performance is absolutely horrendous due to the fact all of my lights are currently in Realtime.
i have over 100+ rooms, and although i've tried numerous solutions, they either don't work, or would be far too tedious to implement; if any of you have experience with this kind of thing, i would really appreciate it.

i can't use Bakery because i have an AMD graphics card and i'd also like to keep the repository public 😔

some stuff on GitHub i've tried (maybe i did something wrong setting these up? i have no idea lol):

#

if you can offer any tips or help please do 😭

#

Baking lightmaps for tons of room prefabs?

odd knot
#

TES: Blades devs implemented a lot of clever techniques to mitigate them
https://www.youtube.com/watch?v=KbxiGH6igBk

The Elder Scrolls Blades strove to produce high-quality visuals on modern mobile devices. This talk will describe the challenges of achieving that level of quality in procedurally generated 3D environments.

Speakers:
Simon-Pierre Thibault - Bethesda Game Studios
Sergei Savchenko - Bethesda Game Studios

Slides available here: https://www.slide...

▶ Play video
cyan sphinx
# odd knot Baking to prefabs should _work_ But the issue would be visual discontinuities be...

it's more about how i should go about making it work.. like i have a base to work off of i just don't know how to make it work, if that makes sense.

if this is useful to anyone, this code was the closest to working, but i was still getting errors and crap i didn't know how to fix (at least in Unity 6):
https://pastebin.com/LArMaVUJ (LightmapObject)
https://pastebin.com/K14DvK1p (LightmapPrefab)
https://pastebin.com/6sKzd9yY (LightmapObjectEditor)
https://pastebin.com/vVSbu7zj (LightmapPrefabEditor)

odd knot
#

At a glance I see modifications to material property blocks, which URP does not support

cyan sphinx
#

time to set it up again :P

#

i remember i changed some things to be compatible with URP but i think i probably missed some

odd knot
#

So I assume you're not using the AyaFel prefab lightmapping which doesn't have any of that

cyan sphinx
#

i don't remember at all where i got that code from lol

odd knot
#

Anyway, even when modular light baking works technically, practically it's pretty subpar

#

So you may have to consider ways to optimized realtime lighting

cyan sphinx
#

you think i could use adaptive probe volumes?

#

oh nvm it's scene-specific

#

i just don't get how i can optimize realtime lighting with sooooo many lights, like maybe 400+ lights in a map generation

#

culling helps a bit but i feel like performance is still bad lol

odd knot
# cyan sphinx you think i could use adaptive probe volumes?

Should look into them
Generally they're more expensive than baked lightmaps, and afaik the process to load them in with addive scenes is harder too
But if there's a way to attach them to prefabs then they would be better than prefab lightmapping
But maybe not by a huge margin because you'd still have discontinuity issues

odd knot
#

What platform are you targetting

#

What rendering paths can you use
More importantly have you profiled lights as the cause of your performance issues

cyan sphinx
# odd knot Any examples or more information? How many lights per module How big are their r...

sorry, i don't really have any more examples other than some screenshots of the rooms, since i've been remaking them recently; but i can tell you that to achieve these framerates, i had:

  • to be in the build version of the game
  • have rooms i wouldn't be screenshotting disabled
  • to disable all scripts (except for freecam, and some FMOD stuff ig)

as for those:

  • about 7 lights?
  • a range of about 15-20
  • spot lights with hard shadows and a couple of point lights
  • about 2 rooms worth of lights, so like 14
  • desktop
  • forward+ or deferred (since Forward doesn't support more than like 8 realtime lights)
  • yes, i've used the frame debugger and shadows/whatever else related to lighting take up the majority of the draw calls
#

sorry to dump all this info on ya, i was trying to avoid it lmao

odd knot
#
  • Forward+ and deferred make lights so cheap that trying to optimize them is practically pointless, beyond limiting their ranges to what's necessary and even then their reach only matters in screen space
  • But shadowcasting is expensive no matter what, especially for point lights
  • draw calls don't impact performance in URP if you're using SRP batching, so your assumptions about their cost may not be accurate
cyan sphinx
#

draw calls don't impact performance in URP if you're using SRP batching, so your assumptions about their cost may not be accurate

what??? 😭

#

i did not know this lol

odd knot
#

Rule of thumb is you don't have to worry about batching at all
Having different shaders between meshes is the biggest cost, but not too terrible at that
The more your objects share shaders and the more similar their materials are in keywords, the better

#

But even a "poorly" SRP batched scene is typically just fine so the effort to combine materials is questionably valuable
SRP batching reduces the cost of draw calls rather than combining them

#

But what you need is more empirical performance testing

cyan sphinx
#

awesome, thanks for all this :)
i think i may be worrying a bit too much about performance, i have pretty mid-range specs and i mean ~200 fps per room isn't too bad i guess

odd knot
#

My hunch is shadoecasting lights can be problematic even when disabled, but I guess that can vary

cyan sphinx
#

do you think i could use light cookies to emulate shadows?

#

i don't have that great of an understanding with some of this stuff, i think i just need to experiment a bit more and see what looks good (and performs well lol)

odd knot
odd knot
#

For example if you want a light that illuminates in all directions but casts shadows into the hallway
Points light shadows would be expensive and redundant, and spot light shadows become distorted and lose quality with outer angles over 90°
So there's a logical option to have a 90° shadow casting downward spot light, overlapping a shadowless point light that has a cookie that excludes the spot's cone below it

cyan sphinx
#

woah

#

thank you so much

#

i'll let ya know how it performs when im done lighting up 108 rooms 😂

cyan sphinx
#

which light should i use for a ceiling lamp like this? currently i'm just doing 2 spot lights, one pointing down, and the other pointing up at the ceiling, so it looks like indirect lighting. i'm wondering if i could do something with light cookies tho

#

actually

#

nevermind i think i have a genius idea

odd knot
odd knot
# cyan sphinx which light should i use for a ceiling lamp like this? currently i'm just doing...

That's something I've used too and it's useful for excluding shadows from the light pointing up
What I described above is the same technique but with a point light cookie instead of a spot
Spot angles don't go above 180°, but point light cookies have no such limitation so you can use one to be a 270° spot effectively for filling in for the "ideal" shadowcasting 90° spot light below it
But if shadows aren't necessary then you need just one point light and combine the spot effect and fake indirect into one cookie

odd knot
cyan sphinx
# odd knot Do share!

i forgot what it was lmao, but i think i'm gonna try making a "light cookie generator" that uses the Transform of a light to capture light cookies in the editor

cyan sphinx
#

sort of works 😂

cyan sphinx
#

adding on to this, i've added batch generating for the light cookies :D

#

i think it looks pretty good, honestly

#

i'm not sure how to fix the artifacts and weird shadows yet lol

cyan sphinx
#

pain in my ass but i added gaussian blur and metadata to the light cookies so you can easily load them into the tool

cyan sphinx
#

for point lights?

odd knot
cyan sphinx
#

i might add point lights/cubemaps to the tool; i think i'm just gonna put it on the Asset Store at this point cause this has taken me like 2 days and i think it would be a waste for me to keep this private 😭

#

there's also a ton of use cases for it, i've tried it out on spinning fans, outdoor environments, hallways, pretty much everything

odd knot
#

Automatic mipmaps you get with cubemap textures can be used for blurring by downsampling
If you get seams iirc you may need to play around with convolution and fixup edge seams settings

cyan sphinx
#

😭

#

actually it'll probably be fun

#

i've had so much fun making the GUI ngl

odd knot
cyan sphinx
#

yup, it seemed like the simplest way

#

pain in my ass

odd knot
#

The RenderToCubemap is only for producing the cubemaps
To get useful cookies out of it you need a bit of setup to build the actual cookie shape around it

cyan sphinx
#

yeah i did a bit of testing with Point lights but i hadn't added any anti-aliasing/blur methods so it looked really bad lol

#

do you know how i could fix an issue like this though? like no matter what orthographic size i do it looks strange

#

i think the first version of the renderer looked wayy better with whatever settings i had originally but i lost it 😂

#

nevermind sorry i figured it out lol

odd knot
cyan sphinx
#

whatt 😭

#

my life is ruined

odd knot
#

Or you can use them but it won't be accurate to the projection
All additional lights are punctual, meaning they project their light as well as cookies and shadow casting from a single point outward

#

90° angle spot light functionally has a 90° FoV depth camera capturing meshes for the shadowmap

#

The frame debugger can show you all the shadowmaps in action

cyan sphinx
#

OH MY GOD YOURE A GENIUS

#

i forgot that existed

odd knot
#

A point light with shadows is 6 90° FoV cameras
That's why the light cookie is the same as a cubemap which is produced by capturing a perspective image of all 6 angles that make up the imaginary cube

cyan sphinx
#

i can't believe i've been doing wrong thi swhole time

#

i'll let u know how it goes, thanks :)

odd knot
#

Perspective cameras with more than 90° FoV will start distorting the produced image though, that's why such spot lights get very bad quality shadows with shadow casting enabled

cyan sphinx
#

really? this is how it is with hard shadows; i don't think it looks horrible and its at 130°

#

i want my cookies to look like this so bad 😭

#

i'm not sure at this point lol

odd knot
odd knot
odd knot
cyan sphinx
cyan sphinx
#

i'm wondering if i can write a shader that shows the depth of objects only, and then i can capture with that instead

#

i'm sure i'll figure it out

cyan sphinx
#

i made it worse