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

Add support for saving lightmap as multiple images #61861

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

techiepriyansh
Copy link
Contributor

@techiepriyansh techiepriyansh commented Jun 9, 2022

master port of #58102.

Needs to be tested on a really large scene for the "roll-over to multiple textures" limit to be reached. I have only tested by hardcoding slices_per_texture = 1, but in theory, should work just fine for the general case too.

Also, currently there is lightmap texture data duplication as both the individual textures and the combined texture co-exist. Need to figure out a way around it. (This only happens when the texture data cannot be contained in a single Image; so no overhead until the roll-over limit is reached).

@techiepriyansh techiepriyansh requested a review from a team as a code owner June 9, 2022 20:04
@Chaosus Chaosus added this to the 4.0 milestone Jun 9, 2022
@Calinou
Copy link
Member

Calinou commented Jun 9, 2022

I tested this PR on #54679 and it doesn't fix the crash encountered when baking lightmaps, even after setting the maximum texture size to 8192. I suppose this doesn't work on that MRP since it only uses a single large mesh, as opposed to several smaller meshes.

That said, the original crash may be better fixed by using int64_t where it's relevant in Image.

@techiepriyansh
Copy link
Contributor Author

Can you please attach the backtrace of the crash?

@Calinou
Copy link
Member

Calinou commented Jun 9, 2022

Can you please attach the backtrace of the crash?

It's slightly different from the one listed in #54679, but I had a similar backtrace with a master build from today.

