Introduction to the OpenGL Shading Language

Similar documents
Today. Rendering - III. Outline. Texturing: The 10,000m View. Texture Coordinates. Specifying Texture Coordinates in GL

Programming shaders & GPUs Christian Miller CS Fall 2011

E.Order of Operations

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Introduction to Shaders.

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

Lecture 2. Shaders, GLSL and GPGPU

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

Sung-Eui Yoon ( 윤성의 )

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics

Shader Programs. Lecture 30 Subsections 2.8.2, Robb T. Koether. Hampden-Sydney College. Wed, Nov 16, 2011

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc.

Programmable Graphics Hardware

12.2 Programmable Graphics Hardware

Supplement to Lecture 22

Programming Guide. Aaftab Munshi Dan Ginsburg Dave Shreiner. TT r^addison-wesley

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Programmable Graphics Hardware

1.2.3 The Graphics Hardware Pipeline

Shaders. Slide credit to Prof. Zwicker

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

OpenGL. Shading Language. Third Edition

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

INF3320 Computer Graphics and Discrete Geometry

CHAPTER 1 Graphics Systems and Models 3

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Grafica Computazionale: Lezione 30. Grafica Computazionale. Hiding complexity... ;) Introduction to OpenGL. lezione30 Introduction to OpenGL

OPENGL RENDERING PIPELINE

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Graphics Pipeline & APIs

An Overview GLUT GLSL GLEW

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Dave Shreiner, ARM March 2009

Lab 9 - Metal and Glass

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

Graphics Hardware. Instructor Stephen J. Guy

Sign up for crits! Announcments

Graphics Pipeline & APIs

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Programmable shader. Hanyang University

CMPS160 Shader-based OpenGL Programming

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

Shader Programming 1. Examples. Vertex displacement mapping. Daniel Wesslén 1. Post-processing, animated procedural textures

Introduction to OpenGL

Rasterization Overview

COMP371 COMPUTER GRAPHICS

Building scalable 3D applications. Ville Miettinen Hybrid Graphics

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Chapter 7 - Light, Materials, Appearance

A Proposal for OpenGL 1.4 Matt Craighead NVIDIA Corporation

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Why modern versions of OpenGL should be used Some useful API commands and extensions

Free Downloads OpenGL ES 3.0 Programming Guide

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Module 13C: Using The 3D Graphics APIs OpenGL ES

Levy: Constraint Texture Mapping, SIGGRAPH, CS 148, Summer 2012 Introduction to Computer Graphics and Imaging Justin Solomon

Shaders (some slides taken from David M. course)

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

GLSL v1.20. Scott MacHaffie Schrödinger, Inc.

TSBK03 Screen-Space Ambient Occlusion

2.11 Particle Systems

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

Advanced Rendering Techniques

OpenGL Essentials Training

Computer Graphics Shadow Algorithms

INF3320 Computer Graphics and Discrete Geometry

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

Evolution of GPUs Chris Seitz

Programming Graphics Hardware

CSE 167: Introduction to Computer Graphics Lecture #13: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

The Application Stage. The Game Loop, Resource Management and Renderer Design

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

Tuesday, 23 March OpenGL Shading Language

CS452/552; EE465/505. Clipping & Scan Conversion

OpenGL Programmable Shaders

GLSL. OpenGL Shading Language. OpenGL 1.5 Logical Diagram. OpenGL 2.0 Logical Diagram

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Rendering Algorithms: Real-time indirect illumination. Spring 2010 Matthias Zwicker

Transcription:

Introduction to the OpenGL Shading Language Randi Rost Director of Developer Relations, 3Dlabs 08-Dec-2005 1

Why use graphics programmability? Graphics hardware has changed radically Fixed functionality is too limiting Never-before before-seen effects are possible Now, APPLICATIONS can take control over the processing that occurs on the graphics hardware Think of yourself as a prisoner (to fixed functionality) that has been set free! Anything is possible! December 9, 2005 2

Use Programmability For Rendering increasingly more realistic materials Metals Stone Wood Paints Etc. December 9, 2005 3

Use Programmability For Rendering natural phenomena Fire Clouds Smoke Water Etc. December 9, 2005 4

Use Programmability For Procedural texturing Stripes Polka dots Bricks Stars Etc. December 9, 2005 5

Use Programmability For Non-photorealistic (NPR) effects Painterly Hatch/stroke/pen and ink Technical illustration Cartoon Etc. December 9, 2005 6

Use Programmability For Animation On/off based on threshold Translation/rotation/scaling of any shader parameter Key-frame interpolation Particle systems Etc. December 9, 2005 7

Use Programmability For Doing new things with texture maps (or doing old things more easily) Polynomial texture maps BRDFs Bump maps Gloss maps Irradiance maps Environment maps Etc. December 9, 2005 8

Use Programmability For More realistic lighting effects Global illumination Spherical harmonics lighting Image based lighting ScoutWalker model courtesy of Christophe Desse December 9, 2005 9

