Take an image and make darker shades of it...

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

Take an image and make darker shades of it...

Post by Jasoco »

In the game I am working on, I am trying to figure out the best way to handle "darkened" areas without drawing things redundantly and I was thinking the best way would to take the wall tiles, paste them onto a Canvas or into Image Data multiple times with each one being drawn slightly darker than the previous, then using the correct darkness image depending on the distance or light level. I would also need to preserve opacity.

Not sure how to go about it though. I guess PixelEffects would be a good idea, but not really sure how to really approach that.

Currently I was simply drawing the image once at 0,0,0 coloring (So they draw completely black) then again a second time with a slight opacity depending on the darkness. But this is redundant as it's causing extra draw calls. I figure if I pre-generate the different dark levels at load it would be so much better.

You my ask why I don't create the images beforehand. Well, I don't really feel like having to recreate each darkness every time I change a tile. That's just silly and wasteful.

I figure 10 light levels would be enough.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Take an image and make darker shades of it...

Post by MarekkPie »

I think the problem with any approach that applies the darkness level uniformly to an object is you don't get nice blending. If you are still working on the raycasting game, then that would be beyond me, but I remember an example of lighting that someone had in a .love file that might do the trick.

Here is it:

viewtopic.php?f=5&t=3622
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Take an image and make darker shades of it...

Post by Jasoco »

No, all I need to do is take an image, create quads, darken its pixels by a certain amount, paste it into Image Data or a Canvas, create quads for the next darkness level, darken them again this time by 2 steps, paste them in, create the quads, repeat until completely dark.

It's easier. And that example has nothing to do with this. That's a completely different method for a completely different game type.

So basically, I just need code to take an image, manipulate its pixels, draw it to something that can be chopped up into Quads. Easy as pie.
User avatar
MarekkPie
Inner party member
Posts: 587
Joined: Wed Dec 28, 2011 4:48 pm
Contact:

Re: Take an image and make darker shades of it...

Post by MarekkPie »

LdXSh.png
LdXSh.png (15.01 KiB) Viewed 533 times
vunLR.png
vunLR.png (388 Bytes) Viewed 533 times
This is what would happen with that method. Especially when dealing with tiled images. But if you are dead set on it,

https://love2d.org/wiki/ImageData:mapPixel

The example talks about brightening an image, but you could change it to whatever.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Take an image and make darker shades of it...

Post by Jasoco »

I'm probably going about it completely wrong. Ignore this thread for now.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Take an image and make darker shades of it...

Post by vrld »

Just drawing the images with a dark color would not work? I.e.:

Code: Select all

love.graphics.setColor(255 * lightness, 255 * lightness, 255 * lightness)
love.graphics.draw(img, x,y)
Could you make an image of the effect you want to achieve?
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Take an image and make darker shades of it...

Post by Jasoco »

No, that's exactly how I wanted to do it. And how I figured it out. But I was hoping I could make it so I could have images fading to different colors so I could use fog with white or red tint or green. But i created a separate thread for that.
User avatar
trookat
Prole
Posts: 18
Joined: Sun Nov 14, 2010 12:32 pm
Location: Western Australia
Contact:

Re: Take an image and make darker shades of it...

Post by trookat »

can't you just ;
copy imgdata to new framebuffer, set the color black and then use the alpha to control lighting levels,draw a poly over the tile, then use that to make quads from?
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Take an image and make darker shades of it...

Post by Jasoco »

I would have to make quads for every single column of every single tile in every single color that I want to use.

With 64 pixel tiles, that's 64 quads per tile times number of tiles times number of colors.

Of course I could reuse the same quads, but then I'd need to make multiple canvases for each color instead. I'm already overusing canvases as it is.
User avatar
hryx
Party member
Posts: 110
Joined: Mon Mar 29, 2010 2:28 am
Location: SF<CA<USA

Re: Take an image and make darker shades of it...

Post by hryx »

Jasoco wrote:But I was hoping I could make it so I could have images fading to different colors so I could use fog with white or red tint or green.
You can just do what vrld said but multiple times in one draw, right?

Code: Select all

-- Image 1, red tint
love.graphics.setColor(255 * lightness, 180 * lightness, 180 * lightness)
love.graphics.draw(img1, x1,y1)
-- Image 2, green tint
love.graphics.setColor(180 * lightness, 255 * lightness, 180 * lightness)
love.graphics.draw(img2, x2,y2)
-- Image 3, blue tint
love.graphics.setColor(180 * lightness, 180 * lightness, 255 * lightness)
love.graphics.draw(img3, x3,y3)
Or maybe I don't understand what you're trying to do.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest