Shaders and FBOs

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Shaders and FBOs

Post by Robin »

nevon wrote:This so needs to find its way into Löve.
Agreed.
Help us help you: attach a .love.
User avatar
Chief
Party member
Posts: 101
Joined: Fri Mar 12, 2010 7:57 am
Location: Norway, 67° north

Re: Shaders and FBOs

Post by Chief »

This would be so cool for effects like, if a character dies the colors invert, etc. etc. etc! Awesome! Just AWESOME!
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Shaders and FBOs

Post by ljdp »

you will need an fbo and then check for foreground color there
How does one check for foreground color?
I want to be able to layer FBOs on top of each other, like stamps.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Shaders and FBOs

Post by Robin »

ljdp wrote:How does one check for foreground color?
love.graphics.getColor()?
Help us help you: attach a .love.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Shaders and FBOs

Post by vrld »

How does one check for foreground color?
What I meant was:
  1. Render to fbo.
  2. Use fragment shader with fbo as alpha mask.
  3. ???
  4. Profit.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
ljdp
Party member
Posts: 209
Joined: Sat Jan 03, 2009 1:04 pm
Contact:

Re: Shaders and FBOs

Post by ljdp »

Well I made a shader that makes black pixels transparent

Code: Select all

uniform sampler2D tex0;

void main(void)
{
    vec4 col = texture2D(tex0, gl_TexCoord[0].st);
    if(col[0] == 0.0 && col[1] == 0.0 && col[2] == 0.0)
	{
		col[3] = 0.0;
	}
    gl_FragColor = col;
}
Using this, and the glBlendFunc( GL_ZERO, GL_ONE_MINUS_SRC_ALPHA ) function I can make portal effects
like in ASCIIpOrtal.

Chect it out here: http://vimeo.com/14015078
It still needs work, especially how to deal with travelling through the portal.
I'll upload the source soon but I'll also need to give you the patch to add the extra blendmode constant.
McP
Prole
Posts: 4
Joined: Sat Aug 14, 2010 1:54 am

Re: Shaders and FBOs

Post by McP »

Anyone got a compiled windows version
pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

Re: Shaders and FBOs

Post by pekka »

I still haven't gotten around to compiling this, because installing dev libs is teh bore. Sorry for almost promising I'd do it earlier in the thread...

I'd like to extend my wishes for Löve treating OpenGL in the same sensible and sane way that the SFML library does, for example. It provides helpful information that your computer does not support PostFX (its term for shader programs), instead of crashing mysteriously. Surely Löve devs will do the same and not just tell people with OpenGL 1.X implementations to go suck it. Right? Right??

You could, for example, install a virtualized OS with only software OpenGL support and test Löve regularly on it. Just so you will know it won't break for people with legacy hardware.

This is important for me because if I am going to publish some games with Löve (it remains a possiblity), I want as many people as possible to be able to enjoy them. I'm switching to something like SFML and Python for good otherwise.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Shaders and FBOs

Post by vrld »

This is in no way meant to be complete nor part of the official LÖVE branch.
The Framebuffer object as seen here will fail gracefully (first trying to use >=OpenGL3 functions, then the extension and then telling it won't work). I think the same would be true for shaders.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Shaders and FBOs

Post by vrld »

I created a branch of the love mercurial repository called love-glsl. As you might have guessed this aims to include GLSL-Shader support to LÖVE.
It is based on the patch in this thread but has a different API:

status = love.graphics.hasShaders()
true if shaders are supported (GL version >= 2.0 and GL_ARB_shader_objects present)

version = love.graphics.getGLSLVersion()
Returns the GLSL version.

shader = love.graphics.newShader()
Creates a new Shader(-program, to be exact)

love.graphics.setShader( shader )
Sets the current shader to 'shader' or uses no shader if argument is nil or omitted. (equivalent to the previous program:use() and program:unuse())

status = Shader:addCode(type, code)
Adds shader code to the program.
type has to be one of 'vertex' or 'fragment' and determines the shader type (duh)
code has to be a string containing GLSL code
status is true if everything went fine, false otherwise. For how to get compile errors, see Shader:compile()

Shader:compile()
Tries to compile (actually link) the shader. Will throw an error with compiler and linker messages if anything went wrong.

log = Shader:infolog()
Returns the a string with error and warning messages of the compile process.

Shader:setUniform(name, u1, u2, u3, u4)
Sets the uniform value with name name to (u1,u2,u3,u4). u2 to u4 can be omitted.
The uniform type is assumed to be float.

Shader:setUniform(name, type, u1, u2, u3, u4)
Same as above, but with type either being "float" or "int".

Shader:setUniformMatrix(name, rows, cols, u1,u2,...u[rows*cols])
Sets a uniform matrix. You need to supply exactly rows*cols numbers.

Shader:setSampler(name, image, unit)
Sets uniform sampler ("uniform sampler2D") value to the texture of the Image object image.
unit can be omitted in which case it defaults to 0.

u1,u2,...,u16 = Shader:getSampler(name, type)
Returns the value of a named uniform. Unused values will be nan or 3735928559 if type is int.
type is either float or int but can be omitted in which case float is assumed.

I attached an updated version of the particles with shaders thing.

Please post any issues/feature requests to the bitbucket repo at http://bitbucket.org/vrld/love-glsl
Attachments
particles.love
(18.22 KiB) Downloaded 140 times
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Post Reply

Who is online

Users browsing this forum: No registered users and 59 guests