Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders

Slides:



Advertisements
Similar presentations
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
Advertisements

COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
Graphics Pipeline.
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 11: OpenGL 3
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.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 7: OpenGL Shading
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.
Real-time Graphical Shader Programming with Cg (HLSL)
Geometric Objects and Transformations. Coordinate systems rial.html.
CS 418: Interactive Computer Graphics Introduction to WebGL: HelloTriangle.html Eric Shaffer.
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.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Week 2 - Friday.  What did we talk about last time?  Graphics rendering pipeline  Geometry Stage.
Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 6: OpenGL 1
1 Dr. Scott Schaefer Programmable Shaders. 2/30 Graphics Cards Performance Nvidia Geforce 6800 GTX 1  6.4 billion pixels/sec Nvidia Geforce 7900 GTX.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CS 4363/6353 OPENGL BACKGROUND. WHY IS THIS CLASS SO HARD TO TEACH? (I’LL STOP WHINING SOON) Hardware (GPUs) double in processing power ever 6 months!
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
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.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
OpenGL Shader Language Vertex and Fragment Shading Programs.
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 2 Graphics Hardware Pipeline, Reflection and Rendering Equations, Taxonomy of Methods
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Shaders in OpenGL Marshall Hahn. Introduction to Shaders in OpenGL In this talk, the basics of OpenGL Shading Language will be covered. This includes.
CS418 Computer Graphics John C. Hart
OpenGL Shading Language (GLSL)
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL Shading Language (GLSL)
The OpenGL API Patrick Cozzi University of Pennsylvania CIS Fall 2012.
© David Kirk/NVIDIA and Wen-mei W. Hwu, ECE408, University of Illinois, Urbana-Champaign 1 Programming Massively Parallel Processors Lecture.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
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.
OpenGL Shading Language (GLSL)
OpenGl Shaders Lighthouse3d.com.
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.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 167 [Win 17], Lecture 6: OpenGL 1 Ravi Ramamoorthi
Shader.
Programmable Shaders Dr. Scott Schaefer.
Programmable Pipelines
Graphics Processing Unit
Chapter 6 GPU, Shaders, and Shading Languages
Real-time Computer Graphics Overview
Introduction to Computer Graphics with WebGL
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Introduction to Computer Graphics with WebGL
Introduction to Shaders
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
OpenGL Background CS 4722.
Presentation transcript:

Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders

OpenGL Rendering Pipeline Geometry Primitive Operations Pixel Operations Scan Conversion (Rasterize) Texture Memory Fragment Operations Framebuffer Vertices Images Traditional Approach: Fixed function pipeline (state machine) New Development (2003-): Programmable pipeline Programmable in Modern GPUs (Vertex Shader) Programmable in Modern GPUs (Fragment Shader)

Simplified OpenGL Pipeline  User specifies vertices (vertex buffer object)  For each vertex in parallel  OpenGL calls user-specified vertex shader: Transform vertex (ModelView, Projection), other ops  For each primitive, OpenGL rasterizes  Generates a fragment for each pixel the fragment covers  For each fragment in parallel  OpenGL calls user-specified fragment shader: Shading and lighting calculations  OpenGL handles z-buffer depth test unless overwritten  Modern OpenGL is “lite” basically just a rasterizer  “Real” action in user-defined vertex, fragment shaders

Shading Languages  Vertex / Fragment shading described by small program  Written in language similar to C but with restrictions  Long history. Cook’s paper on Shade Trees, Renderman for offline rendering  Stanford Real-Time Shading Language, work at SGI  Cg from NVIDIA, HLSL  GLSL directly compatible with OpenGL 2.0 (So, you can just read the OpenGL Red Book to get started)

Shader Setup  Initializing (shader itself discussed later) 1.Create shader (Vertex and Fragment) 2.Compile shader 3.Attach shader to program 4.Link program 5.Use program  Shader source is just sequence of strings  Similar steps to compile a normal program

Shader Initialization Code GLuint initshaders (GLenum type, const char *filename) { // Using GLSL shaders, OpenGL book, page 679 GLuint shader = glCreateShader(type) ; GLint compiled ; string str = textFileRead (filename) ; GLchar * cstr = new GLchar[str.size()+1] ; const GLchar * cstr2 = cstr ; // Weirdness to get a const char strcpy(cstr,str.c_str()) ; glShaderSource (shader, 1, &cstr2, NULL) ; glCompileShader (shader) ; glGetShaderiv (shader, GL_COMPILE_STATUS, &compiled) ; if (!compiled) { shadererrors (shader) ; throw 3 ; } return shader ; }

Linking Shader Program GLuint initprogram (GLuint vertexshader, GLuint fragmentshader) { GLuint program = glCreateProgram() ; GLint linked ; glAttachShader(program, vertexshader) ; glAttachShader(program, fragmentshader) ; glLinkProgram(program) ; glGetProgramiv(program, GL_LINK_STATUS, &linked) ; if (linked) glUseProgram(program) ; else { programerrors(program) ; throw 4 ; } return program ; }

Cliff Lindsay web.cs.wpi.edu/~rich/courses/imgd4000-d09/lectures/gpu.pdf

Fragment Shader Compute Lighting vec4 ComputeLight (const in vec3 direction, const in vec4 lightcolor, const in vec3 normal, const in vec3 halfvec, const in vec4 mydiffuse, const in vec4 myspecular, const in float myshininess) { float nDotL = dot(normal, direction) ; vec4 lambert = mydiffuse * lightcolor * max (nDotL, 0.0) ; float nDotH = dot(normal, halfvec) ; vec4 phong = myspecular * lightcolor * pow (max(nDotH, 0.0), myshininess) ; vec4 retval = lambert + phong ; return retval ; }