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

Generate UV2 and define a lightmap size hint to allow lightmap baking #15

Open
Calinou opened this issue May 2, 2023 · 7 comments
Open

Comments

@Calinou
Copy link
Contributor

Calinou commented May 2, 2023

Currently, lightmaps can't be baked on a Cyclops level (although VoxelGI, SDFGI and ReflectionProbe all work as expected). This is because no UV2 is generated for the shapes, and no lightmap size hint is set for the meshes either.

Godot doesn't expose xatlas (which is internally used to create UV2 for imported 3D scenes), so a custom method must be used here. Fortunately, shapes are usually quite simple and guaranteed to be convex, so this should be less complex than xatlas.

A lightmap scale project setting or CyclopsGlobalScene node should also be added to control the lightmap size multiplier. This can be used to make lightmaps more detailed or more coarse, depending your needs (in terms of bake times and file size).

blackears added a commit that referenced this issue May 7, 2023
…ping to see if it works with that.

#15

Also fixing bug that returns incorrect occluder vertex indices introduced by shift to using face-vertex indexing.
@blackears
Copy link
Owner

The latest head should have code that generates lightmap coordinates on UV2, but I can't get lightmapping to work in Godot. Not just for Cyclops, but even with ordinary mesh objects. Could you test to see if lightmap generation is working?

@Calinou
Copy link
Contributor Author

Calinou commented May 8, 2023

Could you test to see if lightmap generation is working?

I can get lightmapping to work in the following scene with only primitive meshes in 4.0.2: test_lightmap.zip

Make sure to use the Forward+ rendering method, as baking lightmaps with the Compatibility rendering method is not supported and lightmap sampling is broken in the Forward Mobile rendering method. Also, if using primitive meshes like I did in the test project, you'll have to enable Add UV2 in the PrimitiveMesh inspector.

@blackears
Copy link
Owner

Looks like LightmapGI only works in Forward+ mode. I'm using ImmediateMesh to generate the geometry, so I don't think the UV2 layer needs to be explicitly enabled. I'm not sure what to specify for lightmap_size_hint. It looks like the lightmap system uses a default if you leave it blank, so maybe that's good enough?

@blackears
Copy link
Owner

I was able to get your test scene to work. Looks like I can only use Forward+ to generate lightmapGI data.

I don't seem to be able to bake with my blocks, though. I'm getting an error that says No meshes to bake. Make sure they contain an UV2 channel and that the 'Bake Light' flag is on. I can't find a Bake Light flag anywhere and I'm sure that the UV2s are there. Is this a problem with ImmediateMesh? Should I try an ArrayMesh?

@Calinou
Copy link
Contributor Author

Calinou commented May 9, 2023

Is this a problem with ImmediateMesh? Should I try an ArrayMesh?

Is the MeshInstance's bake mode set to Static? This is the default since 4.0, but double-check to make sure.

That said, I don't know if baking lightmaps onto ImmediateMeshes is supported. Logically, it should work if they have UV2, but I don't know if something else in the engine would prevent lightmaps to appear on them.

@blackears
Copy link
Owner

I just rewrote the mesh generation to use ArrayMesh instead of ImmediateMesh. LightmapGI baking is still failing. The MeshInstance3D has bake mode set to static and I compared both the MeshInstance3D and the ArrayMesh to an imported mesh from Blender to make them as similar as possible. Nothing is working. The only thing close to a Bake Light flag I can find is in the import tab. And I can't apply an import setting to a procedurally generated mesh.

@blackears
Copy link
Owner

godotengine/godot#76886

Looks like lightmaps cannot be baked to nodes unless their MeshIntance3D exists in the scene at edit time.

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

No branches or pull requests

2 participants