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

Fix LightmapGI dynamic object lighting #77089

Merged
merged 1 commit into from May 17, 2023

Conversation

DearthDev
Copy link
Contributor

fixes #57890.
potentially fixes #57131 too.

@akien-mga
Copy link
Member

The fix seems sensible looking at surrounding code, but please amend the commit message to be explicit. "fix" doesn't really cut it :)
https://github.com/godotengine/godot/blob/master/CONTRIBUTING.md#format-your-commit-messages-with-readability-in-mind

@DearthDev
Copy link
Contributor Author

Thank you for reviewing the pull request. I appreciate your feedback and have amended the commit message to provide more clarity and explicitness regarding the changes made.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I'll let @clayjohn double check as the rendering expert (especially in case this pattern of error might be found somewhere else).

@jcostello
Copy link
Contributor

I tested in my project and is not quite working.

Sphere with UVs set to dynamic
image

Sphere with UVs set to static
image

@DearthDev
Copy link
Contributor Author

Does it work if you move the object's position in the editor to force update it's lighting?

Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change looks good to me. It seems the bug was introduced by #44623 Looking at other uses of lightmap_captures makes it clear that this particular usage is reversed.

Testing locally it seems that you need to toggle the global illumination mode to make sure that the dynamic object receives dynamic lighting. So there is still something missing before we can close the linked PRs

@jcostello
Copy link
Contributor

Does it work if you move the object's position in the editor to force update it's lighting?

I move it several times and it didn't seems to be affected by the probes

@clayjohn
Copy link
Member

Does it work if you move the object's position in the editor to force update it's lighting?

I move it several times and it didn't seems to be affected by the probes

See my comment above, I think something is wrong with the pairing code as well. I found that it worked after turning the GI mode to static and then back to dynamic. Also remember to bake with probes

@jcostello
Copy link
Contributor

jcostello commented May 15, 2023

See my comment above, I think something is wrong with the pairing code as well. I found that it worked after turning the GI mode to static and then back to dynamic. Also remember to bake with probes

I already baked it with probes. I tried turning the Global Illumination mode from static to dynamic several times (dynamic still said only VoxelGI) and still I have the result of the pictures. Also I disabled and re enabled the LightmapGI node. Do I miss something?

@clayjohn
Copy link
Member

Does it work if you move the object's position in the editor to force update it's lighting?

I move it several times and it didn't seems to be affected by the probes

See my comment above, I think something is wrong with the pairing code as well. I found that it worked after turning the GI mode to static and then back to dynamic. Also remember to bake with probes

I already baked it with probes. I tried turning the Global Illumination mode from static to dynamic several times (dynamic still said only VoxelGI) and still I have the result of the pictures. Also I disabled and re enabled the LightmapGI node. Do I miss something?

I found that hiding the LightmapGI node broke the pairing. For some reason the LightmapGI node isn't properly propagating the dirty flag to GeometryInstances.

@DearthDev
Copy link
Contributor Author

DearthDev commented May 15, 2023

I already baked it with probes. I tried turning the Global Illumination mode from static to dynamic several times (dynamic still said only VoxelGI) and still I have the result of the pictures. Also I disabled and re enabled the LightmapGI node. Do I miss something?

If you save the scene and reopen it will that get them to pair? I can't reproduce your issue. I'll look into fixing the pairing issue in a separate PR.

@jcostello
Copy link
Contributor

jcostello commented May 15, 2023

If you save the scene and reopen it will that get them to pair? I can't reproduce your issue. I'll look into fixing the pairing issue in a separate PR.

I can push my project so you can check the issue

@jcostello
Copy link
Contributor

@DearthDev https://github.com/jcostello/SponzaHD

Here you are

@Calinou
Copy link
Member

Calinou commented May 15, 2023

