Preventing lighting from being drawn on the background

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
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Preventing lighting from being drawn on the background

Post by micha »

How about this solution: Draw the foreground to a canvas, draw this canvas on screen. Then draw the shades, using the foreground canvas as a mask. See the wiki about stencils, at the bottom, there is a section about "Using an Image as a mask".
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Preventing lighting from being drawn on the background

Post by Whatthefuck »

Zer0 wrote:

Code: Select all

    draw_background()
    love.graphics.setStencil(draw_foreground())
    draw_foreground()
    love.graphics.setStencil()
[wiki]love.graphics.setStencil[/wiki]
setStencil says you ONLY draw to where the stencil draws. (the stencil is just a function with stuff that is drawn)
I can't draw the background manually, remember? The background is the default background that comes with love2d, color of which you can modify via love.graphics.setBackgroundColor.

Though I could make my own background.
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Preventing lighting from being drawn on the background

Post by Zer0 »

Whatthefuck wrote: I can't draw the background manually, remember? The background is the default background that comes with love2d, color of which you can modify via love.graphics.setBackgroundColor.

Though I could make my own background.
Let me fix the code then.

Code: Select all

    do_not_draw_background()
    love.graphics.setStencil(draw_foreground())
    draw_foreground()
    love.graphics.setStencil()
stencil should not mess with backgroundcolor
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Preventing lighting from being drawn on the background

Post by micha »

Using a plain vanilla stencil will only work in restricted cases. If the foreground is made of image with "holes" in it (=transparency) then a stencil will not work. A stencil function always considers the full rectangle of an image.
A solution is given on the wiki-page on stencils (see post above).
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Preventing lighting from being drawn on the background

Post by Whatthefuck »

micha wrote:Using a plain vanilla stencil will only work in restricted cases. If the foreground is made of image with "holes" in it (=transparency) then a stencil will not work. A stencil function always considers the full rectangle of an image.
A solution is given on the wiki-page on stencils (see post above).
Interesting, I actually tried doing what you linked me to prior to making this thread, but it did not work. I guess I did something wrong.
Will try again.
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Preventing lighting from being drawn on the background

Post by Whatthefuck »

Guys, I love you, no homo. You helped me achieve exactly what I needed.

You fucking rock.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Preventing lighting from being drawn on the background

Post by micha »

Could you post a screenshot of the result? I am interested.
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Preventing lighting from being drawn on the background

Post by Whatthefuck »

micha wrote:Could you post a screenshot of the result? I am interested.
https://love2d.org/imgmirrur/Ct7Ijsz.png

Using [img] tags doesn't even make it fit in here, so have a link instead. :V
Last edited by Whatthefuck on Sat Jul 26, 2014 5:03 pm, edited 1 time in total.
Whatthefuck
Party member
Posts: 106
Joined: Sat Jun 21, 2014 3:45 pm

Re: Preventing lighting from being drawn on the background

Post by Whatthefuck »

Whatthefuck wrote:
micha wrote:Could you post a screenshot of the result? I am interested.
Sure.

https://love2d.org/imgmirrur/Ct7Ijsz.png

Using [img] tags doesn't even make it fit in here, so have a link instead. :V

Edit: oops, double post. D:

Here, have another one that I took while it was raining in-game: https://love2d.org/imgmirrur/J6CY1rx.png
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Preventing lighting from being drawn on the background

Post by micha »

Thanks.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 7 guests