How do Love2D shaders work?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
joey_green
Prole
Posts: 3
Joined: Tue Jan 24, 2012 9:01 pm

How do Love2D shaders work?

Post 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
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: How do Love2D shaders work?

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
ncarlson
Prole
Posts: 35
Joined: Wed Jul 20, 2011 4:00 pm

Re: How do Love2D shaders work?

Post 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);
		}]]
Post Reply

Who is online

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