godotengine / godot-proposals

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

Support height mapping for triplanar materials using surface-gradient bump mapping #5530

Open JohanAR opened 1 year ago

JohanAR commented 1 year ago

Describe the project you are working on

FPS shooter with large outdoor environments

Describe the problem or limitation you are having in your project

I don't have the resources to hire artists, and I have limited time and skill to create lots of good looking assets. So I rely heavily on generated terrain, which needs to be procedurally textured in a visually appealing way.

Triplanar texturemapping and texture blending are some of the techniques I use for this, but currently Godot tells me that height mapping is incompatible with triplanar texturing, and without it surfaces look flatter and more boring.

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

Having a height texture makes surfaces look better.

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

"Surface Gradient–Based Bump Mapping Framework" by Morten S. Mikkelsen appears to be a solution for combining height maps with triplanar texturing.

https://jcgt.org/published/0009/03/04/

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

No workaround, other than implementing it yourself in a custom shader matieral.

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

Would make StandardMaterial look better for anyone using triplanar mapping

Calinou commented 1 year ago

Beware that using both triplanar and heightmap at the same time can be very expensive, as it requires a lot of texture fetches and loops in the shader.

I suppose one workaround would be to allow using heightmapping when triplanar is enabled, but with triplanar mapping disabled for the heightmap sampling only. This can look good enough for terrain as heavily steep terrain is generally not the location where parallax mapping is the most visible.

JohanAR commented 1 year ago

Maybe the editor could have a little yellow alert sign that shows in the StandardMaterial UI if both are enabled, and if the user clicks/hovers it you get a tooltip explaining that this is a computationally expensive combination.

I haven't looked much into the existing heigh map and deep parallax code, but would there be some reason to use this surface-gradient bump mapping without triplanar? I.e. if it was implemented, should it be a switch similar to deep parallax to switch the algorithm?

Regarding fetches, even if it's expensive it could still be useful for games targeting modern GPUs that can handle it. Or to use on low LOD levels while assigning a faster material to higher LODs.

I read a presentation about MicroSplat (a terrain system in the Unity asset store) which says that it's fast because it "only" does 12 texture lookups per fragment (28 when using triplanar). It compares with CTS (another terrain system) which supposedly does 52 texture lookups (148 for triplanar). I assume you know more about the subject than I do, but even the fast system did a lot more lookups than I thought was feasible. And the number of lookups in CTS sounds ridiculous to me, but I believe people were still using it in their games so I can't be entirely impossible, right?

Source: http://wiki.polycount.com/w/images/4/4a/Boston_Game_Dev_Group_2020_Shaders.pdf

stevenctl commented 11 months ago

triplanar mapping disabled for the heightmap sampling only

By this, do you mean only sampling the heightmaps for one plane? For example, only sample it for the Up plane for something like grass/dirt?

FWIW my 3070 drops from 144 to ~50 FPS when viewing this naïve implementation up close

Calinou commented 11 months ago

By this, do you mean only sampling the heightmaps for one plane? For example, only sample it for the Up plane for something like grass/dirt?

Yes :slightly_smiling_face:

FWIW my 3070 drops from 144 to ~50 FPS when viewing this naïve implementation up close

What does performance look like with a material that has triplanar disabled? Deep parallax is expensive when viewed up close. You can improve its performance by reducing the number of steps. (6 min and 16 max is often enough in practice, especially at lower resolutions).