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
- Favorites in PackageManager
- LudumDare59 : Signal
- Unity Editor: Tree Generator
- Leaf/Foliage Generator Tools (Runs in Browser)
- Testing Unity AI Beta
- Ways to Support UnityCoder Development
- Using UI Slider to Create 5-Star Rating Element
- Game Music Library For Unity (editor plugin)
- Fontastic : Easily Test Fonts in Unity Editor!
- GeoTiff Importer & Terrain Generator for Unity
- Create Baked DropShadow for UI images
- .JP2 Ortho Image Converter to PNG/JPG/TIFF
Recent Comments
- on Mesh Exploder (sources)
- on Sprite Sheet Flip Book Shader
- on Sprite Sheet Flip Book Shader
- on [Asset Store] PolygonCollider2D Optimizer
- on Trajectory Test Scene 2.0
- on Vector3 maths for dummies!
- on UnityHub 3.6.0: Remove Version Control & Cloud Dashboard columns
- on Using RenderDoc with Unity (graphics debugger)
Coin:
CUgDSbRqFcAumDSAcdKDvuXsw26VdkJe8C8WGUQHBAGS
An article by













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