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
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Share a Shader!

Post 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 1071 times
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
slime
Solid Snayke
Posts: 3161
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Share a Shader!

Post by slime »

blurshader.love
Fixed x2
(408.88 KiB) Downloaded 1806 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.
Last edited by slime on Mon Oct 24, 2011 4:10 pm, edited 1 time in total.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Share a Shader!

Post by GijsB »

can you please write my name correct at the first post :P?
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Share a Shader!

Post by RPG »

Shaders in LOVE looks strange... Is this glsl?
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Share a Shader!

Post 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.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Share a Shader!

Post by RPG »

And how can I load native glsl shader?
User avatar
slime
Solid Snayke
Posts: 3161
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Share a Shader!

Post 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
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Share a Shader!

Post 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.
User avatar
thelinx
The Strongest
Posts: 857
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

Re: Share a Shader!

Post 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.
User avatar
RPG
Party member
Posts: 157
Joined: Wed Mar 02, 2011 5:02 am
Location: Russia
Contact:

Re: Share a Shader!

Post by RPG »

effectCodeToGLSL

but not GLSLToeffectCode?
Post Reply

Who is online

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