Shader Question
Posted: Wed Dec 30, 2015 9:38 am
Hi all -
I'm still hard at work on LABWS and tonight I decided to finally start implementing some shader effects. Naturally my first attempt is to figure out how to make a spaceship look like it's splattered with poop.
My first attempt is attached as a .love file. (Press 'space' to reload). I think I have the hang of it, sort of, but I'm sure my code could be much better. I also have a few questions about implementation:
-Are there any fundamental misunderstandings in the way that I've implemented this code that I need to get past before I can be a competent shader coder?
-If I wanted each enemy ship to keep track of multiple splatters, how would I tell the shader to render multiple splatters? Ideally an enemy that gets hit from angle A will have a splatter permanently at angle A; then, later, when it gets hit from angle B, it retains a permanent splatter at angle B. Is there some way of passing data into a shader that gets stored permanently? Or should I just do something like pass in a vec4 of angles every time that the ship gets hit and then use a for loop in the shader to shade every splatter?
-Right now I can only overlay an opaque splatter over the ship (hardcode the pixel color values) or have a semi-transparent overlay (multiply the desired color value by the current pixel value). If I wanted some sort of gradient transparency overlay (i.e., a splatter with variable transparency overlaid on the ship sprite) how would I do that? I have tried just returning pixel values of, for instance, splatter.r * sprite.r * splatter.a, but this doesn't return the results that I want.
Thanks all!
I'm still hard at work on LABWS and tonight I decided to finally start implementing some shader effects. Naturally my first attempt is to figure out how to make a spaceship look like it's splattered with poop.
My first attempt is attached as a .love file. (Press 'space' to reload). I think I have the hang of it, sort of, but I'm sure my code could be much better. I also have a few questions about implementation:
-Are there any fundamental misunderstandings in the way that I've implemented this code that I need to get past before I can be a competent shader coder?
-If I wanted each enemy ship to keep track of multiple splatters, how would I tell the shader to render multiple splatters? Ideally an enemy that gets hit from angle A will have a splatter permanently at angle A; then, later, when it gets hit from angle B, it retains a permanent splatter at angle B. Is there some way of passing data into a shader that gets stored permanently? Or should I just do something like pass in a vec4 of angles every time that the ship gets hit and then use a for loop in the shader to shade every splatter?
-Right now I can only overlay an opaque splatter over the ship (hardcode the pixel color values) or have a semi-transparent overlay (multiply the desired color value by the current pixel value). If I wanted some sort of gradient transparency overlay (i.e., a splatter with variable transparency overlaid on the ship sprite) how would I do that? I have tried just returning pixel values of, for instance, splatter.r * sprite.r * splatter.a, but this doesn't return the results that I want.
Thanks all!