Hi
I tried to implement a shader with the mapPixel() function.
Each time before drawing a picture, I apply a function which change the brightness of a pixel acording to the mouse position. That worked out so far.
But crux about this, this simple function drops my FPS to 2!!
Does anyone know a way how to implement such a thing more efficient?
Jan
mapPixel() is very slow
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
mapPixel() is very slow
- Attachments
-
- Shader.zip
- My trial
- (29.52 KiB) Downloaded 140 times
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: mapPixel() is very slow
I believe this is a CPU and GPU communication bottleneck.
You might have better luck with more hackish shader methods. Create a black image that follows the cursor with a transparent hole in the center.
You might have better luck with more hackish shader methods. Create a black image that follows the cursor with a transparent hole in the center.
Re: mapPixel() is very slow
I'm not sure about all the stuff you're doing in this example, as I'm new to LÖVE myself. However, I can't help but to note something in your love.update(dt). You do love.graphics.newImage() twice. I used to be and Android programmer, and from that I learnt one thing: Never, ever, create new objects every frame. This will cause the garbage collector to be drowned in objects to remove. I'm not sure how fast the garbage collector in lua/LÖVE is though, so this may not be the reason you program is slow. Just wanted to point that out. There is probably a better solution.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: mapPixel() is very slow
Time to calculate how much loops an 800x600 image does.. 240000.. hmm.. I wonder if that could slow it down.. .
Re: mapPixel() is very slow
I'm guessing mapPixel() can still be useful, even on larger areas, if you edit an image like once, or only every once in a while, and then reuse the old one all the other frames. In TC:s example, you could probably improve performance a lot by only creating a new image when the mouse is actually moved.
Still,TC:s approach is very bad. A better solution, as already been suggested, is to draw two images on top of eachother, one being semitransparent.
Still,TC:s approach is very bad. A better solution, as already been suggested, is to draw two images on top of eachother, one being semitransparent.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: mapPixel() is very slow
What? TechnoCat's solution is the fastest, most efficient one I can think of. Make a big PNG ahead of time to cover the screen. It doesn't have to be altered at all except when the mouse moves, and even then it is only to change the XY coords.T-Bone wrote:I'm guessing mapPixel() can still be useful, even on larger areas, if you edit an image like once, or only every once in a while, and then reuse the old one all the other frames. In TC:s example, you could probably improve performance a lot by only creating a new image when the mouse is actually moved.
Still,TC:s approach is very bad. A better solution, as already been suggested, is to draw two images on top of eachother, one being semitransparent.
Kurosuke needs beta testers
- nevon
- Commander of the Circuloids
- Posts: 938
- Joined: Thu Feb 14, 2008 8:25 pm
- Location: Stockholm, Sweden
- Contact:
Re: mapPixel() is very slow
I think he meant Topic Creator, not TechnoCat.tentus wrote:What? TechnoCat's solution is the fastest, most efficient one I can think of. Make a big PNG ahead of time to cover the screen. It doesn't have to be altered at all except when the mouse moves, and even then it is only to change the XY coords.T-Bone wrote:I'm guessing mapPixel() can still be useful, even on larger areas, if you edit an image like once, or only every once in a while, and then reuse the old one all the other frames. In TC:s example, you could probably improve performance a lot by only creating a new image when the mouse is actually moved.
Still,TC:s approach is very bad. A better solution, as already been suggested, is to draw two images on top of eachother, one being semitransparent.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Milwaukee, WI
- Contact:
Re: mapPixel() is very slow
Aha! That was throwing me off quite a bit too. I was only aware of OP.nevon wrote:I think he meant Topic Creator, not TechnoCat.
Re: mapPixel() is very slow
Yes, indeed. I didn't think about the fact that TC could be short for TechnoCat, sorrynevon wrote:I think he meant Topic Creator, not TechnoCat.tentus wrote:What? TechnoCat's solution is the fastest, most efficient one I can think of. Make a big PNG ahead of time to cover the screen. It doesn't have to be altered at all except when the mouse moves, and even then it is only to change the XY coords.T-Bone wrote:I'm guessing mapPixel() can still be useful, even on larger areas, if you edit an image like once, or only every once in a while, and then reuse the old one all the other frames. In TC:s example, you could probably improve performance a lot by only creating a new image when the mouse is actually moved.
Still,TC:s approach is very bad. A better solution, as already been suggested, is to draw two images on top of eachother, one being semitransparent.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: mapPixel() is very slow
And that's why one should never use abbreviations, IMHO.T-Bone wrote:Yes, indeed. I didn't think about the fact that TC could be short for TechnoCat, sorry
Help us help you: attach a .love.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests