I am currently writing a raycaster based on this article, here, however when implemented in OpenFL, I get horrendous performance, or a crash. The code is available in this gist, here. I understand that software rendering is slow, pixel manipulation more-so, but how can I optimize this to achieve a playable performance?
I have implemented the same code in Kha as well, with “better” performance, I guess.
getPixel, setPixel and fillRect are going to be software operations, so it’s up to the CPU performance of modifying the pixels, then uploading that to a GL texture again before rendering.
It’s done by using a similar method; getting and setting pixels of an Image which is then drawn. Performance is not terrible, when run on HTML5. How could I speed this up, or what’s the hardware accelerated alternative?
The best solution would be to directly apply your bitmap rectangle texture to a polygon mesh (composed of 2 triangles for each of your walls) by directly accessing openGL. That way all the computation would be performed by your GPU.
Using lime.graphics.opengl and lime.graphics.GLRenderContext you can probably achieve what you want but you probably would have to write your own ‘DisplayObject’ class as I don’t think the openfl Sprite or Bitmap class directly expose their GL context object…
HTML5 performance is okay, not playable, but okay. I am building with cairo at the moment. Is there anything I could replace the set/getPixel workflow with so it can be usable?
Perhaps there is a way to adapt the code into something that would use OpenGL 3D acceleration for the rendering, rather than software. I found this online, which looks similar, although the draw calls are desktop GL, and not GLES-style calls like we use in Lime or OpenGLView
Nowadays using 3D acceleration is faster, than direct pixels manipulation.
If you want to make wolf-like engine, there is 3 ways:
For each vertical column on screen do standard raycast, but draw each column via GPU (basically it will be 1px vertical line with texture). Wolf 3D for iPhone use this way.
If your level is small, you can just render everything via GPU. And it will be pretty fast. Also this way you can render any level geometry, not just wolf-like