I have a triangulated 2D polygon and a 3D terrain mode as a regular grid. The polygon is e.g. a forrest. How can I render that ON the terrain without textures?
As the model has to be zoomed in and out quickly, textures would make things way more complicated, dithered and slow.
Triangulation of the polygon in the the exact grid could work, but that’s a lot of effort and many, many triangles in the end.
A general triangulation is bad, as it will not go along nicely Wirth the terrain which will peak through the polygon triangles.
A fragment shader deciding if a pixel is inside or outside of that polygon is perhaps possible, but I have to make sure, the texture somehow describing the polygon x and y values is never compressed.
Displacement fragment shader for the terrain?
Can I assume that the terrain-model is height-values on a regular grid? That would be straightforward to draw.
A 2d-polygon is in essence a flat surface with possible jagged edges. How does that turn into a forrest or fit into the 3d surface of the terrain?
I struggle to get the picture.
Well, map features like forrests are stored as geo-referenced polygons. And yes, the terrain a regular grid. The end result should be a colored polygon draped on the terrain somehow.
First, tessellate the terrain into triangles (if you render it as quads, the implementation will do this automatically, but it’s unspecified which diagonal will be used, and you need to know that). Then tessellate the polygon along terrain edges. Finally tessellate the resulting shapes into triangles (the interior will just be the triangles of the terrain grid, but the edges will be various shapes). All of that is 2D; to get the height, vertices which are from the terrain grid keep their height, other vertices have their height obtained by projection onto the terrain.
If you don’t know how to do any of that, try and find a library. While none of the steps are particularly involved, the overall algorithm is more work than anyone’s going to cook up for a forum post.
Realistically, it’s much easier to render the polygons into a texture.
Maybe an approach like drawing fonts, the polygon exterior being transparent.
Cannot help to think that, whatever way, the transition between image and terrain will look artificial.
I think it could be possible to follow the polygon circumference (in an image with the polygon drawn onto) and tone the transparency … like blurring a font. Convoluting the full image might be easier though. This is moving off the question …
Thank you all!
Good ideas, I will make some test scenes.