Live data from Hacker News

Show HN: 2D field of view demo

jsfiddle.net

1–10 of 80 posts

Re: Show HN: 2D field of view demo

#2
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 rooms with no one in them are slightly darker)

Re: Show HN: 2D field of view demo

#4

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…

Permit me a "show HN" of my own ;)

Here's a 3D view-shed calculation on a grid.

http://williamedwardscoder.tumblr.com/post/13269950091/a-whi...

Re: Show HN: 2D field of view demo

#5

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…

Permit me a "show HN" of my own ;) Here's a 3D view-shed calculation on a grid. http://williamedwardscoder.tumblr.com/post/13269950091/a-whi...

This looks great! Are the calculations done in the GPU?

Re: Show HN: 2D field of view demo

#7

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.

Re: Show HN: 2D field of view demo

#8

Earlier quoted context omitted.

Permit me a "show HN" of my own ;) Here's a 3D view-shed calculation on a grid. http://williamedwardscoder.tumblr.com/post/13269950091/a-whi...

This looks great! Are the calculations done in the GPU?

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 - and a move towards Vulkan, then the cost will change. As the cost of getting the result back to where its used for game logic diminishes, then this could increasingly be a candidate for GPU crunching :)

(In my code there's a divide-per-grid-square that could be tackled using scaling perhaps.)

Re: Show HN: 2D field of view demo

#9
In case someone is interested in the design:

https://bbcdn.githack.com/rmsundaram/tryouts/raw/e06259fffad...

Devising the algorithm took around a month; did it in my free time. The implementation took a week, in HTML5 Canvas/JavaScript. Doing a 360°, not-bound-by-distance FoV would have been simpler, but FoV limited by both angle and distance took time.

The idea is to find the field of view of an observer on a map with blocking buildings (polygons) and also to service a line of sight query, to know if a given point is visible to the observer.

The code contains enough comments including citations and references to articles and books. Here's the actual repo from where the above page is served:

http://bitbucket.org/rmsundaram/tryouts/src/master/CG/WebGL/...

Re: Show HN: 2D field of view demo

#10

Earlier quoted context omitted.

This looks great! Are the calculations done in the GPU?

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.

Post reply on HN