Pixel art with GLSL cel shade lighting concept

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Pixel art with GLSL cel shade lighting concept

Post by Boolsheet » Fri Sep 28, 2012 8:36 am

kikito wrote:The sprites look like random color noise
This is just a guess, but it may be because the shader uses a uninitialized variable.

Code: Select all

   vec3 light; // <-- Could be any value at this point.
   for (int i = 0; i < light_position.length(); i++) {      
      vec3 light_direction = light_position[i] - vec3(pixel_coords, 0);
      float dist = length(light_direction);
      float attenuation = smoothstep(100, 50, dist);
      light_direction = normalize(light_direction);
      vec3 current_light = light_diffuse[i] * attenuation * clamp(dot(normal, light_direction), 0.0, 1.0);
      //light += light_diffuse[i] * attenuation * clamp(dot(normal, light_direction), 0.0, 1.0);
      if (length(current_light) > length(light)) { // <-- Usage of uninitialized variable. If light has random bits, there is a very high chance this will always be false.
         light = current_light;
      }
   }
Shallow indentations.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Pixel art with GLSL cel shade lighting concept

Post by Robin » Fri Sep 28, 2012 11:13 am

This so unbelievably cool! I can't wait to see a game with cell-shaded pixel art. :D
Help us help you: attach a .love.

User avatar
felix24
Party member
Posts: 163
Joined: Tue Jul 26, 2011 4:51 pm
Contact:

Re: Pixel art with GLSL cel shade lighting concept

Post by felix24 » Fri Sep 28, 2012 12:21 pm

you sir are a legend. this is sooooo coooool :ultrahappy:

GarbagePillow
Prole
Posts: 41
Joined: Wed Sep 26, 2012 9:19 pm

Re: Pixel art with GLSL cel shade lighting concept

Post by GarbagePillow » Fri Sep 28, 2012 4:25 pm

