-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
[3.2] Add new CPU lightmapper #40035
Conversation
Looks great! did you get to take a look to the probe code in 4.0? I would just backport that directly and not keep compatibility |
Does this new lightmapper take environment lighting into account? If so, this would fix #16398. |
@Calinou It can be enabled, yes :) |
Preliminary look (and after discussing a bit with jfons):
Overall I liked it. Sure there were a number of features I'd like to see added, but there is good reason to get it available as soon as possible, then more features can be added as needed. Once the basic framework is working it should be fairly easy to tweak / add new features. Some ideas:
|
Unlike in the It might be possible to backport the light In the worst case, we could support the light
Out of curiosity, what are the tradeoffs of this method compared to the current backward method? |
Using several lights is a pretty messy solution - as it is better to have something that is easy to edit, and lightmaps can give high quality results, there's no need to restrict them to something similar to PCF shadows. In my toy lightmapper at the moment I'm simply using the light scale to determine light volume, simple with omnis, and also for spotlights for the source volume. I don't know whether this interferes with anything else light wise (can't check this as I'm away from home this week). I'm also planning to simply use light names to distinguish between some extra light types such as orientated bounding box or sphere / ellipse, light from volume or just from the shape surface. For core we could consider some special extra tags for lights to specify all this kind of stuff instead of bodging it. There was also a proposal about simulating complex light shapes on godot proposals (can't look up at the moment) that might be worth considering. Or alternatively just have it support emissive material so that any shape can be a light source.. maybe it can do this already I didn't test. That might be more tricky to mix lightmaps with realtime lighting though.
This is kind of what I'm doing at the moment and it seems to work fine (haven't tried any huge area lights though).
Backward tracing is often used because it tends to be more efficient - however that advantage is partly based on the idea of a view being taken from a camera. A lot of rays won't make it into the camera view so it makes a lot of sense to start by only considering things in view. With a lightmap this is less relevant, in a lot of scenes nearly all the rays from lights will hit something. However with backward tracing you have the advantage that each texel can get equal consideration in terms of number of samples, which tends towards less noise (particularly with later bounces maybe?). Forward tracing also has the possibility of scaling a lot better in large levels, or complex levels. With backward tracing, there is a very real possibility that a lot of texels will spend a large proportion of time tracing to lights that cannot possibly influence them. With forward tracing areas in shadow are not considered. Also areas at a large distance from the light will automatically spend proportionately less of the processing time. I'm not an expert by any means, I found that forward tracing was easier to make artifact free and is closer to 'physically correct' out of the box. With backward tracing you have to make assumptions based on the area of a texel in view of a light, whereas with forward tracing, this happen automagically. With forward tracing there's no need to consider distance to light source, or angle, as falloff and variation depending on surface normal happen automatically. Also with backward tracing there's a number of situations that can give rise to artifacts, consider when a texel has one or multiple cutting planes that may prevent light hitting part of the texel. Some other methods are bidirectional ray tracing and metropolis light transport. These kinds of things are easy to play around with when the main framework is setup for ray tracing / exporting lightmaps etc. |
Judging by the screenshots, this is already supported 🙂
reduz once mentioned adding the ability to specify a "start angle" for SpotLight3D, which would make it possible to create cylinder-shaped lights (as opposed to cone-shaped lights). |
@RandomShaper and I are working on an update to this PR. @RandomShaper added texture atlassing and I added some fixes to the light transport computation. Here's a test scene in case someone wants to try it out :) |
Got the emission working, and I can confirm you can get soft shadows with emissive materials 👍 . So just not with the lights at the moment it seems. For emission to work BTW, you need 1 or more bounces, it won't light anything in the first pass, that caught me out, and the emitting mesh needs to have secondary UVs. Also the emitting mesh has to be in the baked lightmap volume. There are some slight artifacts here but these might be due to padding or not enough texel density. Edit: It looks like the artifacts were from not enough samples. Turning off the denoiser showed this. I think realistically to get rid of these you need high or ultra high quality set. This is with ultra high, 1 bounce, took a couple of mins, looking a lot nicer: 😄 These are jaggies from normal lights, which are rather objectionable so casting multiple rays from a light volume would probably be good to get working: |
@lawnjelly We should look at adding bicubic sampling support when using GLES3. For those using GLES2 (where bicubic sampling might not be possible), we could add an option to supersample the lightmap baking by a 2× factor. This would make lightmaps much slower to bake (so you'd only enable it for final bakes), but this would avoid adding any run-time performance cost. Bicubic sampling is already supported in the |
The jaggies here aren't a filtering issue I don't think. There is a limit to the resolution of the lightmap, so I think it's much easier (and cheaper) to fix it in the lightmap. |
Updated the PR:
Here's an updated test scene, the one I posted before had weird normals on the walls and ceiling: |
I just tried to build the branch on windows but got the following compilation error:
Is there anything special I should be doing for this branch? |
@JFonS you should use |
They will be deleted when the faces are merged, but their edges are needed for merging faces.
colliding with equiplanar CSG faces.
- Fixed file not closed after loading (made future imports in the same session fail) - Fixed saving of lossless (if format not suiable for PNG it forcefully sets it to uncompressed, but that was being done too late, after the value had already been written) - Fixed reload-from-file (involved refactoring loading code from its resource loader class to the class iself, much like how StreamTexture works)
- Use of M_PI. - Better texels-per-unit default and range. - Prevent potential crashes. - Fix unwrap cache file kept open.
Bonus: - On new bakes of the same mesh, touch the import settings file intact only to change what is needed for the new bake setup (namely, don't overwrite texture compression mode).
Just tried the latest and it does build for me now. I loaded up a project I have the relies heavily on the existing lightmapper implementation (but has many problems with it) and tried to bake my scenes using the new light mapper: It appears that Gridmaps are currently not being considered in the new baking process? Most of my scene's geometry lives inside grid maps, none of which gets baked it appears, however a few things in my scenes are just instanced geometry, and those do indeed get baked (and they look good so far!) |
I like that you can now enable/disable the capture data, however it does seem to be similar to the old lightmapper in that the capture data is HUGE! Is one of the goals here to replace the capture data with something like the light probe system in 4.0? I assume that would greatly reduce the binary sizes required, but I suppose that is mostly just an assumption. My test scene (TSCN) went from 5MB to 50MB by enabling capture data with the new Lightmapper. SCN does shrink this by a lot, but this test scene is small. My actual scenes which are all SCNs still come in at almost 100MB (with the old light mapper), the majority of that coming from the Lightmap capture data I believe. If that's not part of this though rewrite, that's totally understandable! |
Never save BakedLightmapData or GIProbe data to a text-based file, as it'll be converted to Base64. You should always save it to a Godot 4.0 will do this for you automatically, but I'm not sure if we can backport that behavior. |
I did some digging, and it looks like a big part of my file size bloat is from using Baked Lightmaps in conjunction with GridMaps: Not sure if a different approach can be used for this new Light mapper when dealing with Gridmaps, or even if a very different approach is even possible for gridmaps, but thought I'd highlight it here in case it could be addressed as part of this. |
It would be pretty great to have an option to save the actual lightmap images on disk as WEBP in order to save disk space. @Calinou mentioned that there might be some load time impact to this, but it might be worth it for some use cases.
|
I've just discovered something which is a giant pain as far as using light scale to determine light volume in the light mapping. Lights have So strangely you can set scale on a light, and use it to determine volume, but the moment you move the light in the editor, it resets the scale to 1.0. This may have been to avoid some problem in regular light use (the direction does become invalid at 0.0 scale, presumably because the basis is zero length). So either re-enabling scale for lights might be needed , or perhaps better still some extra light parameters specifically for lightmapping (and perhaps other GI?). Scale was handy because being an x, y, z it enables you to quickly create long thin lights for example. Blender I seem to remember can use light scale for volume. Emissive materials gives the most versatility in terms of shape, but has the major disadvantage it doesn't work as a realtime shadow mapped light (although it might work with e.g. GI probe, but that is defeating the object of using baked lighting). It can show the light with light probes, but no shadows. Perhaps a dedicated section in the inspector for lights for the baking properties might be an idea then. You could then as well as specifying e.g. an xyz orientated bounding box volume that rotated with the light, you could have more info for the type of light, such as box or sphere, solid, hollow etc. |
@JFonS |
I was talking to jfons about this the other day, he is hoping to get it in time for Godot 3.2.4 Beta 2. there isnt much progress being reflected here as he is working on a separate branch. |
Got it, thanks for the clarification. |
Note that the CPU lightmapper merge is being pushed back to 3.2.4beta3 to allow jfons to make it more polished. IRC log:
|
@dedm0zaj Please upload a minimal reproduction project to make this easier to troubleshoot. |
@hoontee I don't use GIProbe for two reasons:
|
Closing as superseded by #44628. |
Implement a new path-traced CPU lightmapper.
Partially sponsored by Google (GSoC).
Partially sponsored by IMVU.
Partially sponsored by my own free time.
This new lightmapper should give far better results than the current one. See the exact same scene fully lightmapped (direct and indirect light) using the current lightmapper in both modes and the new path-traced one:
I tried to keep the BakedLightmap properties as similar to the 4.0 ones as possible, to keep compatibility as much as possible.
Also added caching to mesh unwrapping to speed up import time and keep unwraps consistent across imports.
Still missing some work on documenting the Embree version used and the changes made to the official version.
Bugsquad edit: This closes #15055, closes #16820, closes #16398, closes #20321, closes #21587, closes #30789, closes #30929, closes #32746, closes #38685, closes #39532.