================================================================
handle_crash: Program crashed with signal 4
Engine version: Godot Engine v4.0.alpha.custom_build (17a7447dbe502ad7b8ea672ae59f320a9a991e35)
Dumping the backtrace. Please include this when reporting the bug on https://github.com/godotengine/godot/issues
[1] /lib64/libc.so.6(+0x42a70) [0x7fa849ee2a70] (??:0)
[2] CowData<Ref<Image> >::get(int) const (/home/hugo/Documents/Git/godotengine/godot/./core/templates/cowdata.h:156)
[3] Vector<Ref<Image> >::operator[](int) const (/home/hugo/Documents/Git/godotengine/godot/./core/templates/vector.h:92)
[4] LightmapGI::bake(Node*, String, bool (*)(float, String const&, void*, bool), void*) (/home/hugo/Documents/Git/godotengine/godot/scene/3d/lightmap_gi.cpp:1014)
[5] LightmapGIEditorPlugin::_bake_select_file(String const&) (/home/hugo/Documents/Git/godotengine/godot/editor/plugins/lightmap_gi_editor_plugin.cpp:43)
[6] void call_with_variant_args_helper<LightmapGIEditorPlugin, String const&, 0ul>(LightmapGIEditorPlugin*, void (LightmapGIEditorPlugin::*)(String const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:236)
[7] void call_with_variant_args<LightmapGIEditorPlugin, String const&>(LightmapGIEditorPlugin*, void (LightmapGIEditorPlugin::*)(String const&), Variant const**, int, Callable::CallError&) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:351)
[8] CallableCustomMethodPointer<LightmapGIEditorPlugin, String const&>::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/./core/object/callable_method_pointer.h:105)
[9] Callable::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/core/variant/callable.cpp:51)
[10] Object::emit_signalp(StringName const&, Variant const**, int) (/home/hugo/Documents/Git/godotengine/godot/core/object/object.cpp:1119)
[11] Error Object::emit_signal<String>(StringName const&, String) (/home/hugo/Documents/Git/godotengine/godot/./core/object/object.h:773)
[12] EditorFileDialog::_action_pressed() (/home/hugo/Documents/Git/godotengine/godot/editor/editor_file_dialog.cpp:487)
[13] EditorFileDialog::_file_submitted(String const&) (/home/hugo/Documents/Git/godotengine/godot/editor/editor_file_dialog.cpp:251)
[14] void call_with_variant_args_helper<EditorFileDialog, String const&, 0ul>(EditorFileDialog*, void (EditorFileDialog::*)(String const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:236)
[15] void call_with_variant_args<EditorFileDialog, String const&>(EditorFileDialog*, void (EditorFileDialog::*)(String const&), Variant const**, int, Callable::CallError&) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:351)
[16] CallableCustomMethodPointer<EditorFileDialog, String const&>::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/./core/object/callable_method_pointer.h:105)
[17] Callable::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/core/variant/callable.cpp:51)
[18] Object::emit_signalp(StringName const&, Variant const**, int) (/home/hugo/Documents/Git/godotengine/godot/core/object/object.cpp:1119)
[19] Error Object::emit_signal<String>(StringName const&, String) (/home/hugo/Documents/Git/godotengine/godot/./core/object/object.h:773)
[20] LineEdit::gui_input(Ref<InputEvent> const&) (/home/hugo/Documents/Git/godotengine/godot/scene/gui/line_edit.cpp:461)
[21] Control::_call_gui_input(Ref<InputEvent> const&) (/home/hugo/Documents/Git/godotengine/godot/scene/gui/control.cpp:940)
[22] Viewport::_gui_input_event(Ref<InputEvent>) (/home/hugo/Documents/Git/godotengine/godot/scene/main/viewport.cpp:1995)
[23] Viewport::push_input(Ref<InputEvent> const&, bool) (/home/hugo/Documents/Git/godotengine/godot/scene/main/viewport.cpp:2741)
[24] Window::_window_input(Ref<InputEvent> const&) (/home/hugo/Documents/Git/godotengine/godot/scene/main/window.cpp:973)
[25] void call_with_variant_args_helper<Window, Ref<InputEvent> const&, 0ul>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, Callable::CallError&, IndexSequence<0ul>) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:236)
[26] void call_with_variant_args<Window, Ref<InputEvent> const&>(Window*, void (Window::*)(Ref<InputEvent> const&), Variant const**, int, Callable::CallError&) (/home/hugo/Documents/Git/godotengine/godot/./core/variant/binder_common.h:351)
[27] CallableCustomMethodPointer<Window, Ref<InputEvent> const&>::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/./core/object/callable_method_pointer.h:105)
[28] Callable::call(Variant const**, int, Variant&, Callable::CallError&) const (/home/hugo/Documents/Git/godotengine/godot/core/variant/callable.cpp:51)
[29] DisplayServerX11::_dispatch_input_event(Ref<InputEvent> const&) (/home/hugo/Documents/Git/godotengine/godot/platform/linuxbsd/display_server_x11.cpp:3136)
[30] DisplayServerX11::_dispatch_input_events(Ref<InputEvent> const&) (/home/hugo/Documents/Git/godotengine/godot/platform/linuxbsd/display_server_x11.cpp:3108)
[31] Input::_parse_input_event_impl(Ref<InputEvent> const&, bool) (/home/hugo/Documents/Git/godotengine/godot/core/input/input.cpp:662)
[32] Input::flush_buffered_events() (/home/hugo/Documents/Git/godotengine/godot/core/input/input.cpp:887)
[33] DisplayServerX11::process_events() (/home/hugo/Documents/Git/godotengine/godot/platform/linuxbsd/display_server_x11.cpp:4117)
[34] OS_LinuxBSD::run() (/home/hugo/Documents/Git/godotengine/godot/platform/linuxbsd/os_linuxbsd.cpp:437)
[35] bin/godot.linuxbsd.tools.64.llvm(main+0x1c0) [0x4277fb0] (/home/hugo/Documents/Git/godotengine/godot/platform/linuxbsd/godot_linuxbsd.cpp:68)
[36] /lib64/libc.so.6(+0x2d590) [0x7fa849ecd590] (??:0)
[37] /lib64/libc.so.6(__libc_start_main+0x89) [0x7fa849ecd649] (??:0)
[38] bin/godot.linuxbsd.tools.64.llvm(_start+0x25) [0x4277d25] (??:?)
-- END OF BACKTRACE --
================================================================
[1]    21845 IOT instruction (core dumped)  bin/godot.linuxbsd.tools.64.llvm ~/Downloads/global_illumination/project.godo

@mrjustaguy
Copy link
Contributor

This would close godotengine/godot-proposals#3734

Copy link
Contributor

@JFonS JFonS left a comment

Choose a reason for hiding this comment

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

Looks great, really clean implementation. I did some testing and everything is working as expected.

scene/3d/lightmap_gi.cpp Outdated Show resolved Hide resolved
@techiepriyansh techiepriyansh changed the title [WIP] Add support for saving lightmap as multiple images Add support for saving lightmap as multiple images Jun 14, 2022
@akien-mga akien-mga merged commit d845d69 into godotengine:master Jun 14, 2022
@akien-mga
Copy link
Member

Thanks!

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

Successfully merging this pull request may close these issues.

6 participants