Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.69k stars 158 forks source link

Use hex tiling for tiling reduction #343

Open MasterDingo opened 1 year ago

MasterDingo commented 1 year ago

Is your feature request related to a problem? Please describe. The existing way for tiling reduction still gives rather noticeable tile seams.

Describe the solution you'd like Use hex tiling mechanism instead, like in this C code https://github.com/mmikk/hextile-demo

Describe alternatives you've considered Additional context

Zylann commented 1 year ago

I saw about hextiling in BGFX demos, it's a neat technique. It's however more expensive than what I'm doing currently, I use only 2 texture samples, while hextiling seems to use 3 + computes a lot more stuff (so with PBR textures: x2, using 4-channel splatmap: x4, so 24 fetches. And with triplanar: 72 fetches, not even counting heightmap fetches and internal Godot fetches)

Many options were asked for in shaders of this plugin, and I wish to expose options. Just like Godot exposes myriads of options in its materials. But Godot 3 achieves this by dynamically changing preprocessor macros, which isn't a thing for user shaders. That means if I wanted to have options, either I have to litter shaders with if inside (which is very bad for performance when there are many) or I have to copy/paste all the shaders for every combination of options, which is unmaintainable. It might be easier in Godot with preprocessor support, but macros can't be toggled from the inspector so it would still require many shader variants. Or it would have to be global to the entire game by writing the symbol in project settings to enable it. (I said this many times in about every issue asking for shading options but I repeat it anyways^^")

This would be a cool enhancement still.

Zylann commented 1 year ago

I made a port of the shader to Godot 3 (just the shader for one texture, not a full-blown terrain shader): hextile.zip Demo project here: https://github.com/Zylann/godot_hextile It's a lot of code, would easily double the size of terrain shaders. And I feel like it could be optimized a bit... it certainly is way slower than the anti-tiling done currently in the plugin (despite being lower quality). Didn't write an integration to the plugin though. image FPS without hextiling: 965 FPS with hextiling: 710