PS: Please do not nest quotes in replies as it makes the thread difficult to read. Only quote the exact text you are replying to. (Unfortunately, GitHub won't do this for you, so you have to edit the quoted text manually.)

@DearthDev
Copy link
Contributor Author

@DearthDev https://github.com/jcostello/SponzaHD

Here you are

Upon reviewing the code in the debugger, everything appeared to be functioning properly. To troubleshoot the issue, I attempted to rebuild the light map. Subsequently, my screen displayed unexpected behavior and the Godot became unresponsive.

1

After realizing that there were errors related to VoxelGI in the scene, I suspected that the scene might have been corrupted or damaged. Again, I think it's an issue with pairing. Then, I tried creating a new scene and baking a lightmap with all the same meshes. The dynamic lighting worked perfectly, However, I did observe some visual errors, which I attributed to the process of copying the directional light and world environment from the previous scene. It seemed that some settings in the world environment or camera attributes, such as exposure, were causing issues.

2

The visual errors are unrelated to lightmap captures and resetting all the world environment settings and camera attributes settings fix all the visual errors.

@jcostello
Copy link
Contributor

@DearthDev have you been able to get lighting from the probes?

@DearthDev
Copy link
Contributor Author

DearthDev commented May 16, 2023

@DearthDev have you been able to get lighting from the probes?

Yes, after making the new scene it worked fine.

@jcostello
Copy link
Contributor

@DearthDev I recreated the scene and I notice the problem might be with reflection probes. I can't figure it out but when reflection probes are enabled in order for a dynamic mesh to have the lightmap probes light I have to enable the mesh first before the reflection probes. Can you try that?

@jcostello
Copy link
Contributor

jcostello commented May 16, 2023

When playing the scene, objects are not receiving dynamic light (No reflection probe in this case to avoid the issue above)

Edit: Moving the object after lauching the game applies the dynamic but if the object doesn't move at all it will receive no light until moves. It should be applied even if the object didn't move yet

Playing
Screenshot from 2023-05-16 09-38-48

Editor
Screenshot from 2023-05-16 09-39-02

@jcostello
Copy link
Contributor

I tried it on the TPS demo and in some cases it samples from the invalid probes inside meshes. We should avoid those probes

Close invalid probe
image

Far from invalid probe
image

@jcostello
Copy link
Contributor

scene/3d/lightmap_gi.cpp:558 - Inconsistency found in triangulation while building BSP, probe interpolation quality may degrade a bit.

Message while baking. IDK if its relevant

@DearthDev
Copy link
Contributor Author

I've ran into that error in my personal projects.
Should these be opened as issues?

We know:

  1. LightmapSH and geom isn't getting paired upon baking
  2. Inconsistency found in triangulation while building BSP error
  3. Invalid probes

@jcostello
Copy link
Contributor

jcostello commented May 16, 2023

I've ran into that error in my personal projects. Should these be opened as issues?

We know:

  1. LightmapSH and geom isn't getting paired upon baking
  2. Inconsistency found in triangulation while building BSP error
  3. Invalid probes

To me, those issues are related to this preventing dynamic light to work so could be fix on this PR. But lets hear @Calinou opinion

@clayjohn
Copy link
Member

My preference is to create the 3 suggested issues then merge this as-is. We shouldn't block a perfectly good bug fix just because it doesn't fix all bugs with the feature it touches. That is too much to expect from a contributor

@DearthDev
Copy link
Contributor Author

My preference is to create the 3 suggested issues then merge this as-is. We shouldn't block a perfectly good bug fix just because it doesn't fix all bugs with the feature it touches. That is too much to expect from a contributor

I agree and then we can have any discussion pertaining to each issue separately.

@akien-mga akien-mga merged commit b42cea1 into godotengine:master May 17, 2023
13 checks passed
@akien-mga
Copy link
Member

akien-mga commented May 17, 2023

Thanks! And congrats for your first merged Godot contribution 🎉

@jcostello
Copy link
Contributor

Congratz @DearthDev 😄

BTW can you create the issues for

  1. LightmapSH and geom isn't getting paired upon baking
  2. Inconsistency found in triangulation while building BSP error

I will create for the invalid probes that I have more information about it

@YuriSizov
Copy link
Contributor

Cherry-picked for 4.0.4.

@YuriSizov YuriSizov changed the title LightmapGI dynamic object lighting fix Fix LightmapGI dynamic object lighting Jul 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants