29
2012
2D Raycasting Visibility – Voxel Travelsal
Converted this AS3 2D raycast (by Lee Grey) to Unity javascript. (Image: raycast is coming from the middle, hits a wall..)
Next:
– Use grid array instead of reading pixels from image.. (done)
– Try if this is faster compared to the old Raycast visibility code (done)
– And would this ever work with moving objects..?
– 3D version needed for Voxel Terrain digging (mesh collider is too slow)
Some results:
– v2.0: 50000 rays, mainthread: ~40ms (using 2D grid map) vs. old real raycast ~68ms
Added version 2.0 webplayer:
– Calculates 512 rays for visibility with voxel travelsal.
Webplayer:
http://unitycoder.com/upload/demos/VoxelTravelsal2DRaycasting1/ (v1.0)
http://unitycoder.com/upload/demos/VoxelTravelsal2DRaycasting2/ (v2.0)
Download source:
voxelTravelsal1.unityPackage
voxelTravelsal2.unityPackage
Related Posts
11 Comments + Add Comment
Leave a comment
Recent posts
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
- Check if point is inside polygon 2D (using line intersection)
- UnityHub: Enable Create Project Button (without having to select Cloud Organization)
- UI: Make Tooltip background fit Text content length
- Pong-Wars in Unity
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub)
- UnityHub: Add support for custom project title (instead of folder name) or use ProductName
- Testing Unity MUSE AI
- QR Code Generator Online
Added v2.0 webplayer
@mgear – I’m glad you’re putting the raycast to good use. Please let me know if you have any feedback for improvements.
How has the performance compared to your earlier raycast experiments?
Cheers.
Thanks! On that early test it was about twice as fast – compared to unity physics raycast. (I guess it would be even faster if done properly..: )
Can you give an estimate as to when the source code for this will be publicly available?
I am especially interested in the second version which, at a first glance, seems to solve a problem I am currently having.
Besides that, thank you for an awesome blog 🙂
Thanks, i’ll upload this later next week. Did you convert that same code or some other?
v2 has some problems too..(thats why you can only move in that limited area currently)
Yeah, I ended up converting Lee’s approach as well after trying a simple Bresenham algorithm. The first approach I used was to update the pixels of an overlay texture used for displaying the fog. This is now done by shading instead which yields better performance, though it is still to slow. I’m curious as to how you got the very smooth circle and edges?
It uses this code to build/modify mesh for the visible area:
http://unitycoder.com/blog/2012/02/15/raycast-realtime-visibility-2-0/
Some interesting stuff here:
Comparative study of field of view algorithms for 2D grid based worlds
http://roguebasin.roguelikedevelopment.org/index.php?title=Comparative_study_of_field_of_view_algorithms_for_2D_grid_based_worlds
A Fast Voxel Traversal Algorithm
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.42.3443&rep=rep1&type=pdf
Super Fast Ray Casting in Tiled Worlds using DDA
simple grid visibility
https://towardsdatascience.com/a-quick-and-clear-look-at-grid-based-visibility-bf63769fbc78