Defold raycasting

Raycasting in defold engine.

I am making a raycasting in defold. And i want to share it to community.
Be carefull, i can’t unload textures, so game will use more and more memory.
I don’t recomend play more then few minutes

github
html

Features done:
1)raycasting
2)textured walls
3)textured floor and ceiling
4)sprites
5)fov can be changed(throw exception now, will be fixed :grinning:)

Controls:
1)wasd - move
2)qe - rotate
3)0 - - increase/decrease fov

8 Likes

This is awesome! We need to figure out the issue you’re having with textures. I’m back at work on Tuesday unless someone else is able to assist before that.

2 Likes

I also were interested writing my raycasting version just for fun. How come the html is so slow? Done any checks where the bottleneck is?

  1. My implementation for drawing vertical lines for ray, is slow. Moving it to C and some optimization should fix it.
  2. I use lua table to hold color for every pixel. Then i draw them to buffer. If i use only buffer, it will save some ms.
  3. Debug map use new loop with raycasting to draw debug rays. Also drawing rays, spend some ms.

Maybe something else. :grinning:

After optimizations:
1)move to C function to casting ray
2)move to C function to drawing vertical line
3)removing debug rays.

Html working x3 time faster :grinning:

5 Likes

Remove table with screen pixels.Use only buffer. Now it is about 16ms per frame in html.(only for drawing walls). I think i can do more optimizations. But now i will be working on other features.

1 Like

add textured floor and ceiling.
fps is bad now. 40-50ms per frame. :wink:

7 Likes

Make a lot of things to increase performance. Now html version use 8-12ms per frame. :wink:
PC is x2-x3 faster then html.Not test in phones.But i beleive, it will be faster then html.
1)Move all raycasting code to C from lua
2)Refactor C code.
3)Make some optimizations
4)Use png for textures(lua tables with color integers,was used before)

6 Likes

Main functionality is done. It contains some bugs but all basic items working(walls,floors and sprites)
:grinning:

11 Likes

and how’s the performance? Any jaw-dropping before/after graphs? :wink:

1 Like

Performance need be improved. For screen 640x480.I cast 640 rays. In laptop(i5-6300U) average time is 4 ms(html 8ms). Android(Galaxy s7) 20ms :confused:

Looks like the bottleneck is drawing vertical line of pixels. And i have no idea how it can be improved.
Also i need update texture every frame, it use about 1-2ms in pc, and can’t be improved.

Parallel execution can give big performance boost.I will add it sometimes later. :grinning:

4 Likes

I need to implement:

  • different height walls
  • doors
  • sprites that not perpendicular to player.

After that all items, that i need, will be done.And i can focus on performance.

2 Likes