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

Similar documents
CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

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

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

Shaders (some slides taken from David M. course)

Lecture 2. Shaders, GLSL and GPGPU

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

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

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

Pipeline Operations. CS 4620 Lecture 14

Shaders. Slide credit to Prof. Zwicker

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

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

Rendering Subdivision Surfaces Efficiently on the GPU

12.2 Programmable Graphics Hardware

CS GPU and GPGPU Programming Lecture 8+9: GPU Architecture 7+8. Markus Hadwiger, KAUST

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

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

Programming Graphics Hardware

Programmable Graphics Hardware

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

Shading Languages for Graphics Hardware

Programming shaders & GPUs Christian Miller CS Fall 2011

frame buffer depth buffer stencil buffer

Homework 3: Programmable Shaders

CS GPU and GPGPU Programming Lecture 11: GPU Texturing 1. Markus Hadwiger, KAUST

Programmable Graphics Hardware

CIS 536/636 Introduction to Computer Graphics. Kansas State University. CIS 536/636 Introduction to Computer Graphics

Supplement to Lecture 22

Evolution of GPUs Chris Seitz

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

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

Shading Languages Tim Foley

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

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

CS GPU and GPGPU Programming Lecture 12: GPU Texturing 1. Markus Hadwiger, KAUST

The Rasterization Pipeline

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

Lecture 13: OpenGL Shading Language (GLSL)

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

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

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

The F-Buffer: A Rasterization-Order FIFO Buffer for Multi-Pass Rendering. Bill Mark and Kekoa Proudfoot. Stanford University

A Real-Time Procedural Shading System for Programmable Graphics Hardware

Cg 2.0. Mark Kilgard

Cg: A system for programming graphics hardware in a C-like language

CS427 Multicore Architecture and Parallel Computing

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

Programming Graphics Hardware

COMP371 COMPUTER GRAPHICS

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

Comparing Reyes and OpenGL on a Stream Architecture

A Trip Down The (2011) Rasterization Pipeline

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

Introduction to Shaders.

OpenGL Programmable Shaders

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

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

CS195V Week 9. GPU Architecture and Other Shading Languages

CS GPU and GPGPU Programming Lecture 16+17: GPU Texturing 1+2. Markus Hadwiger, KAUST

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

3D buzzwords. Adding programmability to the pipeline 6/7/16. Bandwidth Gravity of modern computer systems

Programmable Graphics Hardware

Graphics Hardware. Instructor Stephen J. Guy

Pipeline Operations. CS 4620 Lecture 10

Parallelizing Graphics Pipeline Execution (+ Basics of Characterizing a Rendering Workload)

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

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

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

Optimal Shaders Using High-Level Languages

Parallelizing Graphics Pipeline Execution (+ Basics of Characterizing a Rendering Workload)

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Mobile graphics API Overview

Mattan Erez. The University of Texas at Austin

Cornell University CS 569: Interactive Computer Graphics. Introduction. Lecture 1. [John C. Stone, UIUC] NASA. University of Calgary

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

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

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

CHAPTER 1 Graphics Systems and Models 3

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

Canonical Shaders for Optimal Performance. Sébastien Dominé Manager of Developer Technology Tools

Introduction. Chapter What Is Cg?

MXwendler Fragment Shader Development Reference Version 1.0

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

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

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

1.2.3 The Graphics Hardware Pipeline

Spring 2011 Prof. Hyesoon Kim

Beginning Direct3D Game Programming: 1. The History of Direct3D Graphics

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

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

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

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

TSBK03 Screen-Space Ambient Occlusion

Basics of GPU-Based Programming

Introduction to the OpenGL Shading Language

Assignment 4: Shading and Lighting

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

Automatic Tuning Matrix Multiplication Performance on Graphics Hardware

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

OPENGL RENDERING PIPELINE

Transcription:

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

Reading Assignment #4 (until Feb. 23) Read (required): Programming Massively Parallel Processors book, Chapter 2 (History of GPU Computing) GLSL book, Chapter 7 (OpenGL Shading Language API) OpenGL Shading Language 4.5 specification: Chapter 2 http://www.opengl.org/registry/doc/glslangspec.4.50.pdf Download OpenGL 4.5 specification http://www.opengl.org/registry/doc/glspec45.core.pdf Read (optional): OpenGL 4.0 Shading Language Cookbook, Chapter 3 http://www.opengl.org/wiki/history_of_opengl See more at: http://www.opengl.org/documentation/specs/ 2

