Page 2 of 33

Re: Share a Shader!

Posted: Wed Oct 12, 2011 10:43 am
by vrld
There are two things you can change: the metaball equation and the threshold in if (d <= .0007).
The equation defines the gooeyness of the balls, whereas the threshold defines the size. Changing the eqation usually requires to change the threshold too. For example:

Code: Select all

float metaball(vec2 x)
{
	return 1.0 / sqrt(dot(x, x));
}

vec4 effect(vec4 color, Image tex, vec2 tc, vec2 pc)
{
	float d = metaball(pc - balls[0]) + metaball(pc - balls[1]) + metaball(pc - balls[2]);
	if (d <= .03)
		return vec4(1.0);
	return vec4(0.0);
}
You can also directly use the distance value d as color to get glowy things, or discretize it, to get something that resembles height lines.
metaballs.love
metaballs²
(666 Bytes) Downloaded 1051 times

Re: Share a Shader!

Posted: Fri Oct 14, 2011 9:26 pm
by slime
blurshader.love
Fixed x2
(408.88 KiB) Downloaded 1789 times
full-screen blur shader.

EDIT: Holy shit. This is why it's always a really good idea to test out optimizations for shader code. I manually unrolled the for-loop (it was only looping twice), and on my Intel HD 3000 I went from 1.32ms frame time with no blur and 21.28ms frame time with blur on, to 1.59ms frame time with blur on! Intel cards suck at for-loops!

You could also probably shrink the canvas size and scale everything, and then scale back up when rendering to improve performance a bit.

Re: Share a Shader!

Posted: Sun Oct 16, 2011 7:41 am
by GijsB
can you please write my name correct at the first post :P?

Re: Share a Shader!

Posted: Sun Oct 16, 2011 5:43 pm
by RPG
Shaders in LOVE looks strange... Is this glsl?

Re: Share a Shader!

Posted: Sun Oct 16, 2011 5:47 pm
by thelinx
See PixelEffect.
These effects are written in a language based on GLSL (OpenGL Shading Language) with a few things simplified for easier coding.
Iirc it's GLSL with a few variable types renamed to be more LÖVEly.

Re: Share a Shader!

Posted: Sun Oct 16, 2011 5:52 pm
by RPG
And how can I load native glsl shader?

Re: Share a Shader!

Posted: Sun Oct 16, 2011 6:00 pm
by slime
RPG wrote:And how can I load native glsl shader?
It's much better practice to convert your native shader code to love standards - which isn't hard at all, but if you absolutely can't for some reason...

Code: Select all

function love.graphics._effectCodeToGLSL(code) return code end
The PixelEffect changes from regular GLSL are outlined more in the readme here: https://bitbucket.org/vrld/love-glsl

Re: Share a Shader!

Posted: Sun Oct 16, 2011 6:29 pm
by RPG
slime wrote:
RPG wrote:And how can I load native glsl shader?
It's much better practice to convert your native shader code to love standards
I don't think so. love is not the only engine in the world that supports shaders, and glsl shaders must be easily ported between engines. GLSL is standart and it was developed to be the standart.
which isn't hard at all
I have 1000's lines of glsl shaders in more than 20 fragment programs. Too bad that love does not support them in a clean form.

Re: Share a Shader!

Posted: Sun Oct 16, 2011 6:32 pm
by thelinx
Slime did post a solution for you, if you really want to use your raw GLSL shaders.

Code: Select all

function love.graphics._effectCodeToGLSL(code) return code end
Just put that somewhere in your code and you should be able to load regular shaders.

Re: Share a Shader!

Posted: Sun Oct 16, 2011 6:36 pm
by RPG
effectCodeToGLSL

but not GLSLToeffectCode?