I want to randomly place objects USING ALPHA MAP (only black color, not grayscale). The black areas on the map are using to determine where we CAN place an object.
Why do I want to do this? For example, we have some terrain with a river. We want to randomly place a chest on that terrain and the point is we want our chest NOT TO BE IN THE RIVER. We have a special location to place that chest and that location can have a very complex structure.
Simple map with lake and river:
Black/white map of the location for placing objects:
Of course, we can just take random points with Random.Range() and check each point by comparing it with pixel values: "Is the point on the black area?" BUT if we would have a very small (<10% of total area) and complex "available" area (for example, islands in the swamp) then there will be a very large amount of "garbage" points. Therefore it is very inefficient method.
Does the quick and performance technique exist to get desirable amount of "available" points?