godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Add support for vertex-based lightmaps #8062

Open DarkDruid216 opened 8 months ago

DarkDruid216 commented 8 months ago

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 commented 8 months ago

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

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.

DarkDruid216 commented 8 months ago

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