Thanks for the kind words Dreadkillz, Robin, Felix. :)
kikito wrote:Unfortunately none of the multi-lighted examples seem to work on my machine (Mac Book Air 2012 13')

The sprites look like random color noise:
The attachment screenshot.png is no longer available
The first two examples (with only one light source) looked great though.
Ughhh, sorry about that. At least it looks... interesting. Hopefully the new one will work. Let me know if it's still broken.
Boolsheet wrote:
kikito wrote:The sprites look like random color noise
This is just a guess, but it may be because the shader uses a uninitialized variable.

Code: Select all

   vec3 light; // <-- Could be any value at this point.
   for (int i = 0; i < light_position.length(); i++) {      
      vec3 light_direction = light_position[i] - vec3(pixel_coords, 0);
      float dist = length(light_direction);
      float attenuation = smoothstep(100, 50, dist);
      light_direction = normalize(light_direction);
      vec3 current_light = light_diffuse[i] * attenuation * clamp(dot(normal, light_direction), 0.0, 1.0);
      //light += light_diffuse[i] * attenuation * clamp(dot(normal, light_direction), 0.0, 1.0);
      if (length(current_light) > length(light)) { // <-- Usage of uninitialized variable. If light has random bits, there is a very high chance this will always be false.
         light = current_light;
      }
   }
Doh. I guess I was just assuming the values were automatically set to 0. I think I've fixed all those errors with this new version.

Image
Attachments
MultiLights4_2.love
Hopefully fixed bug in MultiLights4.love
(12.44 KiB) Downloaded 667 times
Last edited by GarbagePillow on Fri Sep 28, 2012 4:40 pm, edited 1 time in total.

User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Pixel art with GLSL cel shade lighting concept

Post by Nixola » Fri Sep 28, 2012 4:32 pm

Code: Select all

Error: [string "graphics.lua"]:1346: Invalid operation:
- Trying to send the wrong value type to shader variable, or
- Trying to send array values with wrong dimension, or
- Invalid variable name.
stack traceback:
        [C]: in function 'sendFloat'
        [string "graphics.lua"]:1346: in function 'send'
        main.lua:20: in function 'send_lights'
        main.lua:89: in function 'update'
        [string "boot.lua"]:407: in function <[string "boot.lua"]:373>
        [C]: in function 'xpcall'
Intel G41 Express Chipset, Windows 7 x86


EDIT: Fixed, you were sending two 5-element arrays when the shader expected two 4-element ones, just change lines 2-3 to

Code: Select all

extern vec3 light_position[5]; //it was [4]
extern vec3 light_diffuse[5]; //it was [4]
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics

GarbagePillow
Prole
Posts: 41
Joined: Wed Sep 26, 2012 9:19 pm

Re: Pixel art with GLSL cel shade lighting concept

Post by GarbagePillow » Fri Sep 28, 2012 4:41 pm

Nixola wrote:

Code: Select all

Error: [string "graphics.lua"]:1346: Invalid operation:
- Trying to send the wrong value type to shader variable, or
- Trying to send array values with wrong dimension, or
- Invalid variable name.
stack traceback:
        [C]: in function 'sendFloat'
        [string "graphics.lua"]:1346: in function 'send'
        main.lua:20: in function 'send_lights'
        main.lua:89: in function 'update'
        [string "boot.lua"]:407: in function <[string "boot.lua"]:373>
        [C]: in function 'xpcall'
Intel G41 Express Chipset, Windows 7 x86


EDIT: Fixed, you were sending two 5-element arrays when the shader expected two 4-element ones, just change lines 2-3 to

Code: Select all

extern vec3 light_position[5]; //it was [4]
extern vec3 light_diffuse[5]; //it was [4]
Thanks, I updated it.

I really wish these things didn't run on my computer when they have bugs like this. It's so much harder to fix.

User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Pixel art with GLSL cel shade lighting concept

Post by kikito » Fri Sep 28, 2012 6:24 pm

Now it works ok on my Mac.

This is very hipnotic. I like it.

Although maybe you shouldn't overdo multi-colored lights if you are going for a cell-shaded effect. The previous ones with a single white light looked more "appropiate" somehow. Simpler graphics with simpler effects, I guess.
When I write def I mean function.

User avatar
Lafolie
Inner party member
Posts: 805
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Pixel art with GLSL cel shade lighting concept

Post by Lafolie » Fri Sep 28, 2012 6:56 pm

@Kikito "hypnotic" :)

I have to agree though. Having the the tech to do something doesn't mean you should use it all the time. I imagine you can pull of some impressive scenes but using the coloured lights sparingly, like in a lava-filled cavern or something.
Do you recognise when the world won't stop for you? Or when the days don't care what you've got to do? When the weight's too tough to lift up, what do you? Don't let them choose for you, that's on you.

luaz
Citizen
Posts: 83
Joined: Sun Sep 16, 2012 2:55 pm

Re: Pixel art with GLSL cel shade lighting concept

Post by luaz » Fri Sep 28, 2012 8:04 pm

Pretty awesome for isometric projects!
If you're going to reply to my post, consider posting an (preferably working) example - 99.7% of time time, I already know how to implement the feature theoretically! ;) I don't learn very well from references, etc....

GarbagePillow
Prole
Posts: 41
Joined: Wed Sep 26, 2012 9:19 pm

Re: Pixel art with GLSL cel shade lighting concept

Post by GarbagePillow » Fri Sep 28, 2012 9:06 pm

luaz: Definitely.

Lafolie, Kikito: I also think the single light version was superior visually. It's like how christmas trees with just white lights generally look better than ones with a bunch of colors. But it might be nice to be able to have colored accent lights for certain situations, like lava. Anyways, I just wanted to experiment with it. :) I'm not sure I have the right solution to it yet either... the lights values round and shape the object more than they should. They are not perfect cells.

Another technique that might be interesting with pixel art is 3d look up tables.

Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests