Page 9 of 33
Re: Share a Shader!
Posted: Thu May 24, 2012 3:17 pm
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.
Re: Share a Shader!
Posted: Sat May 26, 2012 9:30 pm
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?
Re: Share a Shader!
Posted: Mon May 28, 2012 7:54 pm
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.
Best
Re: Share a Shader!
Posted: Mon Jun 04, 2012 10:58 pm
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 );
}
]]
Re: Share a Shader!
Posted: Tue Jun 05, 2012 9:11 pm
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.
Re: Share a Shader!
Posted: Wed Jun 06, 2012 9:11 am
by StoneCrow
haha okay thanks, Ill take another crack at it
Re: Share a Shader!
Posted: Wed Jun 06, 2012 11:03 am
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
)
- 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!
Re: Share a Shader!
Posted: Wed Jun 06, 2012 11:20 am
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 11748 times
And before I edit that page, should I remove the old snippet?
Re: Share a Shader!
Posted: Thu Jun 07, 2012 8:17 am
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.
Re: Share a Shader!
Posted: Thu Jun 07, 2012 2:39 pm
by Patalo
Well, I took StoneCrow's code to finish the adaptation of the film effect (I hope you don't mind
)
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.