-
-
Notifications
You must be signed in to change notification settings - Fork 97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute and store light direction information when baking lightmaps with the CPU lightmapper #3078
Comments
How would this handle multiple light sources? It sounds like you would need a normalmap for every surface and for every light source. If so, things would get very expensive very quickly. My understanding is that effects like this are using handled by baking higher-order spherical harmonics. Even then, I can see it becoming very expensive if you desire a high level of detail. |
This would store only one direction per texel, which makes it an approximation. Despite this, it can still provide good visuals as you can see in the video. If you design your lighting around these limitations, the difference between baked and real-time normal/specular may be hard to notice to the untrained eye. Xonotic (DarkPlaces) doesn't rely on spherical harmonics or anything fancy like that. It's able to do this using OpenGL 2.1 only 🙂 For reference, here's the lightmap + deluxemap (= light direction map) used in the Xonotic map featured in the video: The final deluxemap is then added (or blended?) to the surface's normal maps, which allows it to be baked at the same resolution as the lightmap itself. |
So this feature would be limited to a single light source per pixel? |
It would average the light direction from all the nearby light sources (plus the directional light, if present at that pixel). It might sound very limiting, but it's not that bad in practice. It will almost always look better than not having any directional information available, because that results in flat-looking surfaces which look unappealing. |
Not directly related but holy shit the Xonotic video blew my mind. I never thought completely baked lighting could look this good. |
I've found some more information about various lightmap directional storage methods here: https://geom.io/bakery/wiki/index.php?title=Manual#Directional_mode The one I've suggested in this proposal seems to be akin to dominant direction. Spherical harmonics are supported in |
I experimented with supporting normal maps in the The dominant direction algorithm requires a different approach (storing a secondary texture with light direction only), so the code must be redone from scratch. |
Implement support for subtractive shadowmapping or shadowmasking in DirectionalLight (for use with BakedLightmap) #2354 and
Use directional LightmapGI information to display specular lobes for fully baked (static) lights godot#63016.
Describe the project you are working on
The Godot editor 🙂
Describe the problem or limitation you are having in your project
When using BakedLightmap (LightmapGI in
master
) with lights that have their bake mode set to All, directional information is lost. This has two negative consequences:This is not as much of a problem with the default Indirect bake mode, since light direction is mostly visible for direct lighting (although it's not completely irrelevant for indirect lighting either).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Both of these issues can be alleviated by storing the baked lights' directional information in a separate texture.
Here's an example of what it looks like in Xonotic, which uses fully baked lighting (both direct and indirect light):
xonotic-lightmap-directional.mp4
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Store directional information in the form of normal maps associated to each lightmap. (I don't remember if it has to be tangent-space or object-space, but it can surely be stored with red and green channels only to reduce the storage space and VRAM required.)
Then, in the default material shader, use this directional information to influence the pixel's normal direction.
For specular lobes, we will also have to figure out a way to determine the specular reflection's origin and color. I'm not sure exactly what's the math behind it exactly, but I know that the aforementioned Xonotic can display specular lobes without requiring light entities to be present in the compiled map. It just manages to do guesswork somehow 🙂
There should be a property in BakedLightmap to disable baking directional light information for people who don't need it. This should speed up baking slightly and reduce the storage requirements, which is important when targeting mobile/web platforms.
This needs to be implemented separately for
3.x
's CPU lightmapper andmaster
's GPU lightmapper, although I think it's more important to have in3.x
first given the presence of low end-oriented renderers. Also, we already have some kind of directional lightmapping support inmaster
, but it's broken for lights that use the All bake mode: godotengine/godot#49936Note: LightmapGI in
master
has a Directional property, but it only affects indirect lighting and doesn't work correctly when a light's bake mode is set to All. It seems to be more about enabling rough reflections using spherial harmonics rather than making normal maps and specular lobes effective with baked lighting.If this enhancement will not be used often, can it be worked around with a few lines of script?
No, as the lightmapper and default scene shader need to be modified.
Is there a reason why this should be core and not an add-on in the asset library?
This is core lightmapping functionality which can't be supplied by an add-on.
The text was updated successfully, but these errors were encountered: