So I have lighting in my game, however I came across an issue - the shadows are drawn on the background. I need a way of preventing the shadows from being drawn on the background. Here's the problem I came across:
The orange'ish color is the background, and obviously, it should be void of any light being drawn over it.
How do I prevent that? Use a shader? And if so, what kind? Any examples?
Now, not all backgrounds should be void of the lighting. Here's an example of the background that does receive the lighting and should stay that way:
Preventing lighting from being drawn on the background
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Preventing lighting from being drawn on the background
Probably using a canvas for the foreground (everything BUT the background) that is shaded and drawing it ontop of the unshaded background.
[wiki]Canvas[/wiki]
EDIT: I sure hope you're using spritebatches for those tiles. (Just mentioning because alot of draw calls is WAAAY more expensive than one draw call with a spritebatch)
[wiki]Canvas[/wiki]
EDIT: I sure hope you're using spritebatches for those tiles. (Just mentioning because alot of draw calls is WAAAY more expensive than one draw call with a spritebatch)
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Preventing lighting from being drawn on the background
That won't do anything.Zer0 wrote:Probably using a canvas for the foreground (everything BUT the background) that is shaded and drawing it ontop of the unshaded background.
[wiki]Canvas[/wiki]
Re: Preventing lighting from being drawn on the background
What method are you using for drawing the lighting? Is it a shader or a mesh or something else?
Check out my blog on gamedev
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Preventing lighting from being drawn on the background
It's a spritebatch.micha wrote:What method are you using for drawing the lighting? Is it a shader or a mesh or something else?
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Preventing lighting from being drawn on the background
Show us the code. Give us a .love file showing the issue. Otherwise it's too difficult to help you.
When I write def I mean function.
Re: Preventing lighting from being drawn on the background
A spriteBatch like 1 sprite per pixel? *cough* inefficient *cough*Whatthefuck wrote:It's a spritebatch.micha wrote:What method are you using for drawing the lighting? Is it a shader or a mesh or something else?
I was guessing for a shader and you did not really explain how you did the lightning.
1. Draw the background
2. Start drawing to canvas with lightning shader
3. Draw everything shaded
4. Draw the canvas
If you don't want to use a shader for some reason use a stencil.
1. Draw background without lightning
2. Use the foreground as a stencil and draw it.
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Preventing lighting from being drawn on the background
1 sprite per 20x20 pixels, it's actually pretty efficient (not THE most efficient method but for a person who has no clue how to write shaders and in the way I use it, it produces good results). And no, I don't use any shaders.Zer0 wrote:A spriteBatch like 1 sprite per pixel? *cough* inefficient *cough*Whatthefuck wrote:It's a spritebatch.micha wrote:What method are you using for drawing the lighting? Is it a shader or a mesh or something else?
I was guessing for a shader and you did not really explain how you did the lightning.
1. Draw the background
2. Start drawing to canvas with lightning shader
3. Draw everything shaded
4. Draw the canvas
If you don't want to use a shader for some reason use a stencil.
1. Draw background without lightning
2. Use the foreground as a stencil and draw it.
The background is just the default one with the colors being changed via love.graphics.setBackgroundColor.
How would I use a stencil for that?
For reference, the finalized lighting is drawn into a separate canvas, which is then upscaled.
Last edited by Whatthefuck on Fri Jul 25, 2014 8:41 am, edited 2 times in total.
-
- Party member
- Posts: 106
- Joined: Sat Jun 21, 2014 3:45 pm
Re: Preventing lighting from being drawn on the background
There's so much code and stuff that I'd have to spend hours to pack everything into a separate .love file.kikito wrote:Show us the code. Give us a .love file showing the issue. Otherwise it's too difficult to help you.
Edit: argh, no automerge. ;_;
Re: Preventing lighting from being drawn on the background
Whatthefuck wrote:How would I use a stencil for that?
Code: Select all
draw_background()
love.graphics.setStencil(draw_foreground())
draw_foreground()
love.graphics.setStencil()
setStencil says you ONLY draw to where the stencil draws. (the stencil is just a function with stuff that is drawn)
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Who is online
Users browsing this forum: Bing [Bot] and 1 guest