Page 1 of 1

How do Love2D shaders work?

Posted: Tue Apr 24, 2012 3:18 pm
by joey_green
This is mostly out of curiosity but:

1. Why is there no vertex shader?
2. Is the vertex shader really in the love2d implementation just hidden from the user?
3. Does the shader code you write need to be GLSL compatible?

I'm actually using love2d for a class project and don't really know the answers to these questions and was hoping someone could shed some light.

Thanks

Re: How do Love2D shaders work?

Posted: Tue Apr 24, 2012 3:28 pm
by Nixola
I don't know anything about shaders, but I remember Thelinx said there's a way to use pure GSGL code, by changing a function

Re: How do Love2D shaders work?

Posted: Tue Apr 24, 2012 6:45 pm
by ncarlson
joey_green wrote: 1. Why is there no vertex shader?
I'm not sure why this design decision was made. One of the core maintainers might be able to answer that.
joey_green wrote: 2. Is the vertex shader really in the love2d implementation just hidden from the user?
No, it's not hidden. If you have a look at love's source code, you'll see that there is no support for vertex shaders.

Code: Select all

GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
There is no similar glCreateShader call for a vertex shader.
joey_green wrote: 3. Does the shader code you write need to be GLSL compatible?
With the exception of not having a vertex shader, yes, it's just glsl. Love adds a small wrapper to facilitate shader development:

Code: Select all

		local header = [[#version 120
		#define number float
		#define Image sampler2D
		#define extern uniform
		#define Texel texture2D
		uniform sampler2D _tex0_;]]
		local footer = [[void main() {
			// fix weird crashing issue in OSX when _tex0_ is unused within effect()
			float dummy = texture2D(_tex0_, vec2(.5)).r;
			gl_FragColor = effect(gl_Color, _tex0_, gl_TexCoord[0].xy, gl_FragCoord.xy);
		}]]