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
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Hi! Two quick questions.

Has anyone used 'kernels' with PixelEffect(is it possible)?

The IM library has:

Code: Select all

image, error = im.FileImageLoad(filename)
r,g,b,a = image[0],image[1],image[2],image[3]
Does Love have a similiar way to get the red, green, blue & alpha channels.
I know about:

Code: Select all

r,g,b,a = love.graphics,getColor()
but that is for only a single pixel.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Oh no! Another shader.
Just a cross between 'tunnel' and 'shockwave'.
For what it's worth.
Played with meatballs(metaballs) but still haven't got complete control over it.
Are there other hidden features in GLSL?
Attachments
puddle.love
Radiating waves
(50.28 KiB) Downloaded 2040 times
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Just a varient of vrid's metaballs.
Don't really know how you would use it in a game.
Leave that up to the more eventuresome. :joker:
Best
Attachments
donuts.love
(50.44 KiB) Downloaded 2002 times
User avatar
StoneCrow
Party member
Posts: 199
Joined: Sat Apr 17, 2010 9:31 am
Location: Wales the land of leeks and leaks
Contact:

Re: Share a Shader!

Post by StoneCrow »

Been trying to get the film grain effect from here to work but having no joy at all, anyone got any tips or can tell me if it would work anyway.

Code: Select all

effect2 = love.graphics.newPixelEffect[[
	extern number time;

	extern bool grayscale;

	// noise effect intensity value (0 = no effect, 1 = full effect)
	extern number nIntensity;

	// scanlines effect intensity value (0 = no effect, 1 = full effect)
	extern number sIntensity;

	// scanlines effect count value (0 = no effect, 4096 = full effect)
	extern number sCount;

	extern Image tDiffuse;

	extern vec2 rand;
	
	vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc)
	{
		vec4 cTextureScreen = Image( tDiffuse, rand );
		
		number x = rand.x * rand.y * time * 1000.0;
		x = mod( x, 13.0 ) * mod( x, 123.0 );
		number dx = mod( x, 0.01 );
	
		vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx * 100.0, 0.0, 1.0 );
		
		vec2 sc = vec2( sin( rand.y * sCount ), cos( rand.y * sCount ) );
		
		cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;
		
		cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );
		
		if( grayscale ) {

			cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );

		}
		
		return vec4( cResult, cTextureScreen.a );
	
	}
	]]
Dull but sincere filler.
User avatar
Patalo
Prole
Posts: 41
Joined: Sun Apr 29, 2012 1:15 pm
Contact:

Re: Share a Shader!

Post by Patalo »

I think that "extern vec2 rand;" should not be an extern.
The "vUv" vector is probably simply tc (or pc, I always invert these two).
Note that I'm not sure at all, but the way you have written it, every pixel is always the same color.
Current project : 3D fractal explorer DEFract ( viewtopic.php?t=9193)
Github : https://github.com/plule/ | Twitter : http://twitter.com/plule_
User avatar
StoneCrow
Party member
Posts: 199
Joined: Sat Apr 17, 2010 9:31 am
Location: Wales the land of leeks and leaks
Contact:

Re: Share a Shader!

Post by StoneCrow »

haha okay thanks, Ill take another crack at it :)
Dull but sincere filler.
User avatar
Patalo
Prole
Posts: 41
Joined: Sun Apr 29, 2012 1:15 pm
Contact:

Re: Share a Shader!

Post by Patalo »

