Help with a shader.

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
dncwalk99
Prole
Posts: 2
Joined: Tue Jun 26, 2012 10:26 pm

Help with a shader.

Post 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?
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: Help with a shader.

Post 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
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Help with a shader.

Post 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)
dncwalk99
Prole
Posts: 2
Joined: Tue Jun 26, 2012 10:26 pm

Re: Help with a shader.

Post 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?
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Help with a shader.

Post 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)
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 5 guests