Page 5 of 6

Re: Shaders and FBOs

Posted: Sun Aug 08, 2010 9:23 pm
by Robin
nevon wrote:This so needs to find its way into Löve.
Agreed.

Re: Shaders and FBOs

Posted: Sun Aug 08, 2010 9:59 pm
by Chief
This would be so cool for effects like, if a character dies the colors invert, etc. etc. etc! Awesome! Just AWESOME!

Re: Shaders and FBOs

Posted: Mon Aug 09, 2010 4:06 pm
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.

Re: Shaders and FBOs

Posted: Mon Aug 09, 2010 5:29 pm
by Robin
ljdp wrote:How does one check for foreground color?
love.graphics.getColor()?

Re: Shaders and FBOs

Posted: Mon Aug 09, 2010 5:34 pm
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.

Re: Shaders and FBOs

Posted: Mon Aug 09, 2010 10:38 pm
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.

Re: Shaders and FBOs

Posted: Sun Aug 22, 2010 9:44 pm
by McP
Anyone got a compiled windows version

Re: Shaders and FBOs

Posted: Fri Aug 27, 2010 11:20 am
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.

Re: Shaders and FBOs

Posted: Fri Aug 27, 2010 12:34 pm
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.

Re: Shaders and FBOs

Posted: Mon Sep 06, 2010 6:39 pm
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