Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
GLSL Essentials

You're reading from   GLSL Essentials If you're involved in graphics programming, you need to know about shaders, and this is the book to do it. A hands-on guide to the OpenGL Shading Language, it walks you through the absolute basics to advanced techniques.

Arrow left icon
Product type Paperback
Published in Dec 2013
Publisher Packt
ISBN-13 9781849698009
Length 116 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Jacobo Rodriguez Jacobo Rodriguez
Author Profile Icon Jacobo Rodriguez
Jacobo Rodriguez
Arrow right icon
View More author details
Toc

Vertex shader outputs


Vertex shaders can output generic values to the next stage. Those values are going to be passed to the geometry shading stage first, then rasterized, and finally passed to the fragment shading stage in one of the allowed interpolation fashions. You can choose the kind of interpolation, but we will use in this book a linear perspective-corrected interpolation.

To specify an output variable, you must use the interpolation type along with the out keyword:

#version 430
#pragma debug(on)
#pragma optimize(off)
layout (location = 0) in vec4 Position;
layout (location = 1) in vec2 TexCoord;

uniform mat4 Modelview;
uniform mat4 Projection;

// smooth = linearly perspective-correct interpolation
smooth out vec2 texCoordsInterpolated;
void main()
{
  gl_Position = Projection * Modelview * Position;

  // Write the vertex attribute into an output variable that will be interpolated in a later pipeline's stages
  texCoordsInterpolated = TexCoord;
}
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime