Help end child hunger

Communication OpenGL -> Shaders

Prev: Cleaning Up Next: Uniform Variables
 

An application in OpenGL has several ways of communicating with the shaders. Note that this is a one way communication though, since the only output from a shader is to render to some targets, usually the color and depth buffers.

The shader has access to part of the OpenGL state, therefore when an application alters this subset of the OpenGL state it is effectively communicating with the shader. So for instance if an application wants to pass a light color to the shader it can simply alter the OpenGL state as it is normally done with the fixed functionality.

However, using the OpenGL state is not always the most intuitive way of setting values for the shaders to act upon. For instance consider a shader that requires a variable to tell the elapsed time to perform some animation. There is no suitable named variable in the OpenGL state for this purpose. True, you can use an unused lights specular cutoff angle for this but it is highly counterintuitive.

Fortunately, GLSL allows the definition of user defined variables for an OpenGL application to communicate with a shader. Thanks to this simple feature you can have a variable for time keeping appropriately called timeElapsed, or some other suitable name.

In this context, GLSL has two types of variable qualifiers (more qualifiers are available to use inside a shader as detailed in Data Types and Variables subsection):

  • Uniform
  • Attribute

Variables defined in shaders using these qualifiers are read-only as far as the shader is concerned.

In the following subsections the details of how, and when to use these types of variables are detailed.

There is yet another way of sending values to shaders: using textures. A texture doesn’t have to represent an image; it can be interpreted as an array of data. In fact, using shaders you’re the one who decides how to interpret your textures data, even when it is an image. The usage of textures is not explored in this section since it is out of scope.

 

Prev: Cleaning Up Next: Uniform Variables
 

2 Responses to “Communication OpenGL -> Shaders”

  1. This is great tutorial. I appreciate your share. Thank you very much.

  2. Thanks for giving information about shading. I want still more Information about this

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

© 2014 Lighthouse3d.com Suffusion theme by Sayontan Sinha