Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411506 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 25, 2024, 10:38:53 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Darkness shader
Pages: [1]
Print
Author Topic: Darkness shader  (Read 1004 times)
Gerrard
Level 0
*



View Profile WWW
« on: November 10, 2015, 03:46:43 AM »

Hello !
I'm new here and I speak french usually, so I hope my post will be fine Wink

I'm working on a game called Pankapu, a 2D platformer. Maybe you already heard about it.
In the game, we have a level in the darkness, and there is a light that follows the character in order to see something.

My shader is simple, it renders all dark except where I put these lights. I use the alpha channel to know how dark it must be (1 => no darkess, 0 => full darkness). It works fine but I have a little problem : when two lights overlap themselves, I take the highest value (seems logical) but as you can see in the screenshot, it looks a little bit weird.

How do you think I can improve that ?
By taking the average around the pixel rendered ?
Or maybe I need to use another alpha blending method than taking the max value ?

Thanks !

Logged

zilluss
Level 1
*



View Profile
« Reply #1 on: November 10, 2015, 04:04:34 AM »

Add the values of the light so two lights will merge into a brighter one.
Logged

@zilluss | Devlog  Hand Point Right
Gerrard
Level 0
*



View Profile WWW
« Reply #2 on: November 10, 2015, 04:08:53 AM »

Thanks, but I already tried that (i forgot to mention it) and it's really not the kind of rendering I want... It doesn't seem natural at all if I add the two lights.
Logged

zilluss
Level 1
*



View Profile
« Reply #3 on: November 10, 2015, 04:49:40 AM »

How do you render the lights? Do you pass them as attributes/uniforms to your shader? Then you know for each pixel how near the closest light is. If there are multiple lights nearby increase the light value of the pixel a little bit, to simulate overlapping lights without the hard look of additive blending.
Logged

@zilluss | Devlog  Hand Point Right
Gerrard
Level 0
*



View Profile WWW
« Reply #4 on: November 10, 2015, 05:00:01 AM »

For now, I render all the lights in a RenderTexture, and after that I use that texture to darken or not the scene.
Your approach seems great, I'll see if I can do something like that ! Thanks.
Logged

epcc
Level 1
*


View Profile
« Reply #5 on: November 13, 2015, 12:27:34 PM »

Additive blending is correct. If it looks weird, it's probably because your light texture is linear instead of quadratic.
It's hard to explain, so see the example textures instead.
Linear:


Quadratic:


Here's the code I generated these images with:
https://gist.github.com/johann2/5ff1546548cc7b2d3144#file-light-py
Logged

Trent
Level 0
***


Someday I'll make games!


View Profile WWW
« Reply #6 on: November 16, 2015, 03:59:05 PM »

Quadratic:


Think you can generate a large version of this? I don't feel like learning the python setup.  Concerned
Logged

Polly
Level 6
*



View Profile
« Reply #7 on: November 16, 2015, 04:18:22 PM »

Think you can generate a large version of this? I don't feel like learning the python setup.

You might want to generate the texture in your engine rather than importing a bitmap ( and use dithering ). Regardless .. here you go.
Logged
Trent
Level 0
***


Someday I'll make games!


View Profile WWW
« Reply #8 on: November 17, 2015, 09:14:43 PM »

Thanks man.  Cool
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic