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.

Slides:



Advertisements
Similar presentations
COMPUTER GRAPHICS SOFTWARE.
Advertisements

Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
CS 4363/6353 BASIC RENDERING. THE GRAPHICS PIPELINE OVERVIEW Vertex Processing Coordinate transformations Compute color for each vertex Clipping and Primitive.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
3D computer graphic Basis for real-time rendering and GPU architecture 劉哲宇,Liou Jhe-Yu.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Models and Architectures Ed Angel Professor of Computer Science, Electrical and Computer.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Beyond Meshes Spring 2012.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Geometric Objects and Transformations. Coordinate systems rial.html.
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.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
CSC 461: Lecture 3 1 CSC461 Lecture 3: Models and Architectures  Objectives –Learn the basic design of a graphics system –Introduce pipeline architecture.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
CSE Real Time Rendering Week 2. Graphics Processing 2.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
1Computer Graphics Lecture 4 - Models and Architectures John Shearer Culture Lab – space 2
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Review of OpenGL Basics
1 3D API OPENGL ES v1.0 Owned by Silicon Graphics (SGL) Control was then transferred to Khronos Group Introduction.
09/16/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Environment mapping Light mapping Project Goals for Stage 1.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
OpenGL-ES 3.0 And Beyond Boston Photo credit :Johnson Cameraface OpenGL Basics.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
Computing & Information Sciences Kansas State University Lecture 12 of 42CIS 636/736: (Introduction to) Computer Graphics CIS 636/736 Computer Graphics.
1 Angel: Interactive Computer Graphics5E © Addison- Wesley 2009 Image Formation Fundamental imaging notions Fundamental imaging notions Physical basis.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
1 Perception and VR MONT 104S, Fall 2008 Lecture 20 Computer Graphics and VR.
Background image by chromosphere.deviantart.com Fella in following slides by devart.deviantart.com DM2336 Programming hardware shaders Dioselin Gonzalez.
OpenGL Shading Language
The Graphics Pipeline Revisited Real Time Rendering Instructor: David Luebke.
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.
Chapter 1 Graphics Systems and Models Models and Architectures.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Models and Architectures 靜宜大學 資訊工程系 蔡奇偉 副教授 2012.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
- Introduction - Graphics Pipeline
Programmable Pipelines
Graphics Processing Unit
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
Understanding Theory and application of 3D
Models and Architectures
Models and Architectures
Models and Architectures
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Graphics Processing Unit
The Graphics Pipeline Lecture 5 Mon, Sep 3, 2007.
Models and Architectures
Models and Architectures
Programming with OpenGL Part 3: Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

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 - the production of appropriate levels of light and darkness within an image.

Type of shaders Vertex shaders Geometry shaders Pixel shaders

Vertex shaders Vertex shaders are run once for each vertex given to the graphics processor. The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen. Vertex shaders can manipulate properties such as position, color, and texture coordinate, but cannot create new vertices. The output of the vertex shader goes to the next stage in the pipeline, which is either a geometry shader if present or the rasterizer otherwise.

Geometry shaders Geometry shaders are a relatively new type of shader. It can generate new graphics primitives, such as points, lines, and triangles, from those primitives that were sent to the beginning of the graphics pipeline. Geometry shader programs are executed after vertex shaders.

Pixel shaders Pixel shaders, also known as fragment shaders, compute color and other attributes of each fragment. Pixel shaders range from always outputting the same color, to applying a lighting value, to doing bump mapping, shadows, specular highlights, translucency and other phenomena. They can alter the depth of the fragment (for Z-buffering), or output more than one color if multiple render targets are active. In 3D graphics, a pixel shader alone cannot produce very complex effects, because it operates only on a single fragment, without knowledge of a scene's geometry

Fixed Functionality Pipeline

Per-Vertex Operations

The geometry processor runs a vertex shader program for each vertex. This shader program performs: lighting transforms viewport transformation perspective transformation vertex assembly of graphics primitives polygon list builds for the pixel processor.

Primitive Assembly

Receives Vertex data from Per-Vertex operations Vertex data combined into complete primitives  Points, lines, triangles

Clip/Project/Viewport Cull

Receives primitives from Primitives Assembly Clips the primitives against the view volume  Removing portions outside of the view Perspective projection Transformed by the viewport definition Polygons culled based on facing

Rasterize

Rasterization Receives Primitives from Clip/Project/Viewport cull Primitives deconstructed to the pixel coverage they should have in the frame buffer Each unit produces is a fragment

Fragment Processing

Fragment processing Fragment processing is a term in computer graphics referring to a collection of operations applied to fragments generated by the rasterization operation in the rendering pipeline. During the rendering of computer graphics, the rasterization step takes a primitive, described by its vertex coordinates with associated color and texture information, and converts it into a set of fragments.

Per-fragment operations

fragments undergo a series of processing steps: Pixel ownership test Alpha test Stencil test Depth test Blending

Frame Buffer Operations

Frame buffer operations Control region of the buffers in the Frame buffer that are drawn(written) to

Programmable locations in pipeline Programmable Location Vertex Shader Programmable Location Fragment Shader

Three types of function Data handling functions State settings functions Rendering functions

Data handling functions Persistent OpenGL data such as frame buffers, textures and VBOs (vertex buffer object) require basic memory management in the form of their provided creation/deletion functions glGenTextures( size, names); // generates one or more textures, size is number of textures // and names is an array in which to store the texture names (numeric IDs) glDeleteTextures( size, names); // deletes one or more textures, size is number of textures // and names is an array of existing texture names (numeric IDs)

OpenGL settings functions OpenGL provides lots of built in capabilities that can be enabled/disabled as needed. Expose settings through specific functions, for example to customize the various light's individual settings you can use the glLight() functions. glEnable( capability); // enable an OpenGL capability glDisable( capability); // disable an OpenGL capability glTranslate( x, y, z); // translates (offsets) the current matrix by x/y/z glRotate( angle, x, y, z); // rotates the current matrix: angle around x/y/z

Rendering functions There are only two functions that perform actual rendering in OpenGL, both render the current vertex data in a variety of modes using the current OpenGL settings. The difference between the two functions is that one expects vertex data to be explicitly ordered while the other uses an array of indices into the vertex data to specify order.

Rendering functions cont … glDrawArrays(); glDrawElements(); Using vertex arrays reduces the number of function calls and redundant usage of shared vertices. Therefore, you may increase the performance of rendering.

One program, two shaders Nothing in OpenGL can be rendered without using a custom program A program is made up of two shaders; the vertex shader and the fragment shader the vertex shader processes every vertex that has been passed to OpenGL, transforming the positions into clip space and setting up any values that should be interpolated across connected vertices such as colors or texture coordinates OpenGL then performs some magic and calls the fragment shader for every visible fragment providing the interpolated values for that fragment.

One program, two shaders The following diagram illustrates the roles of the vertex and fragment shaders, what they can read and what they should write. \

The vertex shader attribute vec4 position; // vertex position attribute attribute vec2 texCoord; // vertex texture coordinate attribute uniform mat4 modelView; // shader modelview matrix uniform uniform mat4 projection; // shader projection matrix uniform varying vec2 texCoordVar; // vertex texture coordinate varying void main() { vec4 p = modelView * position; // transform vertex position with modelview matrix gl_Position = projection * p; // project the transformed position and write it to gl_Position texCoordVar = texCoord; // assign the texture coordinate attribute to its varying

The fragment shader precision mediump float; // set default precision for floats to medium uniform sampler2D texture; // shader texture uniform varying vec2 texCoordVar; // fragment texture coordinate varying void main() { // sample the texture at the interpolated texture coordinate // and write it to gl_FragColor gl_FragColor = texture2D( texture, texCoordVar);