Skip to content
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

GPULightmapper leaks light in situations where the CPU lightmapper wouldn't #51638

Closed
jcostello opened this issue Aug 13, 2021 · 25 comments · Fixed by #52618
Closed

GPULightmapper leaks light in situations where the CPU lightmapper wouldn't #51638

jcostello opened this issue Aug 13, 2021 · 25 comments · Fixed by #52618

Comments

@jcostello
Copy link
Contributor

Godot version

v4.0.dev.calinou [6f043f7]

System information

Mx Linux (Debian Based)

Issue description

The lightmapper leaks even with thick walls.

image

Steps to reproduce

Use the minimal reproduction project and bake the lightmap

Minimal reproduction project

GPULightmapLeak.zip

@Calinou Calinou changed the title GPULightmapper leaks GPULightmapper leaks light in situations where the CPU lightmapper wouldn't Aug 13, 2021
@Calinou Calinou added this to the 4.0 milestone Aug 13, 2021
@JFonS
Copy link
Contributor

JFonS commented Aug 17, 2021

I did some testing on this, direct light seems to be correct and without leaks, but the first bounce breaks a number of things. I'm still not sure why. It may be some weird geometry or maybe something is wrong in the way we handle hits against backfaces, but there's definitely something going on that needs more investigation.

@jcostello
Copy link
Contributor Author

I test it out with a simpler geometry (a cube with thick walls and a window, all conected) and the bleeding still happens

@williamd67
Copy link
Contributor

williamd67 commented Sep 11, 2021

I found one issue that GPULightmapper's triangles and bounding-boxes arrays became out-of-sync. This causes issues when the incorrect bounding-boxes were used to test the triangle in trace_ray. I fixed that issue in #52570. This does not fix the leaking, yet it does improves some other side-effects.

Before

Screenshot from 2021-09-11 12-51-39
Screenshot from 2021-09-11 12-55-12

After

Screenshot from 2021-09-11 13-01-22
Screenshot from 2021-09-11 12-58-53
Screenshot from 2021-09-11 13-01-49

@jcostello
Copy link
Contributor Author

Nice, it improved the other side effects. Any idea why the leaking might happen? I suspect that is because the UVs because even if you bake lighting around 2 boxes, the seams got some leaks

@williamd67
Copy link
Contributor

I found another issue: rays that hit back-face triangles where counted in the bounce lighting calculations. Normally this was not the case, except for edges of planes where rays can get 'behind' the scene. This is fixed in #52618.

This did not solve the leaking completely, yet I found another setting that combined with this back-face exclusion fixed it. Changing the Lightmap Scale of the Global Illumination of the Hut-mesh from 1x to 2x removed all the leakage. Also to get a better effect I recommend to change the lightmap quality to high.

After

Screenshot from 2021-09-13 00-01-39
Screenshot from 2021-09-12 23-42-25

@jcostello
Copy link
Contributor Author

I tried a similar model in Unity and I found that intercepting geometry is not well handled so as you said, scaling the mesh in the lightmap helped in Unity too. I tried it on Godot and helped but still and issue where the seams meet. So upscaling the mesh in the lightmap helps with intercepting geometry but still an issue with the seams.
In your after you can still see artifacts in the edges of the cube and in the room's corner.

@jcostello
Copy link
Contributor Author

One thing we can try is to have a cube with custom uv2 and with generated uv2s. The custom uv2 should have the problem only where the T seams meet. The generated uv2 will have in all the edges due to have every face with seems

@williamd67
Copy link
Contributor

williamd67 commented Sep 13, 2021

In your after you can still see artifacts in the edges of the cube and in the room's corner.

Just to be sure, I have two fixes and two afters. In the second fix I do not notice an issue (lightmap is scaled 2x). Although when you use 1x it show issues more clearly. I plan to investigate further.

@jcostello
Copy link
Contributor Author

Yes. Just to clarify, let me point out where I see the artifacts

Edge of the box
image

Corner of the room.
image

If you need I can create another scenario to point this issues better

@williamd67
Copy link
Contributor

I will have a look and another scenario might help. As you mentioned this could be related to the seaming phase which I did not investigate yet.

@williamd67
Copy link
Contributor

I think the original issue where light is leaking through edges is fixed by #52618. I will continue to investigate the other artifacts that have been mentioned.

@JFonS
Copy link
Contributor

