# Fragment shader vertColor question

**URL:** <https://discourse.processing.org/t/fragment-shader-vertcolor-question/31076>\
**Category:** Processing\
**Created:** [July 5, 2021, 8:36pm UTC](https://discourse.processing.org/t/fragment-shader-vertcolor-question/31076 "2021-07-05T20:36:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![zmitchell](https://avatars.discourse-cdn.com/v4/letter/z/c2a13f/32.png) [@zmitchell](https://discourse.processing.org/u/zmitchell)\
**Post date:** [July 5, 2021, 8:36pm UTC](https://discourse.processing.org/t/fragment-shader-vertcolor-question/31076/1 "2021-07-05T20:36:14Z")

</div>

I’m reading the [PShader reference](https://processing.org/tutorials/pshader/) and I have a question about code listing 4.2:

Vertex shader:

```auto
uniform mat4 transform;

attribute vec4 position;
attribute vec4 color;

varying vec4 vertColor;

void main() {
  gl_Position = transform * position;
  vertColor = color;
}

```

Fragment shader:

```auto
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif

varying vec4 vertColor;

void main() {
  gl_FragColor = vertColor;
}

```

In the vertex shader `color` is the color of the input vertex. In this code listing you set the output color `vertColor` equal to the input color `color`. However, once you go over to the fragment shader you’re just passed a single `vertColor`, which I understand to be the color of a single vertex.

Why are you only passed a single `vertColor`? Is `vertColor` automatically interpolated from the vertices of the fragment?

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [July 6, 2021, 11:45am UTC](https://discourse.processing.org/t/fragment-shader-vertcolor-question/31076/2 "2021-07-06T11:45:02Z")

</div>

if I understand correctly, color (and other attributes) values are interpolated when passed from vert shader to frag shader.

[http://www.lighthouse3d.com/tutorials/glsl-tutorial/rasterization-and-interpolation/](http://www.lighthouse3d.com/tutorials/glsl-tutorial/rasterization-and-interpolation/)

So, for example, if you want to add shading using lights and normals (phong, PBR, etc) you want to do it inside the fragment shader - otherwise (if you implement it in the vertex shader) the result may look distorted.
