I need this to modify the terrain splat map under a building when it is placed.
What is the simplest way to rasterize a polygon (convex) in Unity like shown on the image?
I need this to modify the terrain splat map under a building when it is placed.
What is the simplest way to rasterize a polygon (convex) in Unity like shown on the image?
I’m not sure what exactly you’re asking here. The image on the right is not just a rasterized polygon. It’s already antialiased. Just rasterizing a polygon is rather simple. Performing antialiasing is a bit more complex.
The general idea is to just iterate through all pixels in the AABB of your polygon and check if the pixel is inside or outside the polygon. For antialiasing there are several techniques possible. A common one is super sampling (so you just pretend there are more pixels (double, quadruple) and you just average the result of those sub pixels). Other approaches will just sample the same polygon several times but with slight offsets in each direction.
You may want to read through Spatial anti-aliasing. Of course technically you could just use Unity’s rendering engine and your GPU to render the polygon to a rendertexture and read the result back. However the tricky part would be to actually combine the result into your splat map. Also the rendering overhead and read-back would probably be worse for performance.