Oh two other things.
- I think that his "tDiffuse" texture is the input texture, so it should simply be the "tex" parameter of the effect function. (if you are not printing texture, I think that cTextureScreen is the "color" parameter. Here is another subtility I haven't totally understood :crazy: )
- I'm not sure you can send boolean value with LÖVE, there is only float, matrix and texture sending functions. (so the extern bool grayscale should be treated with a float. Or just by commenting/uncommenting the line in if(grayscale))

I'll give a try, I'm quite interested in the result (I'm on a game with home-made CRT screen effects, there's some effects that are not really convincing)

Good luck! Let us know if you got some result!
Current project : 3D fractal explorer DEFract ( viewtopic.php?t=9193)
Github : https://github.com/plule/ | Twitter : http://twitter.com/plule_
User avatar
richapple
Citizen
Posts: 65
Joined: Sun Dec 25, 2011 10:25 am

Re: Share a Shader!

Post by richapple »

I wanted to do it long time before, since I saw that big snippet in wiki.
I'm talking about HSV snippet.

old wiki snippet:

Code: Select all

vec3 HSV(float h, float s, float v)
{
	if (s <= 0 ) { return vec3 (0.0); }
	h = h * 6;
	float c = v*s;
	float x = (1-abs((mod(h,2)-1)))*c;
	float m = v-c;
	float r = 0.0;
	float g = 0.0;
	float b = 0.0;

	if (h < 1) { r = c; g = x;b = 0.0;}
	else if (h < 2) { r = x; g = c; b = 0.0; }
	else if (h < 3) { r = 0.0; g = c; b = x; }
	else if (h < 4) { r = 0.0; g = x; b = c; }
	else if (h < 5) { r = x; g = 0.0; b = c; }
	else  { r = c; g = 0.0; b = x; }

	return vec3(r+m,g+m,b+m);
}
from pouet.net which probably took somewhere else too:

Code: Select all

vec3 HSV(float h,float s,float v)
{
	return mix(vec3(1.),clamp((abs(fract(h+vec3(3.,2.,1.)/3.)*6.-3.)-1.),0.,1.),s)*v;
}
Here's the demo for those who want it:
Hue.love
Small demo
(1.01 KiB) Downloaded 11714 times
And before I edit that page, should I remove the old snippet?
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 »

Just wanted to drop a thanks into this thread for all the great examples. Using this and the wiki I managed to write a pixelEffect in minutes.

Thanks guys! ooking forward to seeing more crazy stuff. ^.^

Edit: Actually, I have a question regarding this post:

vrld wrote:A simpler, but not necessarily faster bloom-like effect can be done by oversaturated blurring (code untested):

Code: Select all

bloom = love.graphics.newPixelEffect [[
vec2 image_size;

vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc)
{
    vec2 pixel_offset = vec2(1.0)/image_size;
    color = Texel(tex, tc); // maybe add a weight here?

    color += Texel(tex, tc + vec2(-offset.x, offset.y));
    color += Texel(tex, tc + vec2(0, offset.y));
    color += Texel(tex, tc + vec2(offset.x, offset.y));

    color += Texel(tex, tc + vec2(-offset.x, 0));
    color += Texel(tex, tc + vec2(0, 0));
    color += Texel(tex, tc + vec2(offset.x, 0));

    color += Texel(tex, tc + vec2(-offset.x, -offset.y));
    color += Texel(tex, tc + vec2(0, -offset.y));
    color += Texel(tex, tc + vec2(offset.x, -offset.y));

    return color / 9.0; // use 10.0 for regular blurring.
}
]]
How would I get the above pixelEffect to work? Assuming that this shader is complete here, what exactly do you pass to image_size? Surely tables don't work.
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.
User avatar
Patalo
Prole
Posts: 41
Joined: Sun Apr 29, 2012 1:15 pm
Contact:

Re: Share a Shader!

Post by Patalo »

Well, I took StoneCrow's code to finish the adaptation of the film effect (I hope you don't mind :3 )
It works pretty well, I think I will take some parts for my project. The desaturation/illumination that comes with the grain is really cool.
Attachments
film.love
(208.76 KiB) Downloaded 1027 times
Current project : 3D fractal explorer DEFract ( viewtopic.php?t=9193)
Github : https://github.com/plule/ | Twitter : http://twitter.com/plule_
Post Reply

Who is online

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