Author: Romain Vergne (website)
Please cite my name and add a link to my web page if you use this course

Image synthesis and OpenGL: graphics pipeline

Quick links to:
  1. Reminder: simplified pipeline
  2. Fixed pipeline (OpenGL 1)
  3. Dynamic pipeline (OpenGL 2)
  4. Dynamic pipeline (OpenGL 4)
  5. Sources

Reminder: simplified pipeline




Download this simple scene


Rendering



Ray-tracing
  • Propagate rays from pixels
  • Scene = set of intersectable primitives
Rasterization
  • Project primitives on screen
  • discretize primitives
  • Scene = set of rasterizable primitives

The GPU

What is the difference between a CPU (Central Processing Unit) and a GPU (Graphics Processing Unit)? A simple demonstration here.

Fixed pipeline (OpenGL 1)






Vertex processing
  • Input: one vertex (and attributes)
  • Output: one vertex (modified)
Vertex projection
  • ModelView Matrix
  • Projection Matrix
Assign attributes
  • Color
  • Texture coordinates
  • etc.




Primitive processing



  • Input: vertices, topology
  • Output: primitive
  • Vertex assembly
  • Perspective division
  • Viewport transformation
  • Clipping 
  • Backface culling



Rasterization



  • Input: primitive
  • Output: fragments
  • Fragment generation
  • Multiple possible fragment per pixel
  • Assign color / texture / depth / ... per fragment
  • Interpolation along each primitive



Fragment processing
  • Input: fragments
  • Output: pixel
Effects
  • Fog
  • Textures
  • Images
Tests
  • Stencil test
  • Depth test





Pixel processing



  • Input: pixels
  • Output: pixels

  • Alpha test
  • Blending

Fixed pipeline :


Dynamic pipeline (OpenGL 2)



Vertex and fragment processing now programmable!

  • Vertex shader
  • Fragment shader
  • little program executed on the GPU
  • languages:
    • GG (nvidia only)
    • HLSL (DirectX only - Microsoft)
    • GLSL (OpenGL Shading Language)

Why is it usefull?


How does a shader look like?


// GLSL version
#version 330

// Vertex attributes (given by glVertexAttribPointer(...))
layout(location = 0) in vec3 vertexPosition_modelspace;
layout(location = 1) in vec3 vertexColor;

// Output data: will be interpolated for each fragment
out vec3 fragmentColor;

// ModelViewProjection matrix (constant for the whole mesh)
uniform mat4 MVP;

void main() {   
    // Output position of the vertex, in clip space : MVP * position
    gl_Position =  MVP * vec4(vertexPosition_modelspace,1);

    // The color of each vertex will be interpolated
    // to produce the color of each fragment
    fragmentColor = vertexColor;
}


// GLSL version
#version 330

// Interpolated values from the vertex shaders
in vec3 fragmentColor;

// Ouput data
out vec3 color;

void main() {
    // Output color = color specified in the vertex shader,
    // interpolated between all 3 surrounding vertices
    color = fragmentColor;
}
Vertex shader
Fragment shader

How can we tell the GPU to use our own GLSL program?


Image taken here

Dynamic pipeline (OpenGL 4)



Programmable stages


  • Vertex/fragment shaders
  • Tesselation
    • Tess. Control Shader
    • Tess. Evaluation Shader
    • generate patches
  • Primitive
    • geometry shader
    • stream output
  • Compute
    • compute shader

Have a look to the full detailed pipeline here

Sources


PREVIOUS: EXERCICE02
NEXT: EXERCICE03