JFonS commented Sep 20, 2021

I haven't followed the issue too closely, but the work by @williamd67 should help get rid of all the obvious leaks. @jcostello did you have a chance to test #52618?

Something that isn't clear to me yet is whether the UV2s are imported along with the model or generated by Godot at import. Keep in mind that the various UV2 islands need to be separated by at least a 2 pixel gap, otherwise there's nothing the lightmapper can do to prevent light leaks due to bilinear filtering. Godot's unrwapper should already handle this, but we don't have any way to enforce this for imported UV2s.

@jcostello
Copy link
Contributor Author

At first wtih #52618 I see new artifacts in this PR. I will create 2 more specific scenarios to upload so you guys can try

@JFonS @williamd67

image

@jcostello
Copy link
Contributor Author

@JFonS @williamd67 I created 4 cases where I see problems with the light mapper. Here is the project you can see each case in the scene folder.

https://drive.google.com/file/d/1XbWk4HVYI-fH7PyzetGVKmUQ8O5VoEOq/view?usp=sharing

Test1.tscn - Hollow cube (solid) with omni light on it.
image
Seems that the leaks are not occurring but there is a shadow on the seams. Its an intended AO?

Test2.tscn - Cubes with spotlight
image
Dark spot in the middle cube (causes by the last bounce?). Also white light in the edges.

image
When moving the camera, a white square appears in the left cube's corner. Maybe not related with the lightmapper.

Test3.tscn - Hut model with omnilight in it.
This model has a lot of intersecting geometry. Not the best geometry but it will happen in games and some issues should be fixed.

image
Darker square inside the hut.

image
Artifacts outside when using x8 in the mesh scale inside the lightmap and medium quality in the lightmap node

Test4.tscn - complex model
image
Leaking thought the model (doesn't seems to be a bounce)

@williamd67
Copy link
Contributor

Thanks @jcostello, this is exactly what I need to test more and further. I will take your model and try to find and fix the issues (or explain why they happen).

@jcostello
Copy link
Contributor Author

@williamd67 no problem. Let me know if I can help you testing your progress in any way 💪

@akien-mga akien-mga reopened this Sep 22, 2021
@jcostello
Copy link
Contributor Author

I retested this on master and seems that most of the things were fixed. Maybe I downloaded your PR @williamd67 but I didn't change the branch.

Anyway with the first test case, when baking at medium quality (3 bounces, mesh x1) the strange AO disappear (which is how it would work)

image

But baking it at ultru (3 bounces, mesh x1) it has an strange blob.

image

Happens the same with x1, x2, x4 and x8 in the mesh size.

@jcostello
Copy link
Contributor Author

With the hut example. The inside looks good as it should the outside still looks with artifacts but its fixed if baked at ultra.

Medium
image

Ultra
image

@jcostello
Copy link
Contributor Author

scene 4 still have leaks but provably its because the geometry of the mesh

image

@williamd67
Copy link
Contributor

I found that the background color leaked, which I fixed in #53081. This PR fixes the test1.scn which still showed some background color leaking when there is no dynamic light.

This PR will not solve the other issues you found. I will continue to investigate those.

@jcostello
Copy link
Contributor Author

Awesome. Great job @williamd67 . You are the man

@williamd67
Copy link
Contributor

The above PR fixes the blob in scene 1 (baking at ultra, 3 bounces, 1x mesh).

@JFonS
Copy link
Contributor

JFonS commented Oct 19, 2021

I think all the reported problems were addressed, so this issue can be closed.

@williamd67 Great job tracking down and fixing all those issues :) If you want to keep improving the GPU now that you are familiar with it, I can think of a couple of improvements that may be interesting to you. The first one would be to add soft shadow support for direct lights, similar to what was done in #50184 but for the GPU lightmapper. The other one would be to improve performance a bit by adding adaptive sampling support.

@JFonS JFonS closed this as completed Oct 19, 2021
@jcostello
Copy link
Contributor Author

@JFonS adding a few things to the list that would be good to check out and fix

#49936
#53770
#53436

and a few proposals that would be really necesary for lightmaps

godotengine/godot-proposals#3213
godotengine/godot-proposals#3233

@williamd67
Copy link
Contributor

@JFonS, sure I like to improve it further. I will start by investigating the issues mentioned by @jcostello. After that I will look at the proposals.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants