Peatral / Godot-Map-Generator

A map generator made with godot
0 stars 0 forks source link

Todo: Noisy edges #1

Open deezaster opened 1 year ago

deezaster commented 1 year ago

First of all congratulations on this Godot project, just fantastic.

I saw that your to-do list includes "Noisy edges." I would be interested to know how you plan to implement this. Are you going to work with shaders? Or do you have another trick?

Peatral commented 1 year ago

Thanks a lot! As you found the to do list, you probably noticed too that I have based this map generator on this project, so the to do list is just all the different parts of exactly that project. With the major difference that I want to know how the voronoi cells are located (Imagine different regions of a country), thats why they are selectable.

I am currently not actively working on this (as I currently have different things to deal with), but I guess I know at least 2 solutions to the noisy edges problem. They are:

I personally think shaders would be faster to implement (As you could just distort the whole island for example), but I would say custom draw functions would be a more precise way to handle the situation. Each cell (polygon) gets rendered through this function as I have all the information I need about the cell itself and the neighboring cells. I would probably implement that, but I am not sure about the performance impact. As you might have noticed, I slapped a gdextension together to deal with a few geometry problems that were quite slow in GDScript. As I tried to construct this whole project quite modular you could try yourself implementing that draw function (or a shader solution).

And I am curious how you found this project 🤔

deezaster commented 1 year ago

How to find you? Easy. In Github I searched for "godot map generator" (only 24 results)

Peatral commented 1 year ago

Ok lol that's what I thought. Well, if you still care I quickly updated the project and the gdextension to release 4.0. Should be easier to run it now, I don't even remember what alpha or beta I created this in.

deezaster commented 1 year ago

I downloaded your version from 7 Nov, so without gdextension, and adapted it to godot 4. The speed is primarily not important for me.

The project runs fine. I just wanted to know how you did the implementation.

My version (I'm just experimenting!) is a generation of hexagons based on FastNoiseLite, so very simple. I persist the generated map as a scene. This solves (a little bit) the performance problem.

I was surprised that you also work with polygons. The reason why I take polygons and not sprites, so that when zooming the quality always remains the same.

I am a complete beginner when it comes to shaders. That's why I was a bit disappointed when I didn't find any shaders on your site. After all, I want to learn from the best ;-)

In addition, I am trying with the implementation of "Fog of War". But my solution does not convince me yet.

CleanShot 2023-03-04 at 19 16 35@2x

(Sorry of my bad english)

Peatral commented 1 year ago

Interesting, I'm just experimenting too, I currently have no "real" use for my generator. As I mentioned earlier, I want to have irregular sized regions that can be traced back (with neighbors and everything). Of course hex tiles are easier to implement but I think voronoi cells look nicer (but that obviously depends on the kind of project you are doing), therefore it made sense to use polygons. I don't know about the code from november but at this point the polygons actually get drawn using the draw function. Also I guess one could easily modify my generator to use hex cells instead of voronoi cells.

Drawing every cell on its own might be a bit inefficient so I guess I could try to write a shader to render the whole island. To do this I would have to need access to a few things in the shader:

The only question is how to pass those things to the shader. I think one could pass a long array of centers and polygons and biome data indexed by center/polygon (similar to how the delaunator works). Additionally I would have to pass the bounds of the island to be able to find the right cell. In 4.0 uniform arrays in shaders are finally possible so that would probably the way to go.

I imagine if I would have a shader to render the whole island, noisy edges would be easy to implement. I am definitely not a bloody beginner when it comes to shaders but I am by no means a master.

I don't know what kind of style you want to use for your game but I guess a more foggy fog of war would look better than just a clean black edge. It looks like you use 2D lights and illuminate surrounding tiles with tiles you have already visited. Modifying the light shape could yield interesting results. I don't know of course if that's how you implemented it but it might be worth a try.