Page 1 of 1

Help with a shader.

Posted: Tue Jun 26, 2012 10:32 pm
by dncwalk99
Yea. I've been playing with Love off and on since 6.x days. I like that GLSL shader support was added, but it's way over my head. All I'm trying to do is make a vignette shader that I can use, but I can not wrap my head around it. I've tried looking at code for porting on GLSL Sandbox, but still no luck. Anyone willing to walk me through creating a vignette shader?

Re: Help with a shader.

Posted: Wed Jun 27, 2012 9:07 am
by richapple
I believe It's a simple task: all you got to do is to:
(in shader of course)
  1. Find the distance from the current position to the center of the screen (distance(vec2, vec2) function makes it piss easy)
  2. Maybe tweak it a bit (divide by something like 2)
  3. return vec4(1.-dist, 1.-dist, 1.-dist, 1.)
The last step was not very elegant but I am not sure if return vec4(1.)-vec3(dist) works. It should, haven't checked
If you got stuck, let me know, I may do it again in pseudocode

Re: Help with a shader.

Posted: Wed Jun 27, 2012 7:04 pm
by Xgoff
richapple wrote:I believe It's a simple task: all you got to do is to:
(in shader of course)
  1. Find the distance from the current position to the center of the screen (distance(vec2, vec2) function makes it piss easy)
  2. Maybe tweak it a bit (divide by something like 2)
  3. return vec4(1.-dist, 1.-dist, 1.-dist, 1.)
The last step was not very elegant but I am not sure if return vec4(1.)-vec3(dist) works. It should, haven't checked
If you got stuck, let me know, I may do it again in pseudocode
if it doesnt work then you should be able to do vec4(1.0) - vec4(vec3(dist), 0.0)

Re: Help with a shader.

Posted: Wed Jun 27, 2012 9:25 pm
by dncwalk99
What is the best way to implement this in a way that i can still see my game under the vignette? As i currently understand shaders in love2d.. there is no way. The shader would cover over everything right?

Re: Help with a shader.

Posted: Thu Jun 28, 2012 12:11 am
by Xgoff
dncwalk99 wrote:What is the best way to implement this in a way that i can still see my game under the vignette? As i currently understand shaders in love2d.. there is no way. The shader would cover over everything right?
i haven't tried doing things with shaders that affect the whole screen, so i'm not sure if it's possible to do that directly or if you;d have to draw everything onto a canvas and pass that to the shader instead

but basically, inside the shader you'd simply multiply the fragment color with the result of the vignette (which should be normalized)

EDIT: actually, you could instead just use a screen-size quad for the vignette, and draw that over everything else (in this case, a vignette fragment would be 0, 0, 0 with the alpha being controlled by the vignette output)