Pass-through Vertex shader


Hey embers,

It’s my understanding that Cinder offers up some simple stock shaders. I’ve seen it in a number of sample programs. To be honest however, it all looks a bit like magic to me when I look into the source files that take care of generating the shader files.

Therefore, I thought it simpler to just straight-up ask if it’s possible to get a default passthrough vertex shader from cinder?

I’ve made one myself for another project like below, just wondering if I can spare myself the code in future projects…

#version 150 core

uniform mat4		ciModelViewProjection;
uniform mat4		ciModelView;
in vec4				ciPosition;
in vec3				ciColor;
out lowp vec3		vColor;

void main( void )
    //gl_Position = ciModelView * (ciPosition + vec4(200, 0, 0, 0));
	gl_Position = ciPosition;
    vColor = ciColor;


std::cout << gl::env()->generateVertexShader( gl::ShaderDef().color() ) << std::endl;


Note that your version of a pass-through vertex shader is incorrect. The vertex shader should set gl_Position to the clip space position, where x, y and z are in the range [-1…1]. In most cases, this means you’ll have to convert the object space ciPosition like this:

gl_Position = ciModelViewProjection * ciPosition;

Edit: Cinder’s shader generator is just a bunch of string manipulation to enable or disable a few simple effects. If you want to compare the differences between e.g. gl::ShaderDef().color() and gl::ShaderDef().color().texture(), you can use @lithium.snepo’s trick to output the resulting shader code.



I think it’s worth taking a look at how cinder generates it’s shaders. It helped me understand what was going on under the hood. Here is a link to the line in the current master branch and here you can view all the “magic” variables that cinder can pass to a shader automatically