Zylann / godot_heightmap_plugin

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

Auto texturing #234

Open xTroMx opened 3 years ago

xTroMx commented 3 years ago

Is it possible to auto texture based on height and slopes ?

Zylann commented 3 years ago

Not sure what you mean by that, but in doubt, I'd say yes, but not out of the box.

If you want to automatically have a texture based on slope directly with no exceptions, and without having to paint anything, you pretty much have to write that logic yourself in the shader. It isn't hard, but given the infinite possibilities there is to texture a terrain, you'll understand that this plugin does not provide them all (there are a lot of different shaders already!), so the best way in that route is to fork one of the shaders.

Otherwise, this plugin provides authored texturing, which means you have to paint textures where you want them to be, rather than coding that. One easy way to apply a texture to slopes in this workflow is to pick a large brush, and use the slope slider in the bottom panel, which allows to limit the range of angles at which the brush will apply.

xTroMx commented 3 years ago

Thanks for answering. What Im looking for is to generate island maps randomly, and for that the textures should be also done automatically. like at heigh 0 to10 its the sand texture, from 9 to 20, its grass (9-10 is the blending of the 2 textures), 19-30, rocks, etc... Grass for example, is present when slope is very small and rock is present when slope is high.

Zylann commented 3 years ago

If you don't want to use a shader, you can also generate the splatmaps procedurally as part of your generator using either a compute viewport or GDScript. But it seems a shader will be faster.

xTroMx commented 3 years ago

If you can do it, Im willing to pay to have it developed, and make it available for all

Zylann commented 3 years ago

The problem is not about this, it's about the way it can integrate to the main plugin. There are million different ways of doing it and one has to be defined clearly. How many textures? Which slots do what? Normalmaps? Which options? Is it fully procedural or are some splatmaps still involved? Is it low poly? Etc...

In the brush system, the feature you want is already available in the form of slope limiter.

In terrain generation, well, you generate the terrain already. So why can't you generate the splatmap too? It's just yet another image to set pixels on.

If you have no idea how to do this in a shader I can help explain what you can do. A doc section could be added with such example. One main issue with the shader approach being built-in, is that everytime someone wants a shader feature to be added, I have to add an if in all shaders so that they support it too (crapping perfs in the long run and bloating them for users who dont need it), or write yet another copy/pasted version of a shader, and this is a nightmare to maintain in the long run because there are infinite possible combinations. One shader with procedural splatting could be made, but then someone else will need extra features on it that it misses, for example specific channels using a splatmap and others not. So very often, it's just way easier if you adapt one of the shaders to your needs with a bit of code. I'm considering to experiment VisualShader, but even then, you would have to modify the node graph to include the feature you want.

xTroMx commented 3 years ago

Well, Im just trying to focus more on the game development of my project, especially since I never really worked with shaders before, and Im sure this is something that will benefits many people. It might not need to be in all exsiting shaders, maybe just the splat 16 one....

How many textures? : 8 is fine Normalmaps: Yes, but not a must Options: select a texture, height starts, heigft ends, blending starts, blending ends, slopes degree High poly, Random heightmap is generated, then auto texturing is apply, in script

this is actually a good example: (except the slope factor is missing, since grass for example should not be there in high slopes) https://www.cprogramming.com/discussionarticles/texture_generation.html

Zylann commented 3 years ago

never really worked with shaders before,

But you had time to write an island generator^^ It's really not complicated to do what you need, just many ways of doing it. You dont even need to mess with shaders if you simply generate the splatmap image too. The link you just shared is the same logic you could use to generate such splatmap. Difference is, you write it in your script (since you seem familiar with scripts instead). Are you asking for the plugin to provide a GDScript generating such splatmaps for you instead? (You'd still have to invoke it yourself).

If you absolutely need shaders for some reason (so no splatmaps, it would run on the graphics card every frame) I could try to experiment this with multisplat16, but I guess I'll select only some slots to behave procedurally. Otherwise you'd need 16 vec4 uniforms to fit all the options and won't be able to generate some of the textures with more intricate rules (like roads, forest leaves or riverbeds). I just can't guarantee when I have time to do any of this.

Gusher commented 3 years ago

Am looking for something like this too, basicly my terrains are made externally with 3rd party terrain editors, will import heightmap and splatmap, but this plugin would be nice to randomly assign textures if a splatmap was imported, 4 textures are a good start, 8 is great for massive terrains...