Page 1 of 1
Efficiently drawing pixels
Posted: Sun Jun 08, 2014 1:39 pm
by christiankolding
I'm in the process of coding a simple raycaster, and so far the performance is horrenderous. I believe this might be due to the fact that I am drawing the pixels to the screen one at a time. I tried using the canvas, but it really didn't help (maybe I was using it wrong?). Should I be using a canvas for something like this, or is there another way for me to draw a bunch of pixels more efficiently?
I attached a .love file. Can also check out the source on my GitHub profile (see footer).
Thanks in advance!
Re: Efficiently drawing pixels
Posted: Mon Jun 09, 2014 4:49 pm
by Robin
Drawing pixels one by one? That's more a [wiki]Shader[/wiki] thing.
Re: Efficiently drawing pixels
Posted: Tue Jun 10, 2014 5:57 pm
by christiankolding
Hmm, I am not quite sure how I would go about doing this with a shader. I have always thought of shaders as something I use to add effects to my game. I looked up shaders in the wiki, but I am not any closer to a solution. Can you point me to a good resource for shaders, or alternatively show how I would go about doing this?
EDIT: Actually, I googled and found some old posts on raycasters in LÖVE and I think I found a solution. I can simply draw the columns of each texture as quads, which should significantly reduce the number of draw calls.
Re: Efficiently drawing pixels
Posted: Tue Jun 10, 2014 7:25 pm
by Jasoco
Robin wrote:Drawing pixels one by one? That's more a [wiki]Shader[/wiki] thing.
I was wondering if a shader could be written to do the floors and ceilings in a Raycasting game actually.
When I was
playing around with Raycasting a while ago I did floors by casting rays against a rotated canvas inside another canvas and drawing each line of the floor from its horizon to the bottom of the screen and just scaled each row quad based on its distance from the camera. It worked great and was super fast, but caused obvious graphical inconsistencies due to the rotating of the image. Maybe a shader could handle this instead?
One day I plan on getting back to designing a 3D Wolfenstein style engine. Especially after
playing through GunGodz which is an amazing game and very inspiring to simple FPS designers.
Re: Efficiently drawing pixels
Posted: Tue Jun 10, 2014 9:19 pm
by christiankolding
So I managed to drastically improve fps by using the quad method. I can't exactly see how I would use that for the floors and ceilings, however. That must be a challenge for another day. Jasoco, do you by any chance have the source for that lying around? The thing with canvases sounds pretty interesting, and maybe I can use that to improve my code.
Re: Efficiently drawing pixels
Posted: Tue Jun 10, 2014 10:51 pm
by Jasoco
It's lying around this forum in many places. Mainly every single other Raycasting thread.
Edit: I'll post it once again.
- 3D.love
- (795.58 KiB) Downloaded 159 times
Don't expect to use it with anything other than 0.8.0. And it's shitty code. You won't like it at all. Enjoy!
I'd rather have a shader-based method for figuring out what the floor should look like.
Re: Efficiently drawing pixels
Posted: Wed Jun 11, 2014 11:37 am
by undef
christiankolding wrote:So I managed to drastically improve fps by using the quad method. I can't exactly see how I would use that for the floors and ceilings, however. That must be a challenge for another day. Jasoco, do you by any chance have the source for that lying around? The thing with canvases sounds pretty interesting, and maybe I can use that to improve my code.
Do you use love.graphics.quad?
Because that doesn't exist anymore since 0.9, if so just updating to 0.9 could make your code run more efficiently due to LuaJIT.