CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders

Slides:



Advertisements
Similar presentations
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Advertisements

CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
Introduction to Shader Programming
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Introduction to Computer Graphics Ed Angel Professor of Computer Science, Electrical and.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
COMP4070 Computer Graphics Dr. Amy Zhang. Welcome! 2  Introductions  Administrative Matters  Course Outline  What is Computer Graphics?
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Geometric Objects and Transformations. Coordinate systems rial.html.
GPU Shading and Rendering Shading Technology 8:30 Introduction (:30–Olano) 9:00 Direct3D 10 (:45–Blythe) Languages, Systems and Demos 10:30 RapidMind.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
A Crash Course in HLSL Matt Christian.
Computer Graphics Tz-Huan Huang National Taiwan University.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Angel and Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Introduction to Computer Graphics Ed Angel Professor Emeritus of Computer.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics I, Fall 2008 Introduction to Computer Graphics.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
Stream Processing Main References: “Comparing Reyes and OpenGL on a Stream Architecture”, 2002 “Polygon Rendering on a Stream Architecture”, 2000 Department.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
Ray Tracing using Programmable Graphics Hardware
What are shaders? In the field of computer graphics, a shader is a computer program that runs on the graphics processing unit(GPU) and is used to do shading.
Programming with OpenGL Part 3: Shaders Ed Angel Professor of Emeritus of Computer Science University of New Mexico 1 E. Angel and D. Shreiner: Interactive.
GLSL I.  Fixed vs. Programmable  HW fixed function pipeline ▪ Faster ▪ Limited  New programmable hardware ▪ Many effects become possible. ▪ Global.
An Introduction to the Cg Shading Language Marco Leon Brandeis University Computer Science Department.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
Programmable Pipelines
Graphics Processing Unit
Deferred Lighting.
Introduction to OpenGL
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Introduction to Computer Graphics
Introduction to Computer Graphics
CS5500 Computer Graphics April 17, 2006 CS5500 Computer Graphics
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
03 | Creating, Texturing and Moving Objects
Introduction to OpenGL
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders Hank Childs, University of Oregon March 12th, 2019

Talk _more_ about the test

Project G Blender WebGL #1 WebGL #2 CUDA Bezier Computer Vision Shaders

Schedule Upcoming: Today: shaders, live code Thursday: test re-take

Late Passes Will bring forms to final

Hank OH Primary purpose of Hank’s OH is now to help with self-defined projects Also can help with 1A-1F,2A,2B Friday OH: 11am-12noon

Final Presentations 3 minutes each Make sure to make it clear what you did Try to impress judges What is cool about what you did? Format PowerPoint Demo PowerPoint + Demo Connect A/V to Rm 220 project before 9am as test

Shaders

Shaders Shader: computer program used to do “shading” “Shading”: general term that covers more than just shading/lighting Used for many special effects Increased control over: position, hue, saturation, brightness, contrast For: pixels, vertices, textures

Motivation: Bump Mapping Idea: typical rasterization, calculate fragments fragments have normals (as per usual) also interpolate texture on geometry & fragments use texture for “bumps” take normal for fragment and displace it by “bump” from texture image from wikipedia

Bump Mapping Example credit: http://www.fabiensanglard.net/bumpMapping/

Bump Mapping Example

How to do Bump Mapping? Answer: easy to imagine doing it in your Project 1A- 1F infrastructure You have total control But what OpenGL commands would do this? Not possible in V1 of the GL interface, which is what we have learned It is possible with various extensions to OpenGL We will learn to do this with shaders

Shading Languages shading language: programming language for graphics, specifically shader effects Benefits: increased flexibility with rendering OpenGL (as we know it so far): fixed transformations for color, position, of pixels, vertices, and textures. Shader languages: custom programs, custom effects for color, position of pixels, vertices, and textures.

ARB assembly language ARB: low-level shading language at same level as assembly language Created by OpenGL Architecture Review Board (ARB) Goal: standardize instructions for controlling GPU Implemented as a series of extensions to OpenGL You don’t want to work at this level, but it was an important development in terms of establishing foundation for today’s technology

GLSL: OpenGL Shading Language GLSL: high-level shading language also called GLSLang syntax similar to C Purpose: increased control of graphics pipeline for developers, but easier than assembly This is layer where developers do things like “bump mapping” Benefits: Benefits of GL (cross platform: Windows, Mac, Linux) Support over GPUs (NVIDIA, ATI) HW vendors support GLSL very well

Other high-level shading languages Cg (C for Graphics) based on C programming language outputs DirectX or OpenGL shader programs deprecated in 2012 HLSL (high-level shading language) used with MicroSoft Direct3D analogous to GLSL similar to CG RSL (Renderman Shading Language) C-like syntax for use with Renderman: Pixar’s rendering engine

Relationship between GLSL and OpenGL Source: wikipedia

4 Types of Shaders Vertex Shaders Fragment Shaders Geometry Shaders Tessellation Shaders It is common to use multiple types of shaders in a program and have them interact.

How Shaders Fit Into the Graphics Pipeline You can have 0 or 1 of each shader type Vertex & fragment: very common Geometry & tessellation: less common adaptive meshing Transform Vertices from World Space to Device Space Rasterize Contribute Fragments to Buffers geometry & tessellation shaders: create new geometry before rasterized vertex shaders: custom implementation fragment shaders: custom implementation

Vertex Shader Run once for each vertex Can: manipulate position, color, texture Cannot: create new vertices Primary purpose: transform from world-space to device-space (+ depth for z-buffer). However: A vertex shader replaces the transformation, texture coordinate generation and lighting parts of OpenGL, and it also adds texture access at the vertex level Output goes to geometry shader or rasterizer

Geometry Shader Run once for each geometry primitive Purpose: create new geometry from existing geometry. Output goes to rasterizer Examples: glyphing, mesh complexity modification Formally available in GL 3.2, but previously available in 2.0+ with extensions Tessellation Shader: doing some of the same things Available in GL 4.0

Fragment Shader Run once for each fragment Purpose: replaces the OpenGL 1.4 fixed-function texturing, color sum and fog stages Output goes to buffers Example usages: bump mapping, shadows, specular highlights Can be very complicated: can sample surrounding pixels and use their values (blur, edge detection) Also called pixel shaders

How to Use Shaders You write a shader program: a tiny C-like program You write C/C++ code for your application Your application loads the shader program from a text file Your application sends the shader program to the OpenGL library and directs the OpenGL library to compile the shader program If successful, the resulting GPU code can be attached to your (running) application and used It will then supplant the built-in GL operations

How to Use Shaders: Visual Version sends “char *” version of program to GL via function call Project2B’ C++ code Project2B’ binary g++ Program is used on GPU to support Project2B’ binary OpenGL library reads text file when running OpenGL compiles program, binary made just for the current execution shader program is a binary shader program

Compiling Shader

Compiling Shader: inspect if it works

Compiling Multiple Shaders

Attaching Shaders to a Program

Inspecting if program link worked…

BUT: this doesn’t work in VTK… VTK has its own shader handling, and it doesn’t play well with the GL calls above… note: VTK6.1 much better for shaders than 6.0

Simplest Vertex Shader Many built-in variables. Some are input. Some are required output (gl_Position).

Simplest Vertex Shader (VTK version) VTK uses special names propFuncVS: vertex shader propFuncFS: fragment shader somehow it changes these into “main” just in time…

Bump-mapping with GLSL bump map texture output

Will need to load a texture…

Need to put 2D textures on our triangles…

Need to set up shaders and textures…

So what is the vertex shader program?...

And what is the fragment shader program?...