Use Programmability For More realistic shadow effects Ambient occlusion Shadow mapping Volume shadows Orc model courtesy of Christophe Desse December 9, 2005 10

Use Programmability For More realistic surface effects Refraction Diffraction Anisotropic reflection BRDFs MascotAngst model courtesy of Christophe Desse December 9, 2005 11

Use Programmability For Imaging operations Color correction/transformation Noise removal Sharpening Complex blending December 9, 2005 12

Use Programmability For Better antialiasing Stochastic sampling Adaptive prefiltering Analytic integration Frequency clamping Etc. December 9, 2005 13

Use Programmability for Highly parallel computation Visualization of complex functions Numerical simulation Etc. December 9, 2005 14

Shading Languages Key to making visual programmability accessible to ISVs Need to get out of the assembler dark ages Graphics vendors busy building compiler expertise Soon will be as important to performance as drivers are today Same industry API dynamics as fixed function APIs Just the programming level has changed HLSL Direct3D Microsoft Glide Proprietary Open Standard December 9, 2005 15

Market Creation With API Standards The foundation of professional graphics 3Dlabs Initiated OpenGL ES development and is chairing Khronos and the OpenGL ES Working Group The standard for embedded 3D graphics launched at SIGGRAPH 2003 3Dlabs chaired Khronos Graphics Working Group 3Dlabs initiated OpenGL 2.0 development and is Permanent ARB Member OpenGL 2.0 was launched at Siggraph 2004 The standard for dynamic media authoring launched at SIGGRAPH 2001 The foundation of programmable, cross-platform, professional graphics December 9, 2005 16

Visual Processing Revolution Visual processing is changing the face of hardware, APIs and tools Innovation is required at all three levels OpenGL Shading Language support released March 2004 OpenGL Shading Language is part of the OpenGL standard as of OpenGL 2.0 Sept. 2004. 3Dlabs released compiler front-end as open source Hardware vendors are innovating rapidly to support graphics programmability Shader Tools Shading Languages Visual Processors December 9, 2005 17

GLSL and 3Dlabs 3Dlabs shipped industry s first OpenGL Shading Language drivers Running on complete family of Wildcat VP boards 3Dlabs has placed compiler front-end into open source To catalyze industry adoption To encourage cross-vendor consistency to error-checking 3Dlabs has placed various development tools into open source GLSLdemo, GLSLparsertest, GLSLvalidate, ShaderGen Already in use by leading-edge edge Toolkit Providers Lightwork Design Already in use by leading-edge edge ISVs Solidworks Pandromeda Many others that have not yet announced products December 9, 2005 18

GLSL Background and Current Status 19

Status OpenGL 2.0 is here! Specification approved in September 2004 OpenGL Shading Language is part of core API for shading language is part of core Spec is available at OpenGL.org Still backwards compatible with previous versions December 9, 2005 20

GLSL Book First edition released by Addison-Wesley in Feb. 2004 Second edition due out early January 2006 Contains more detailed information Introduction and overview Complete reference Dozens of detailed examples Companion web site http://3dshaders.com December 9, 2005 21

Shading Language Differences GLSL compiles directly from high level source to machine code inside of OpenGL HLSL translates high level source to Direct3D source outside of DirectX HLSL Shader Assembly level code HLSL Translator D3D Program Direct3D Driver OpenGL 2.0 Driver GLSL Compiler High level source OpenGL Shader Provided by the IHV Hardware Hardware Provided by the IHV December 9, 2005 22

OpenGL 2.0 Logical Diagram December 9, 2005 23

Vertex Processor Capabilities Lighting, material and geometry flexibility Vertex processor can do general processing, including things like: Vertex transformation Normal transformation, normalization and rescaling Lighting Color material application Clamping of colors Texture coordinate generation Texture coordinate transformation December 9, 2005 24

Vertex Processor Capabilities The vertex shader does NOT replace: Perspective divide and viewport mapping Frustum and user clipping Backface culling Primitive assembly Two sided lighting selection Polygon offset Polygon mode December 9, 2005 25

Vertex Processor Overview Standard OpenGL attributes gl_color gl_normal etc. Generic attributes 0, 1, 2, Texture Maps Vertex Processor User-defined uniforms: epsilon, mylightpos, surfcolor, etc. Built-in uniforms: gl_fogcolor, gl_modelviewmatrix, etc. Standard Varying gl_frontcolor gl_backcolor etc. Special Variables gl_position gl_clipvertex gl_pointsize User-defined Varying normal refraction etc. December 9, 2005 26

Fragment Processor Capabilities Flexibility for texturing and per-pixel pixel operations Fragment processor can do general processing, including things like: Operations on interpolated values Texture access Texture application Fog Color sum Pixel zoom Scale and bias Color table lookup Convolution Color matrix December 9, 2005 27

