# Pass-through Vertex shader

**URL:** <https://discourse.libcinder.org/t/pass-through-vertex-shader/542>\
**Category:** Using Cinder\
**Created:** [February 3, 2017, 8:28am UTC](https://discourse.libcinder.org/t/pass-through-vertex-shader/542 "2017-02-03T08:28:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gazoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/gazoo/32/61_2.png) [@Gazoo](https://discourse.libcinder.org/u/Gazoo)\
**Post date:** [February 3, 2017, 8:28am UTC](https://discourse.libcinder.org/t/pass-through-vertex-shader/542/1 "2017-02-03T08:28:18Z")

</div>

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;
}

```

Cheers,  
Lasse

---

<div class="post-metadata">

**Author:** ![lithium](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/lithium/32/38_2.png) [@lithium](https://discourse.libcinder.org/u/lithium)\
**Post date:** [February 3, 2017, 10:38am UTC](https://discourse.libcinder.org/t/pass-through-vertex-shader/542/2 "2017-02-03T10:38:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul.houx](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/paul.houx/32/31_2.png) [@paul.houx](https://discourse.libcinder.org/u/paul.houx)\
**Post date:** [February 3, 2017, 11:00am UTC](https://discourse.libcinder.org/t/pass-through-vertex-shader/542/3 "2017-02-03T11:00:51Z")

</div>

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:

```auto
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’s trick to output the resulting shader code.

-Paul

---

<div class="post-metadata">

**Author:** ![sharkbox](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/sharkbox/32/39_2.png) [@sharkbox](https://discourse.libcinder.org/u/sharkbox)\
**Post date:** [February 3, 2017, 4:25pm UTC](https://discourse.libcinder.org/t/pass-through-vertex-shader/542/4 "2017-02-03T16:25:59Z")

</div>

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 [https://github.com/cinder/Cinder/blob/master/src/cinder/gl/EnvironmentCore.cpp#L203](https://github.com/cinder/Cinder/blob/master/src/cinder/gl/EnvironmentCore.cpp#L203) and here you can view all the “magic” variables that cinder can pass to a shader automatically [https://github.com/cinder/Cinder/blob/master/src/cinder/gl/GlslProg.cpp#L616](https://github.com/cinder/Cinder/blob/master/src/cinder/gl/GlslProg.cpp#L616)

-charlie
