Optimised line intersection by adding two simple prechecks.#14
Optimised line intersection by adding two simple prechecks.#14marmottchen wants to merge 1 commit into
Conversation
|
Hi @marmottchen! Thank you very much!! I created a script for benchmarking the code, here. Somehow, I found that the code with the two checks is a bit slower than the old version. Look at the outputs below. My guess is that since the values calculated for the checks are not used later in the function, we ultimately lose more time than we save. Anyway, I still think doing the two checks is smart, but maybe we need to do this strategically? Any ideas? Btw, if you try to run the benchmarks you will probably get the error |
|
My idea was to eliminate edges that are clearly not going to intersect by observing the rectangles for which they are the diagonals. Like boxes around the edges. We could try the same idea a step higher up with the hulls. I can try to adapt the code on the weekend, altho I dont know how to give the shader the additional hull information. |
|
That seems like a great idea. There's one catch, hull data can change from frame to frame, because it's useful to have movable hulls in a game. So, we need to compute the bounding boxes every frame. This may be worth it tho, especially if we cache the bounding boxes, since we can expect that most hulls won't change. For sending this data to the shader, first you need to create an SSBO uniform in the light shader. Just take a look at how Then, you need to go to Lastly, to send the bounding box data in each frame, simply do as in function If you are having trouble implementing this, just ping me and I'll be happy to help. Also, no need to implement the caching yet, we can do that later. Excited to see what you come up with :) |
I added two simple checks to the line intersection function.
This avoids calculating intersections with edges that arent in the minimal rectangle containing fragmentTexCoord and lightPos.
The change should make the algorithm faster, altho I dont know how to test that.