Fragment Processor Capabilities The fragment shader does NOT replace: Shading model Coverage Pixel ownership test Scissor Stipple Alpha test Depth test Stencil test Alpha blending Logical ops Dithering Plane masking Histogram Minmax Pixel packing Pixel unpacking December 9, 2005 28

Fragment Processor Overview Standard Varying gl_color gl_secondarycolor etc. Special Variables gl_fragcoord gl_frontfacing User-defined Varying normal refraction etc. Texture Maps Fragment Processor User-defined uniforms: epsilon, mylightpos, surfcolor, etc. Built-in uniforms: gl_fogcolor, gl_modelviewmatrix, etc. Special Variables gl_fragcolor gl_fragdepth gl_fragdata[n] December 9, 2005 29

Vertex Processor Input Vertex shader is executed once each time a vertex position is specified Via glvertex or gldrawarrays or other vertex array calls Per-vertex input values are called attributes Change every vertex Passed through normal OpenGL mechanisms (per-vertex API or vertex arrays) More persistent input values are called uniforms Can come from OpenGL state or from the application Constant across at least one primitive, typically constant for many primitives Passed through new OpenGL API calls December 9, 2005 30

Vertex Processor Output Vertex shader uses input values to compute output values Vertex shader must compute gl_position Mandatory, needed by the rasterizer Can use built-in in function ftransform() to get invariance with fixed functionality Vertex shader may compute: gl_clipvertex (if user clipping is to be performed) gl_pointsize (if point parameters are to be used) December 9, 2005 31

Vertex Processor Output Other output values are called varying variables E.g., color, texture coordinates, arbitrary data Will be interpolated in a perspective-correct correct fashion across the primitives Defined by the vertex shader Can be of type float, vec2, vec3, vec4, mat2, mat3, mat4, or arrays of these Output of vertex processor feeds into OpenGL fixed functionality If a fragment shader is active, output of vertex shader must match input of fragment shader If no fragment shader is active, output of vertex shader must match the needs of fixed functionality fragment processing December 9, 2005 32

Vertex Processor Definition The vertex processor executes the vertex shader The vertex processor has knowledge of only the current vertex An implementation may have multiple vertex processors operating in parallel December 9, 2005 33

Vertex Processor Definition When the vertex processor is active, the following fixed functionality is disabled: The modelview matrix is not applied to vertex coordinates The projection matrix is not applied to vertex coordinates The texture matrices are not applied to texture coordinates Normals are not transformed to eye coordinates Normals are not rescaled or normalized Normalization of GL_AUTO_NORMAL evaluated normals is not performed Texture coordinates are not generated automatically Per vertex lighting is not performed Color material computations are not performed Color index lighting is not performed Point size distance attenuation is not performed All of the above applies when setting the current raster position December 9, 2005 34

Intervening Fixed Functionality Results from vertex processing undergo: Color clamping or masking (for built-in in varying variables that deal with color, but not user-defined varying variables) Perspective division on clip coordinates Viewport mapping Depth range Clipping, including user clipping Front face determination Flat-shading Color, texture coordinate, fog, point-size and user-defined varying clipping Final color processing December 9, 2005 35

Fragment Processor Input Output of vertex shader is the input to the fragment shader Compatibility is checked when linking occurs Compatibility between the two is based on varying variables that are defined in both shaders and that match in type and name Fragment shader is executed for each fragment produced by rasterization For each fragment, the fragment shader has access to the interpolated value for each varying variable Color, normal, texture coordinates, arbitrary values December 9, 2005 36

Fragment Processor Input Fragment shader may access: gl_frontfacing contains direction (front or back) of primitive that produced the fragment gl_fragcoord contains computed window relative coordinates x, y, z, 1/w Uniform variables are also available OpenGL state or supplied by the application, same as for vertex shader If no vertex shader is active, fragment shader get the results of OpenGL fixed functionality December 9, 2005 37

Fragment Processor Output Output of the fragment processor goes on to the fixed function fragment operations and frame buffer operations using built-in in variables gl_fragcolor computed R, G, B, A for the fragment gl_fragdepth computed depth value for the fragment gl_fragdata FragData[n] arbitrary data per fragment, stored in multiple render targets Values are destined for writing into the frame buffer if back end tests all pass Clamping or format conversion to the target buffer is done automatically outside of the fragment shader December 9, 2005 38

Fragment Processor Definition The fragment processor executes the fragment shader The fragment processor has knowledge of only the current fragment An implementation may have multiple fragment processors operating in parallel When the fragment processor is active, the following fixed functionality is disabled: The texture environments and texture functions are not applied Texture application is not applied Color sum is not applied Fog is not applied December 9, 2005 39

Fragment Processor Definition The fragment processor does not affect the behavior of the following: Texture image specification Alternate texture image specification Compressed texture image specification Texture parameters behave as specified even when a texture is accessed from within a fragment shader Texture state and proxy state Texture object specification Texture comparison modes December 9, 2005 40