Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Similar documents
Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

CSCI 4239/5239 Advanced Computer Graphics Spring 2015

Programming shaders & GPUs Christian Miller CS Fall 2011

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

12.2 Programmable Graphics Hardware

Programmable Graphics Hardware

Shaders. Slide credit to Prof. Zwicker

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

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

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

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

Introduction to Shaders.

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

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

Lecture 2. Shaders, GLSL and GPGPU

Supplement to Lecture 22

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

Programmable shader. Hanyang University

COMP371 COMPUTER GRAPHICS

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

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

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

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

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

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

Graphics Hardware. Instructor Stephen J. Guy

Introduction to the OpenGL Shading Language

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

OpenGL Programmable Shaders

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

Programming Graphics Hardware

Lecture 13: OpenGL Shading Language (GLSL)

Programmable Graphics Hardware

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

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

Graphics Programming. Computer Graphics, VT 2016 Lecture 2, Chapter 2. Fredrik Nysjö Centre for Image analysis Uppsala University

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

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

BCA611 Video Oyunları için 3B Grafik

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

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

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

Lecture 09: Shaders (Part 1)

Shaders (some slides taken from David M. course)

An Overview GLUT GLSL GLEW

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

Chapter 7 - Light, Materials, Appearance

Shading Language Update

CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS SPRING 2016 DR. MICHAEL J. REALE

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

CS427 Multicore Architecture and Parallel Computing

3D Production Pipeline

CS 179: GPU Programming

OPENGL RENDERING PIPELINE

Lecture 15 of 41. Scene Graphs: State Videos 1: CGA Shorts, Demos

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

MXwendler Fragment Shader Development Reference Version 1.0

Copyright Khronos Group 2012 Page 1. Teaching GL. Dave Shreiner Director, Graphics and GPU Computing, ARM 1 December 2012

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

Programmable Graphics Hardware

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

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

Shader Series Primer: Fundamentals of the Programmable Pipeline in XNA Game Studio Express

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

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

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

Programmable Shading. University of Texas at Austin CS354 - Computer Graphics

Cg 2.0. Mark Kilgard

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

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

CS 432 Interactive Computer Graphics

Cg Toolkit. Cg 2.2 April 2009 Release Notes

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

Zeyang Li Carnegie Mellon University

printf Debugging Examples

- Surface Rendering -

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

EDAF80 Introduction to Computer Graphics. Seminar 3. Shaders. Michael Doggett. Slides by Carl Johan Gribel,

CPSC 436D Video Game Programming

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Shading Languages. Ari Silvennoinen Apri 12, 2004

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI

Cg Toolkit. Cg 2.2 February 2010 Release Notes

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

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Mattan Erez. The University of Texas at Austin

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Programmable GPUs Outline

CS475/CS675 - Computer Graphics. OpenGL Drawing

CHAPTER 1 Graphics Systems and Models 3

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

Hardware Shading: State-of-the-Art and Future Challenges

WebGL and GLSL Basics. CS559 Fall 2015 Lecture 10 October 6, 2015

CMPS160 Shader-based OpenGL Programming

OPEN GL BACKGROUND. Objectives. Early History of APIs. SGI and GL. PHIGS and X. Modified from Angel 6e book slides

Homework 3: Programmable Shaders

Transcription:

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

What is a Shader? A shader is a computer program that runs on the GPU to calculate the properties of vertexes, pixels and other graphical processing Examples: Vertex position or color computed by a program Texture generated by a program Per-pixel lighting Image processing Cartoon shading

How does a shader work? Shader Language used to specify operations RenderMan, ISL, HLSL, Cg, GLSL Compile instructions into program e.g. glcompileshader() Shader performs calculations as part of graphics pipeline Runs calculations on GPU instead of CPU

What is a Shader Language? Typically C/C++ like for, while, if,... for control flow Adds special types like vec4 (4 component vector) and mat4 (4x4 matrix) and operators Predefined variables used to get data (gl_vertex) and return result (gl_position) Simplifies and extends C/C++ for efficiency Matrix & vector operations supported in hardware Graphics Processing Unit (GPU) Built-in functions like normal, blend, etc.

