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 vertex-based lightmaps #8062

Open
DarkDruid216 opened this issue Oct 10, 2023 · 3 comments
Open

Add support for vertex-based lightmaps #8062

DarkDruid216 opened this issue Oct 10, 2023 · 3 comments

Comments

@DarkDruid216
Copy link

Describe the project you are working on

I’m working on retraux/low poly turn based tactics game for mobile, and many of the game’s characters and assets look a lot like something out of a game from the 1990’s, so to help with the aesthetic, it would not just include low res lightmaps but also vertex based baked lighting.

Describe the problem or limitation you are having in your project

I’m already using the model’s vertex colors for other things like AO/specular, emissions, and material types, and taking how it’s part of the albedo and would multiply by the light and not add to it, it doesn’t work unless you make the light horrendously dim.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

An option on the baked lighting node that you can toggle on or off that can generate baked vertex lighting that goes through the lighting pass the same as its texture based equivalent, lightmaps. It’ll be affected by the lighting data resource the same as lightmaps, and it’ll interact the same to other lights like lightmaps, too.

It can also cast baked shadows and AO, too.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

I was thinking this baked vertex lighting system would be like a resource like its companion pixel lightmap with an array of colors in accordance to the vertices of the model.

Just light every vertex up during the pass.

As for toggling it on or off, it would be a flag the same for pixel based lighting.

As for it baking the actual lightmap, it’s the same as pixel based, but you would only need to trace and cast rays for every vertex over every voxel.

If this enhancement will not be used often, can it be worked around with a few lines of script?

You can do this by making a custom script and record all the lighting data for every vertices in an array and have it make a resource with that, but you would also need access to the lighting pass for this to work, which is disabled for vertex based shaders.

Is there a reason why this should be core and not an add-on in the asset library?

Oh! To be like an equivalent or companion to lightmaps you can turn off at anytime from the baked lighting node’s inspector.

The vertex based baked lighting system could be wildly efficient for massive worlds or if the levels’re blocky and doesn’t need pixel based lightmaps for it.

Think of like an option or an addition to smooth out shadows if you’re making, say, a PS1 retraux game where the vertex lighting’s there to smooth out the light and shadows for the point-filtered lightmaps.

It’s a popular genre, and this tool can definitely help with getting the vibe across.

@Calinou
Copy link
Member

Calinou commented Oct 10, 2023

Baking lightmaps to vertex colors was something I discussed with @JFonS at some point. It's feasible, but there are caveats:

  • We need a way to store vertex colors separately from a mesh, similar to the UV2 unwrap cache. However, unlike UV2 unwrap cache, each copy of an instanced mesh should have its own vertex colors. See Implement persistent MeshInstance3D vertex colors on a per-instance basis #6486 which also requires something similar.
  • If the mesh already uses vertex colors for its own coloring purposes or for use in custom shaders (such as splatmapping), we need to multiply these colors with the lightmapper-generated vertex colors. This may require specific additions to the scene shader.
  • To reduce memory bandwidth usage, vertex colors in Godot 4.x are limited to 8 bpc RGBA – they can't be overbright. This means lighting from bright emissive materials may appear to be too dark. Precision issues may also be visible in certain cases, but I think vertex color interpolation will make this issue not too noticeable.
  • Supporting lightmaps with directional information won't be possible, but this is probably not an issue given the intended use cases.

The baking process itself would likely bake a lightmap texture as usual, but every vertex on baked meshes would then sample the texture using the vertex's UV2 coordinates then write a vertex color for the given vertex. The texture is then discarded as it's not needed anymore.

Note that we don't expect Godot 3.x to gain large new rendering features, as most of the development focus is on Godot 4.x.

@Calinou Calinou changed the title Vertex based lightmaps for Godot 3 and 4. Add support for vertex-based lightmaps Oct 10, 2023
@DarkDruid216
Copy link
Author

Ah, I can tell there might be some issues, but I bet most of them wouldn’t be as noticeable. >B3c

@bertodelrio256
Copy link

bertodelrio256 commented Dec 10, 2024

  • To reduce memory bandwidth usage, vertex colors in Godot 4.x are limited to 8 bpc RGBA – they can't be overbright. This means lighting from bright emissive materials may appear to be too dark. Precision issues may also be visible in certain cases, but I think vertex color interpolation will make this issue not too noticeable.

I know in unity the way they get around this is by multiplying either the albedo or vertex light channel by something like 16, then adjusting the baked light energy to match it.

The baking process itself would likely bake a lightmap texture as usual, but every vertex on baked meshes would then sample the texture using the vertex's UV2 coordinates then write a vertex color for the given vertex. The texture is then discarded as it's not needed anymore.

If the light rays can be fired from vertices instead of from texels in a texture, it should, because one of the advantages vertex color baking has is that you can bake huge, huge scenes that would require massive amounts memory with a texture. with a texture we would have the same wait time and limitations. also, vertex lightmaps dont need a uv channel.

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

No branches or pull requests

3 participants