Shading Example Multiple layers: procedural shading, fetch textures, do lighting,... A Real-Time Procedural Shading System for Programmable Graphics Hardware Kekoa Proudfoot, William R. Mark, Svetoslav Tzvetkov, and Pat Hanrahan, SIGGRAPH 2001.

Example: Per-Pixel(Fragment) Lighting Simulating smooth surfaces by calculating illumination for each fragment Example: specular highlights (Phong illumination/shading) per-fragment evaluation linear interp. from vertices 4

Example: Bump Mapping / Normal Mapping High-frequency surface detail from normal map (texture storing surface normals) that yields per-fragment normal vectors for shading 5

Normal Map Example: Quake 2 Model ( ) + ( ) = Diffuse Decal Specular Gloss Note: Gloss map defines where to apply specular Final result! 6

Normal Map Example + Model by Piotr Slomowicz 7

Normal Map Example 8

Normal Map Example 9

Doom 3 (id Software, 2004)

Half-Life 2 (Valve, 2004) vs. Half-Life (Valve, 1998)

Half-Life 2: The Lost Coast (Valve, 2005)

Unreal Engine 3 (Epic Games, 2006 )

Crysis (Crytek, 2007)

Shading Languages Ancestors Offline shading: Pixar s RenderMan Shading Language,... Real-time: Stanford Shading Language,... Programmable shading on GPUs Old assembly language OpenGL extensions / Direct3D NVIDIA Cg (compiles to low-level OpenGL or Direct3D shaders) DirectX HLSL (compiles to low-level Direct3D shaders) OpenGL shading language (GLSL); GLSL 1.10 in core OpenGL 2.0 (2004) 15 Write Fragment (pixel) shaders Vertex shaders Geometry shaders...

High-Level Shading Languages Syntax similar to C, plus vector variables and vector instructions: GLSL: vec4 v1; Cg/HLSL: float4 v1; // same as float v1[4] in C ivec3 v2; int3 v2; // same as int v2[3] in C Swizzling: vec4 v3 = v1.xzzy; Basic C, plus built-in functions for graphics, plus C math functions Functions like sin(), pow(), exp(),... Functions like length(), distance(), normalize(), dot(),... Functions like clamp(), mix(),...

GLSL History http://en.wikipedia.org/wiki/opengl_shading_language 17

Programmable Processing Stages GLSL 1.50 (OpenGL 3.2) Vertex shaders (run on vertex processors) Geometry shaders (run on geometry processors) Fragment shaders (run on fragment processors) From the language / API perspective it is useful to consider separate types of processors, even when all of these shaders are in reality executed on identical processing cores on current GPUs! 18

Direct3D 10 Pipeline New geometry shader stage: Vertex -> geometry -> pixel shaders Stream output after geometry shader Courtesy David Blythe, Microsoft 19

Vertex Shader (1) Process vertices and their attributes Position Color, texture coordinate(s),... GLSL 1.20 20

Vertex Shader (2) Pass-through example Pass through per-vertex color Transform vertex position with OpenGL Model-View-Projection matrix 21

Geometry Shader (1) Process whole primitives Emit vertices Emit primitive(s) 22 GL_EXT_geometry_shader4

Geometry Shader (2) Pass-through example Pass through (emit) all vertices Pass through (emit) one primitive 23

Fragment Shader (1) Process fragments Write one or more output fragments Use input color, texture coordinates,... Compute shading, sample textures,... Optionally discard fragment MRT: multiple render targets GLSL 1.20 24

Fragment Shader (2) Pass-through example Pass through interpolated color as fragment color 25

Detailed Geometry Coarse base mesh Refine through subdivision High-frequency detail from displacement mapping 26

Simple OpenGL Program (1) Simplest option for window and context management: GLUT Can use GLEW for OpenGL extensions (not shown here; see programming assignment!) 27

Simple OpenGL Program (2) Init a (vertex) shader 28

29

30

31

32 GLSL 1.20

GLSL 1.20 beware: N must be normalized: N = normalize(n); 33

Thank you.