godot: Unable to bake lightmap with CSG due to the lack of ability to generate UV2 for CSG nodes

Godot version: Godot 3.2.4-beta6 to Godot 3.3-rc8

OS/device including version: Windows 10 NVIDIA GeForce GTX 750 Ti GLES2/GLES3

Issue description:

BakedLightmap does not work with CSG nodes. As far as I can tell, this worked up to beta 5.

As far as I can tell the CSG node does not have a UV2 layer. And I cannot use “Create Outline Mesh” + “Unwrap UV2 for Lightmap/AO” with it (The Mesh option in the toolbar does not appear for CSG nodes).

Steps to reproduce:

  • Create new Godot project (GLES2 or GLES3, does not matter).
  • Create new Spatial scene.
  • Save it, any name.
  • Add CSGBox (or any other CSG node) to the scene. Observe there is no Mesh icon in the bar when the CSG node is selected.
  • Set use_in_baked_light = true of the CSG node.
  • Add BakedLightmap node (make sure the CGS node is inside).
  • Click BakeLightmap, select any path, click “Save”.

Result: Message appears “No meshes to bake. Make sure they contain UV2 channel and Bake Light flag is on.”

Expected Result: The light is baked (which is no light, since we didn’t add any, and thus the CSG should appear dark).

Minimal reproduction project: BakeMeUp.zip

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Comments: 19 (16 by maintainers)

Most upvoted comments

@Calinou

Alright, what I’m understanding is that CSG does not have UV2, and that baking working before was as accident. In that order of ideas, I propose a solution for this issue: remove the baking light properties from CSG nodes (use_in_baking_light, generate_lightmap and lightmap_scale).

Also, somebody may want to see into the naming of Uv2. The CSG has something called like that, that works.

@kalbfled I ended up working around that by using “Create Outline Mesh” which would create ArrayMesh from the MeshInstances I had, and then “Unwrap UV2 for Lightmap/AO”. I arrived to that searching online. This is also the motivation to mention on this issue that that is not an option with CSG.

I authored the StackExchange question @theraot references above. I attempted the same basic test he describes, except I used MeshInstances with CubeMesh and PlaneMesh as the mesh data. I couldn’t bake light with that setup because Godot refuses to unwrap meshes that are not instances of ArrayMesh.

This doesn’t make sense to me when these meshes already have a mapping in uv1. Maybe this is a candidate for an enhancement–allow baking with PrimitiveMesh instances.

I worked around by creating a plane+cube scene in Blender and transferring it into Godot as .glb.

Is this still reproducible in 3.5 beta 5 or later?

Yes, as far as I know, nothing changed on the subject. This isn’t easy to fix, and will probably require a proposal to decide how to store the generated UV2 for a non-imported, generated mesh. I assume this would also be useful for @Zylann’s terrain add-on to an extent.

@ee0pdt ~~I removed my old comment because it was incorrect. It should be possible to hide the properties only in CSGShape3D and its descendents using _validate_property() as done here: https://github.com/godotengine/godot/blob/27d4e2f09fe76e06e6b4751025acc79d993c61e5/modules/csg/csg_shape.cpp#L571-L579~~

Edit: We’ll have to use the node configuration warning approach as the use_in_baked_light property is used with GIProbe (and its sucessor is used with SDFGI in master). These GI approaches do work with CSG nodes (or are intended to at least). However, the node configuration warning should only be emitted if there’s a BakedLightmap node in the scene tree. This makes the issue significantly harder to resolve.

I tried to make UV2 available in CSG nodes, but it’s not trivial to do correctly. Due to UV padding and seam issues, it would likely better be done by exposing a nondestructive CSG -> MeshInstance conversion workflow and letting Godot use xatlas on the generated mesh instead.

@Calinou I’m not aware of any, but that is not the only option we could explore here. I’m just suggesting we find a way to inform users that these properties have no effect for a given node.

The closest thing I can think of is the warning on a Container node:

image

If you are referring to the uv2 property of the detail section of the material - nope, that’s only telling the material how to scale UV2 IF it exists. And CSG doesn’t have UV2.