Live data from Hacker News

Show HN: 2D field of view demo

jsfiddle.net

11–20 of 80 posts

Re: Show HN: 2D field of view demo

#11

Earlier quoted context omitted.

Not the example code I pasted into the blogpost. To be honest, its not an obvious candidate for offloading the the GPU. Its a light task, the result is probably wanted by the CPU, and these days we probably have spare CPU cores that could be utilized while the GPU is busy. However, with the move towards UMA for CPUs and GPUs - even the newly-announced ARM cores with Mali GPUs have coherent caches between CPU and GPU…

> the result is probably wanted by the CPU -- I think this is a good reason to do it in the CPU. > its not an obvious candidate for offloading the the GPU -- How? Shooting a ray to every vertex comes to my mind.

> its not an obvious candidate for offloading the the GPU -- How? Shooting a ray to every vertex comes to my mind.

I'm not following your meaning here ;)

My blog post describes how to do it in a sweep rather than 'shooting lines', for the performance reasons given in the blog post.

'Shooting lines' is pretty poor for performance because of data locality and cache pressure.

In general, locality is the big performance problem with 'ray tracing' in general. All attempts at speeding up ray tracing are about trying to make 'bundles' of adjacent rays flying in close formation that can be combined or computed together so as to try and give some locality to the problem.

My scanline approach (line as in cache array of adjacent memory, not line as in line-of-sight between eye and obstacle) is good for CPUs and good for GPUs. If you want to offload viewshed computation to the GPU, you ought strive for a scanline approach rather than 'shooting a ray to every vertex' too. My code ought be straightforward to port to a shader.

Re: Show HN: 2D field of view demo

#12

Interesting! How much more complicated would it be if the obstacles were not polygons but points on a grid? I've always been curious how the FoV was computed so fast in the Baldur's Gate games given the complex grid-based map and the weak harder at the time. Example grid: http://aigamedev.com/static/tutorials/FPSB_bg_rsr.png And the FoV rendered: http://cdn.wegotthiscovered.com/wp-content/uploads/Baldurs-G... (the ro…

> How much more complicated would it be if the obstacles were not polygons but points on a grid?

I think with grids, one approach would be to go with a flood fill kind of an algorithm, but doing it cell-by-cell will be costly.

An alternative way would be to unify cells together as a polygon and do intersection testing; with a hammer everything looks like a nail :P

I think in games like Baldur's Gate, [Portal Visibility](http://playtechs.blogspot.in/2007/03/2d-portal-visibility-pa...) is commonly used.

Re: Show HN: 2D field of view demo

#13

I found a bit of a weird 'bug', where I could get the POV to have a straight edge (rather than the curvature), if it's of any use: http://imgur.com/a/MPzGa

Thanks for reporting this ;) This is a floating-point comparison problem, I faced it frequently during development; need to play more with it to arrive at a better epsilon ε value.

No problem :) Glad I could help! :D But other than that, I don't know much about what you're doing, but seems very cool anyway :D

Re: Show HN: 2D field of view demo

#15

Earlier quoted context omitted.

> the result is probably wanted by the CPU -- I think this is a good reason to do it in the CPU. > its not an obvious candidate for offloading the the GPU -- How? Shooting a ray to every vertex comes to my mind.

> its not an obvious candidate for offloading the the GPU -- How? Shooting a ray to every vertex comes to my mind. I'm not following your meaning here ;) My blog post describes how to do it in a sweep rather than 'shooting lines', for the performance reasons given in the blog post. 'Shooting lines' is pretty poor for performance because of data locality and cache pressure. In general, locality is the big performance…

My bad! Of course ray tracing in the GPU would be costly; I dunno where I got that. I think my mind is still stuck on 2D after this, need to go back to 3D :)

When I had to do picking on a 3D terrain, I did a scanline approach too (https://bitbucket.org/rmsundaram/tryouts/src/master/CG/Terra...)

Post reply on HN