Efficiently drawing pixels

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
christiankolding
Prole
Posts: 17
Joined: Sun Jul 22, 2012 11:15 am
Location: Copenhagen, Denmark
Contact:

Efficiently drawing pixels

Post 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!
Attachments
love2d-raycaster.love
(32.25 KiB) Downloaded 169 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Efficiently drawing pixels

Post by Robin »

Drawing pixels one by one? That's more a [wiki]Shader[/wiki] thing.
Help us help you: attach a .love.
christiankolding
Prole
Posts: 17
Joined: Sun Jul 22, 2012 11:15 am
Location: Copenhagen, Denmark
Contact:

Re: Efficiently drawing pixels

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Efficiently drawing pixels

Post 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.
christiankolding
Prole
Posts: 17
Joined: Sun Jul 22, 2012 11:15 am
Location: Copenhagen, Denmark
Contact:

Re: Efficiently drawing pixels

Post 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.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Efficiently drawing pixels

Post 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.
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: Efficiently drawing pixels

Post 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.
twitter | steam | indieDB

Check out quadrant on Steam!
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 1 guest