Share 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.
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Share a Shader!

Post by Ratchet »

Can someone make a shader that makes a monitor bulge effect like this?
Mari0 has a shader like this but I don't know how to use it in 0.9.0.
Image
macOS 10.14 Mojave | LÖVE 11.2
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Share a Shader!

Post by retrotails »

Ratchet wrote:Can someone make a shader that makes a monitor bulge effect like this?
Mari0 has a shader like this but I don't know how to use it in 0.9.0.
Image
I don't even need to post a .love to demonstrate this.
Take a shader from the Mari0 .love, such as CRT.frag, and store it with main.lua.

Code: Select all

function love.load()
  canvas = love.graphics.newCanvas()
  local str = love.filesystem.read('CRT.frag')
  shader = love.graphics.newShader(str)
  shader:send('inputSize', {love.graphics.getWidth(), love.graphics.getHeight()})
  shader:send('textureSize', {love.graphics.getWidth(), love.graphics.getHeight()})
end
function love.draw()
  love.graphics.setCanvas(canvas)
  --draw stuff here
  love.graphics.setCanvas()
  love.graphics.setShader(shader)
  love.graphics.draw(canvas)
  love.graphics.setShader()
end
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Share a Shader!

Post by Ratchet »

Fantastic, thanks!

EDIT: Is there a way to make the scanlines more transparent? Everything looks so dark. Maybe a alpha of 0.5 for the scanlines would be nice
macOS 10.14 Mojave | LÖVE 11.2
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Share a Shader!

Post by retrotails »

Ratchet wrote:Fantastic, thanks!

EDIT: Is there a way to make the scanlines more transparent? Everything looks so dark. Maybe a alpha of 0.5 for the scanlines would be nice
Increase the last number in line 124 of CRT.frag. 0.5 seems okay.

Code: Select all

vec4 weights = vec4(distance / 0.5);
User avatar
Ratchet
Citizen
Posts: 67
Joined: Mon Apr 08, 2013 10:32 am

Re: Share a Shader!

Post by Ratchet »

Much much better, thank you :awesome:
I played with all these values, of cause this one I forgot... (And I'm too stupid to understand these complex math thingys)
macOS 10.14 Mojave | LÖVE 11.2
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Share a Shader!

Post by Helvecta »

beforan wrote:this is pretty simple stuff, and sorry if it's duplicated but I couldn't find one from cursory searching:

a colour cycling shader!
Thanks for posting that shader! I'm learning how to use them too, and so I decided to try and base something off of yours, just without the brightness problems associated with making RGB values follow a sine wave pattern

Image

Code's below for whoever wants it :)
Attachments
HueShift.love
Works for 0.9.0+
(31.19 KiB) Downloaded 605 times
"Bump." -CMFIend420
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

For the Shader challenged, you could just change

Code: Select all

gfx.setColor(255, 255, 255)
gfx.print("Increase/Decrease transition speed: Up/Down")
gfx.setShader(shader)
gfx.draw(img, wdw.getWidth() / 2 - img:getWidth() / 2, wdw.getHeight() / 2 - img:getHeight() / 2)
gfx.setShader()
to

Code: Select all

gfx.print("Increase/Decrease transition speed: Up/Down")
gfx.setColor( 255 * c[1], 255 * c[2], 255 * c[3] )
gfx.draw(img, wdw.getWidth() / 2 - img:getWidth() / 2, wdw.getHeight() / 2 - img:getHeight() / 2)
and forget about Shaders.
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Share a Shader!

Post by Helvecta »

:( Aw crap
Yeah, but shaders!


EDIT: let's make this post more constructive! Zoom-blur shader, ported (and simplified) from here:

Code: Select all

extern float strength;

vec4 effect(vec4 color, Image tex, vec2 tC, vec2 pC){
	float[10] sample;
	for(int i = 0; i < 10; i++){
		sample[i] = (i - 5) / strength;
	}
	
	vec2 dir = (.5 - tC) * -1;
	float dist = sqrt(dir.x * dir.x + dir.y * dir.y);
	dir = dir/dist;
	
	vec4 c = Texel(tex, tC);
	vec4 sum = color;
	
	for(int i = 0; i < 10; i++){
		sum += Texel(tex, tC + dir * sample[i] * strength / 50);
	}
	
	sum /= 10;
	
	float t = dist * strength;
	t = clamp(t, 0, 1);
	
	return mix(c, sum, t);
}
Also a similarly-coded spotlight shader:

Code: Select all

extern float strength;

vec4 effect(vec4 color, Image tex, vec2 tC, vec2 pC){
	vec2 dir = .5 - tC;
	float dist = sqrt(dir.x * dir.x + dir.y * dir.y);
	
	vec4 c = Texel(tex, tC);
	
	float t = dist * strength;
	t = clamp(t, 0, 1);
	
	return mix(c, vec4(0), t);
}
Sorry if someone has already done this :?
"Bump." -CMFIend420
User avatar
OmarShehata
Party member
Posts: 259
Joined: Tue May 29, 2012 6:46 pm
Location: Egypt
Contact:

Re: Share a Shader!

Post by OmarShehata »

Just made a smoke shader. Was really interested about trying shaders that "propagate". By that I mean, shaders that have an initial state and build off it. Had to use two canvases to maintain the previous state and feed it back to the shader.

It's actually based off this paper. The algorithm itself can be summarized in one line (with the rest setting everything up), that being the one that sets the current pixel's alpha value, to the neighboring pixel's values with a certain factor.

Image
Attachments
Smoke.love
(1.28 KiB) Downloaded 2686 times
User avatar
Lafolie
Inner party member
Posts: 809
Joined: Tue Apr 05, 2011 2:59 pm
Location: SR388
Contact:

Re: Share a Shader!

Post by Lafolie »

Really pretty, OmarShehata! I was playing around with it just now, if you 'paint' at the very bottom of the window the effect freezes. I didn't look at the source but I assume it's because the pixels at the bottom never change their alpha values (since there's nothing to sample below them).
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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 15 guests