0

In my application, I have partitioned the screen into different regions. These are given by the polygon boundaries. Once this partition has happened in the CPU, the shader should now give each pixel a value corresponding to the region it is in.

At the moment, I am doing a point-in-polygon test for each pixel, which is of course pretty slow. To accelerate, I also compute the bounding boxes for each polygon for a first pre-check.

Is there a faster way of doing this in principle? I looked into some flood fill algorithms, but they do not seem to be fit for use in shaders.

Or, if I have to do point-in-polygon checks for each pixel, is there an algorithm to compute a simplified polygon contained in the original one, to further enhance performance? This would only leave me to do the point-in-polygon checks with the original polygon for the few cases where pixels are in the bounding box, but not in the simplified polygon.

berndibus
  • 95
  • 10
  • i don't know what you want to do witht thoose values nor how many regions you are considering. But you can instantiate quads for each region of your screen, use a custom shader with a "PerRendererData" flag, and for each quand each frame you set them your custom value. Don't do it it for each pixel but in this case for each quad on the cpu – Paltoquet Nov 20 '19 at 07:57
  • A faster way would be to construct a Mesh from the polygon boundaries render it using MeshRenderer. If this is just an intermediate step in a more complex shader, you can render these Meshes to texture and use the texture as input on your shader. – Leo Bartkus Nov 20 '19 at 17:08

0 Answers0