-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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 not working with MultiMeshes #97755
base: master
Are you sure you want to change the base?
Conversation
9e5c9a5
to
e754253
Compare
An easy alternative way to fix this would be to add a get_bake_mesh that returns the result in the correct order. I'm not sure what is best. It would duplicate a lot of get_meshes, which was the primary reason I just added an arg with a default value that preserves the old behavior but allows swapping for this use. |
It wasn't clear to me if we want to be doing more of the work related to UV2 that is done for normal meshes or not. |
There is still something wrong. The multi mesh seems to be getting dynamic shadows where the mesh instances are not. Will investigate further. |
scene/3d/lightmap_gi.cpp
Outdated
if (multi_mesh) { | ||
// By default, get_meshes returns an Array with the transform first where the code | ||
// below expects the mesh first. Request the order swapped so baking works. | ||
bmeshes = multi_mesh->get_meshes(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of passing a parameter to get_meshes, I would just swap the order here. Since this function is the one with unique expectations, its better to keep the complexity here, instead of spreading it to MultiMeshInstance
There is code to register the Lightmap with a MeshInstance when the Lightmap is loaded. That is probably missing MultiMeshInstances. I would start by looking here and making sure the lightmap is registered properly: godot/scene/3d/lightmap_gi.cpp Line 1386 in 5ccbf6e
|
Yeah, doing this has stopped the dynamic shadows but still not working entirely. I think is a problem where its not using the lightmap possibly because something is missing to tell it to use UV2. Still investigating what is going wrong. I tried looking at gridmap but it seems entirely broken for lightmap_gi as well for similar reasons. |
This message was pasted to the rocket chat thread. Pasting here in-case its helpful for others. I did a bit of investigation with gridmaps and I don't think this can be implemented like gridmaps. Gridmaps do have some uses of multimesh in the code, but it hardly used at all, especially for lightmaps. Everytime i've followed how grid map does it, you just get duplicate geometry. This is because gridmap spawns meshs when you bake the meshes. I have a branch which does not use multimesh at all here (gridmap-no-multimesh). This branch won't display anything when editted, until you bake lightmaps. When it makes the baked meshes, it spawns new meshes. You can see the place this mostly happens here(gridmap mesh instancing). It also does some of this elsewhere to update. Its unclear to me where the multimesh stops drawing but it does. This was further confirmed by instrumenting the code and using the debugger. In the state mentioned above where the grid doesn't have baked meshes(and it doesn't show things properly), the multimesh is used and you can see it being drawed(assuming you're not on my no multimesh branch), but as soon as you bake meshes, it stops and instead you are only drawing mesh(s) made during baking linked above. Here is an image from my no multi-mesh branch showing that it still renders and with working lightmaps: |
aff7cb4
to
7d6a677
Compare
@Calinou, I think I have fixed the issue you hit plus a few others as well (motion vectors where not being handle properly after I had cleaned up code). I had thought those dark cubes were a problem but I believe they just have basically a negative scale so they are inside out. Non-lightmap lighting is also dark on them. You'll want to re-import the the MRP project though. The main defect was a buffer copy which still had an offset (from one of the way I tried implement this) which resulted in no the entire buffer being copied which may have resulted in the project not saving the transforms correctly. I also added menu items to view uv1/uv2 plus unwrap for lightmap since it was frustrating not having them. The code is mostly copy pasted from mesh_instance_3d. Not idea but it definitely improves the work flow. This bit could always be strip out to its own PR or maybe some common class both could use. |
9252a8d
to
ab6eda9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected in all rendering methods. Code looks good to me at a glance (other than the style changes I requested above).
44dcdea
to
ffa8161
Compare
69bb5de
to
a45a539
Compare
super excited for this! awesome work |
3daf730
to
8428a2c
Compare
Resolves #56027
This commit adds support for calling get_meshes on the multimesh_instance_3d. The order of the transform and mesh differs from get_bake_meshes from gridmap so swap the other so they match. This appears to fix the issue.
This fixes uses the attempt from #56027 (comment) but fixes the ordering in the return so the bake works correctly.