Zylann / godot_heightmap_plugin

HeightMap terrain for Godot implemented in GDScript
Other
1.71k stars 159 forks source link

Texture looks streched on steep sides #31

Closed DigitalMonkeyPa1 closed 6 years ago

DigitalMonkeyPa1 commented 6 years ago

Tri-Planar mapping can eliminate these, but performance may be disturbed. https://gamedevelopment.tutsplus.com/articles/use-tri-planar-texture-mapping-for-better-terrain--gamedev-13821 This post explains how to use tri-planar mapping, but it is for jMonkey engine, but the shader code looks almost similar to godot's shader language. Putting an option to enable or disable this one would be cool.

Zylann commented 6 years ago

I wish Godot had togglable #ifdef support in its shader pipeline (https://github.com/godotengine/godot/issues/17303), because that would be one of maaany options I wish the terrain shader could have... I cannot switch shader just for regions of the terrain, and I also can't have much options either at the moment, because that would mean I have to add if blocks all over the place (bad!) or copy/paste the shader dozens of times (also bad). I already have two if for holes (which is legit) and depth blending (which is not), I would like the latter to go away as well...

Also, using triplanar sounds like an expensive operation to add to a shader that some people already have difficulty to run (https://github.com/Zylann/godot_heightmap_native_plugin/issues/22). The current shader has to sample at least 8 textures at once + a few others + the ones Godot inserts internally. 8 fetches are used for splat textures. Triplanar multiplies those by 3, which becomes at most 24 fetches, JUST for the splats.... that's quite a lot, and further reduces the amount of users able to use it. (the article even explains performance is the first downfall). That comes down to the technique being used of course, which I plan to migrate to texture arrays once Godot supports them, but I will still need 8 base fetches unfortunately... Perhaps it could be reduced by using triplanar only on some of the splat textures though. For example, that would raise from 8 to 12 instead. You see now I need ability to code shader options pretty badly before that^^

For now, I can eventually add an option that will enable triplanar mapping only on the FIRST splat texture, which means 1 more if block in the fragment shader to do 4 more texture fetches. So it can be done, but not as efficiently as I would like to. Ideally, I really would like to replace those ifs by #ifdefs because they will almost never change during the execution of a game.

Otherwise, your only go is to modify the shader and implement triplanar on the textures you want, which shouldn't be too difficult (if you know about shaders).

There is another alternative for cliffs that looks better, which is to use cliff meshes (regular models) instead of leaving a stretched heightmap, because, well heightmaps aren't good at cliffs anyways :)

DigitalMonkeyPa1 commented 6 years ago

That's ok, can you check this cool tool to make landscapes: http://www.dplate.de/tools/scapemaker the features like height based water and foilage and clouds are nice. By the way I mailed the developer to give code, it's now available on the website (he also warned me that it's over 12 years old, and unmaintained), just scrap it you may find something useful. Hope you have some fun with it.

Before closing the issue let me try something with tri-planar thing for a few days, then I close this issue.

Zylann commented 6 years ago

I really intend to add a triplanar option to the first texture slot though, that should be ok for the time being.

ScapeMaker looks quite old indeed, but its generator might be of interest. Foliage is currently available in the grass branch, and trees are another subject to investigate in future updates but it might be just mesh-based with impostors.

Zylann commented 6 years ago

Without triplanar: image

With triplanar: image

I can have it optional on the 4th texture slot only. The idea is, the first slots are often used for ground, while cliffs get painted afterwards.

Zylann commented 6 years ago

I just added an option to activate triplanar mapping on the last texture slot. It's not much, but at least allows to reduce stretched look on cliffs.

DigitalMonkeyPa1 commented 6 years ago

Thank you so much. But I am totally confused with the thing "Triplanar Mapping" - found in the docs ( 3D -> SpatialMaterial), is this "Triplanar Mapping" same as the one we have discussed.

Zylann commented 6 years ago

Yes, I took the same formulas to do it. My screenshots look like shit though, because I tested with a texture on which triplanar doesn't work nicely^^ but I'm sure it would work ok with a more organic natural texture.

DigitalMonkeyPa1 commented 6 years ago

So, can I close this issue?

Can I contribute to this project, or do you want to make it on your own?

Zylann commented 6 years ago

You can close the issue if it's fixed for you. You can also contribute to the project if you find things to fix or improve as well.

DigitalMonkeyPa1 commented 6 years ago

Sorry, I was busy with a grass_plugin_4_godot by Marcos Augusto Bitetti, but was surprised that you made one. Have a look at his video : https://www.youtube.com/watch?v=-lxk_bLRBSg

It's made for Godot 2.x, I was trying to port it, at first I thought a few changes is enough, but its more complicated than I thought, a lot has changed from 2.x to 3.x. But your grass implementation, especially UI is very compact, I liked it.

In that grass plugin, he uses MultiMeshInstance to hold mesh data, ie: loads grass mesh instead of pic, except default grass mesh, which is constructed in plugin code. Since every grass is a mesh(instance of multi-mesh) we can apply shaders like wind shader as material.

Can we apply shader materials to the grass in your implementation?

Zylann commented 6 years ago

Please open a different issue to ask about different topics.