- Edited
Summary:
The terrain is starting to look more coherent and visually appealing, thanks to the new shader and various fixes/changes to the way the terrain is being generated..
What's New:
- Unwrapping and Texturing: I've implemented a custom shader to unwrap and apply textures onto a procedurally generated mesh. The shader considers the Y-coordinate of each vertex to decide which texture to apply. The result can be seen in the image below:
- Triangle Direction: Fixed some issues I was facing with the direction in which the triangles were being generated at the corners.
- Height Artifacts: Managed to sort out some visual artifacts where the height was incorrect, particularly where water is supposed to be.
Challenges and Solutions:
Color Interpolation on Vertices: When I initially applied color to vertices it was producing bad results:
The issue stems from the inherent behavior of vertex color interpolation in shaders. This feature works optimally for smooth, flat surfaces, but when applied to a mesh with varying heights and shared vertices, it doesn't behave as expected. Specifically, the colors gradually transition from one vertex to its neighboring vertex without considering any changes in height. This results in an unintended gradient effect where a more distinct color boundary was intended.
To solve this issue, I created a custom shader that considers the height of each vertex before applying the color. This approach allowed for uniform coloring based on the Y-level of each vertex.
Texture Unwrapping: Switching from a color display to a texture display introduced the challenge of unwrapping all of my squares. I accomplished this by using a tilemap format and applied the texture using a ShaderMaterial.
Voila! We've successfully integrated all squares into a single mesh that utilizes just one material. The image below showcases the custom shader that made this possible:
Triangle Direction: I encountered issues with the direction of the triangles, which created problems when vertex heights differed.
To address this, I altered the triangle generation direction for specific cases, flipping the indices to generate triangles in a different order. Below image shows a more detailed explanation of the solution to the problem:
This resolved the issue, as shown below.
This solved a part of the problem but if you notice the last image another one appearead. Artifacts are left behind. This makes the terrain look weird in specific cases. To fix this we go to next challenge.Height Artifacts: Some vertices were placed at incorrect Y-levels, leading to unwanted artifacts.
To combat this, I implemented a check for each vertex against its adjacent vertices. If the heights did not match, the current vertex's height would be adjusted to align with its neighbors.
Up Next: Crafting Data Structures for Game Squares
The focus now shifts to architecting data structures for each of the squares. Specifically, I'll be:
- Assigning various attributes to these squares, such as their type, available resources, and whether or not they're occupied.
- Integrating this data structure to make these squares fully functional within the game environment.
Your insights or tips for effective data structure design in Godot are more than welcome! This should add a layer of complexity as we continue this learning journey!