JavaScript EditorFree JavaScript Editor     Ajax Editor 

Main Page
Previous Page
Next Page

2.1. Introduction to the OpenGL Shading Language

This book helps you learn and use a high-level graphics programming language formally called the OPENGL SHADING LANGUAGE. Informally, this language is sometimes referred to as GLSL. This language has been made part of the OpenGL standard as of OpenGL 2.0.

The recent trend in graphics hardware has been to replace fixed functionality with programmability in areas that have grown exceedingly complex. Two such areas are vertex processing and fragment processing. Vertex processing involves the operations that occur at each vertex, most notably transformation and lighting. Fragments are per-pixel data structures that are created by the rasterization of graphics primitives. A fragment contains all the data necessary to update a single location in the frame buffer. Fragment processing consists of the operations that occur on a per-fragment basis, most notably reading from texture memory and applying the texture value(s) at each fragment. With the OpenGL Shading Language, the fixed functionality stages for vertex processing and fragment processing have been augmented with programmable stages that can do everything the fixed functionality stages can doand a whole lot more. The OpenGL Shading Language allows application programmers to express the processing that occurs at those programmable points of the OpenGL pipeline.

The OpenGL Shading Language code that is intended for execution on one of the OpenGL programmable processors is called a SHADER. The term OPENGL SHADER is sometimes used to differentiate a shader written in the OpenGL Shading Language from a shader written in another shading language such as RenderMan. Because two programmable processors are defined in OpenGL, there are two types of shaders: VERTEX SHADERS and FRAGMENT SHADERS. OpenGL provides mechanisms for compiling shaders and linking them to form executable code called a PROGRAM. A program contains one or more EXECUTABLES that can run on the programmable processing units.

The OpenGL Shading Language has its roots in C and has features similar to RenderMan and other shading languages. The language has a rich set of types, including vector and matrix types to make code more concise for typical 3D graphics operations. A special set of type qualifiers manages the unique forms of input and output needed by shaders. Some mechanisms from C++, such as function overloading based on argument types and the capability to declare variables where they are first needed instead of at the beginning of blocks, have also been borrowed. The language includes support for loops, subroutine calls, and conditional expressions. An extensive set of built-in functions provides many of the capabilities needed for implementing shading algorithms. In brief,

  • The OpenGL Shading Language is a high-level procedural language.

  • As of OpenGL 2.0, it is part of standard OpenGL, the leading cross-platform, operating-environment-independent API for 3D graphics and imaging.

  • The same language, with a small set of differences, is used for both vertex and fragment shaders.

  • It is based on C and C++ syntax and flow control.

  • It natively supports vector and matrix operations since these are inherent to many graphics algorithms.

  • It is stricter with types than C and C++, and functions are called by value-return.

  • It uses type qualifiers rather than reads and writes to manage input and output.

  • It imposes no practical limits to a shader's length, nor does the shader length need to be queried.

The following sections contain some of the key concepts that you will need to understand in order to use the OpenGL Shading Language effectively. The concepts are covered in much more detail later in the book, but this introductory chapter should help you understand the big picture.

Previous Page
Next Page

Облицовка колонн способ облицовки колонн. . Дешевая приставка андроид на телевизор полностью заменит технологию Smart TV.
JavaScript EditorAjax Editor     JavaScript Editor