GL Shader Language (GLSL) Often call GLSLang Added to OpenGL 2.0 First appeared as extension in OpenGL 1.4 Can be accessed in older versions using extentions GL Extension Wrangler (GLEW) often used Geared to real time graphics Inserted into OpenGL pipeline Vertex Shader to manipulate vertexes Fragment Shader to manipulate pixels

GLSL Resources OpenGL Programming Guide (8 ed ) Vermillion Book Don't get older editions GLSL Quick Reference Cheat sheet Many online references http://www.lighthouse3d.com/opengl/glsl/ Watch out for old stuff (OpenGL < 2) Don't be confused by newest stuff (OpenGL 4)

OpenGL Deprecation I will use OpenGL 2.x Feature rich Flat learning curve More advanced examples will use 3.x and 4.x OpenGL Core Profile concentrates on rendering Improved execution time performance User must provide deprecated functionality Steepens the learning curve Deprecated features in Compatibility Profile Increases reliance on third party libraries

Where does GLSL fit? Vertex shader Transformations, color, texture coordinates,... Fragment shader Textures, Color Interpolation, Fog,... OpenGL still does Z-buffering, etc.

Fixed Pipeline Example

How is this different from what we have done before? GLSL instructions can run on GPU Matrix-vector multiplications done fast Without GLSL we influence the pipeline using parameters and fixed operations Lighting calculated at vertexes Textures calculated at fragments Vertex-frament interpolation GL_SMOOTH bilinear interpolation GL_FLAT constant using last vertex With GLSL we can calculate values directly

How does this work with OpenGL?

Other Shader Languages RenderMan Lucasfilm - Pixar - Disney OpenGL Shader (ISL) SGI Interactive Shader Language High-Level Shader Language (HLSL) Microsoft DirectX 9 NVIDIA's Cg proprietary shading language

RenderMan First practical shading language (1988) De-facto entertainment industry standard Remains in widespread use today Generally used for off-line rendering Uncompromising image quality Little hardware acceleration Credits: Jurassic Park, Star Wars Prequels, Lord of the Rings Toy Story, Finding Nemo, Monsters Inc,... No relation to OpenGL in syntax or structure

The Rest (ISL, HLSL, Cg,...) Syntax different but similar approach Generally similar in structure Vertex Shader Fragment Shader Geared towards real time graphics Hardware support Performance stressed

GLSL Versions GLSL 1.0 = OpenGL 1.4 (2002) The first portable shader GLSL 1.2 = OpenGL 2.0 (2004) The shader we will use GLSL 1.3 = OpenGL 3.0 (2008) Some changes in syntax Deprecates some features GLSL 3.3 = OpenGL 3.3 From here on GLSL version match OpenGL Set minimum version using #version

GLSL Variable Qualifiers uniform (e.g. gl_modelviewmatrix) input to vertex and fragment shader from OpenGL or application [read-only] attribute (e.g. gl_vertex) input per-vertex to vertex shader from OpenGL or application [read-only] varying (e.g. gl_frontcolor) output from vertex shader [read-write], interpolated, then input to fragment shader [read-only] const (e.g. gl_maxlights) compile-time constant [read-only]

The problem with shaders EXTREMELY hard to debug No print statements You have to have to do lighting yourself Support is spotty GLSL requires OpenGL 2.0 or extensions Still somewhat a work in progress Generally needs decent hardware So why use it? Ultimate flexibility Unsupported features (e.g. bump maps)

OpenGL Extension Wrangler (GLEW) Maps OpenGL extensions at run time Provides headers for latest OpenGL Finds vendor support at run time Check support for specific functions or OpenGL version at run time Crashes if unsupported features are used Use only if you have to (Windows mostly) Set -duseglew to selectively invoke it Do NOT require GLEW (I don't need it) See MinGW instructions on moodle

Brick Shader (Orange Book Ch 6) Uses scalar Phong shading for lighting Calculates brick/mortar based on model coordinates