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

Similar documents
OPENGL RENDERING PIPELINE

CPSC 436D Video Game Programming

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

Rendering Pipeline/ OpenGL

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

Shaders. Slide credit to Prof. Zwicker

Pipeline Operations. CS 4620 Lecture 14

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

Sign up for crits! Announcments

Computer graphics 2: Graduate seminar in computational aesthetics

CS451Real-time Rendering Pipeline

CS559 Computer Graphics Fall 2015

CHAPTER 1 Graphics Systems and Models 3

CS4620/5620: Lecture 14 Pipeline

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

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

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

We assume that you are familiar with the following:

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Lecture 2. Shaders, GLSL and GPGPU

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

Models and Architectures

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Introduction to Computer Graphics with WebGL

Lets assume each object has a defined colour. Hence our illumination model is looks unrealistic.

Shadows. Prof. George Wolberg Dept. of Computer Science City College of New York

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

CS452/552; EE465/505. Intro to Lighting

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Rasterization Overview

Game Graphics & Real-time Rendering

The Graphics Pipeline and OpenGL I: Transformations!

Introduction to Shaders.

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

Graphics Hardware. Instructor Stephen J. Guy

Pipeline Operations. CS 4620 Lecture 10

Spring 2009 Prof. Hyesoon Kim

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

OpenGL shaders and programming models that provide object persistence

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

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

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

CS 464 Review. Review of Computer Graphics for Final Exam

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

COMP371 COMPUTER GRAPHICS

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

TSBK03 Screen-Space Ambient Occlusion

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

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

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

The Rasterization Pipeline

Drawing Fast The Graphics Pipeline

CS452/552; EE465/505. Review & Examples

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

Computergrafik. Matthias Zwicker. Herbst 2010

Blis: Better Language for Image Stuff Project Proposal Programming Languages and Translators, Spring 2017

The Graphics Pipeline and OpenGL I: Transformations!

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

The Traditional Graphics Pipeline

CS 498 VR. Lecture 18-4/4/18. go.illinois.edu/vrlect18

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

2: Introducing image synthesis. Some orientation how did we get here? Graphics system architecture Overview of OpenGL / GLU / GLUT

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

lecture 16 Texture mapping Aliasing (and anti-aliasing)

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

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Programming shaders & GPUs Christian Miller CS Fall 2011

The Traditional Graphics Pipeline

Three Main Themes of Computer Graphics

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

Evolution of GPUs Chris Seitz

CS452/552; EE465/505. Image Processing Frame Buffer Objects

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

Dave Shreiner, ARM March 2009

CS 4620 Program 3: Pipeline

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

Reading. 18. Projections and Z-buffers. Required: Watt, Section , 6.3, 6.6 (esp. intro and subsections 1, 4, and 8 10), Further reading:

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

PROFESSIONAL. WebGL Programming DEVELOPING 3D GRAPHICS FOR THE WEB. Andreas Anyuru WILEY. John Wiley & Sons, Ltd.

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

OUTLINE. Learn the basic design of a graphics system Introduce pipeline architecture Examine software components for a graphics system

Rendering Objects. Need to transform all geometry then

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

The Rasterization Pipeline

CS 130 Final. Fall 2015

The Traditional Graphics Pipeline

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

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

3D Rasterization II COS 426

Programming Graphics Hardware

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

BCA611 Video Oyunları için 3B Grafik

Ciril Bohak. - INTRODUCTION TO WEBGL

Graphics Pipeline. CS535 Fall Daniel G. Aliaga Department of Computer Science Purdue University

Transcription:

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE UGRAD.CS.UBC.C A/~CS314 Mikhail Bessmeltsev 1

WHAT IS RENDERING? Generating image from a 3D scene 2

WHAT IS RENDERING? Generating image from a 3D scene Let s think HOW. 3

SCENE A coordinate frame 3D objects Their materials Lights Cameras 4

RENDERING 5

RENDERING 6

FRAME BUFFER Portion of RAM on videocard (GPU) What we see on the screen Rendering destination 7

SCREEN Displays what s in frame buffer Terminology: Pixel: basic element on device Resolution: number of rows & columns in device Measured in Absolute values (1K x 1K) Density values (300 dots per inch) 8

Scene Coordinate Frame 3D objects Materials Lights Cameras? Framebuffer final image 9

SINGLE OBJECT How to describe a single piece of geometry? So far geometry has been constructed for you. 10

SHAPES: TRIANGLE MESHES Triangle = 3 vertices Mesh = {vertices, triangles} Example 11

SCENE How to describe a scene? 12

SCENE How to describe a scene? Local Transformations 13

Scene Coordinate Frame 3D objects Materials Lights Cameras? Framebuffer final image 14

SKETCH OF A RENDERING PIPELINE Scene Coordinate frame 3D models Coordinates Local transforms properties (color, material) Lights Camera 15

SKETCH OF A RENDERING PIPELINE Scene Camera View Image Coordinate frame 2D positions of shapes Shape pixels 3D models Depth of shapes Their color Coordinates Normals properties (color, material) Lights Camera Which pixel is visible 16

OPENGL/WEBGL Open Graphics Library One of the most popular libraries for 2D/3D rendering Asoftware interface to communicate with graphics hardware Cross-language API 17

OPENGL RENDERING PIPELINE 18

OPENGL RENDERING PIPELINE Scene Camera Coords Device Coords Image 19

VERTEX SHADER 20

VERTEX SHADER Vertices are stored in vertex buffer Each one is processed by vertex shader Outputs 2D position May compute per-vertex variables (normal, etc.) 21

O P E N G L R E N D E R I N G P I P E L I N E 22

O P E N G L R E N D E R I N G P I P E L I N E Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) 23

T H R E E. J S High-level library for Javascript Uses WebGL for rendering Has Scene, Mesh, Camera objects Scene is hierarchical Mesh has geometry and material properties Camera is used for rendering 24

G E O M E T R Y Triangle meshes Set ofvertices Triangle defines as {vertex_index1, vertex_index2, vertex_index3} 25

O P E N G L R E N D E R I N G P I P E L I N E Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) 26

GLS L OpenGL shading language Used for Fragment and Vertex shaders Lots of useful stuff: vec3, vec4, dvec4, mat4, sampler2d mat*vec, mat*mat Reflect, refract vec3 v( a.xy, 1) 27

V E R T E X S H A D E R VS is run for each vertex SEPARATELY By default doesn t know connectivity Input: vertex coordinates in Object Coordinate System Its main goal is to set gl_position Object coordinates -> WORLD coordinates -> VIEW coordinates 28

V E R T E X S H A D E R Except simple conversion to world coordinates You can do anything with vertices (or anything that s passed) e.g. deform vertices e.g. skinning! [courtesy NVIDIA] 29

var verticesofcube = [ -1,-1,-1, 1,-1,-1, 1, 1,-1, -1, 1,-1, -1,-1, 1, 1,-1, 1, 1, 1, 1, -1, 1, 1, ]; var indicesoffaces = [ 2,1,0, 0,3,2, 0,4,7, 7,3,0, 0,1,5, 5,4,0, 1,2,6, 6,5,1, 2,3,7, 7,6,2, 4,5,6, 6,7,4 ]; var geometry = new THREE.PolyhedronGeometry( verticesofcube, indicesoffaces, 6, 2 ); G E O M E T R Y ( JAVA S C R I P T/ T H R E. J S ) 30

Image Egon Rath 31

O P E N G L R E N D E R I N G P I P E L I N E Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) 32

33

C A M E R A VIEW 34

R A S T E R I Z A T I O N 35

R A S T E R I Z A T I O N 36

R A S T E R I Z A T I O N 37

R A S T E R I Z A T I O N - I N T E R P O L A T I O N 38

R A S T E R I Z A T I O N - I N T E R P O L A T I O N 39

O P E N G L R E N D E R I N G P I P E L I N E Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) 40

F R A G M E N T S H A D E R Fragment = data for drawing a pixel Has gl_fragcoord 2D window coords May set color! 41

F R A G M E N T S H A D E R Common Tasks: texture mapping per-pixel lighting and shading Synonymous with Pixel Shader 42

MINIMAL V E R T E X S H A D E R void main() { } // Transforming The Vertex gl_position = modelviewmatrix * position; MINIMAL F R A G M E N T S H A D E R void main() { } // Setting Each Pixel To Red gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); 43

MINIMAL V E R T E X S H A D E R void main() { } // Transforming The Vertex gl_position = modelviewmatrix * position; defined by Three.JS MINIMAL F R A G M E N T S H A D E R void main() { } // Setting Each Pixel To Red gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); 44

MINIMAL V E R T E X S H A D E R void main() { } // Transforming The Vertex gl_position = modelviewmatrix * position; defined by Three.JS x y z 1.0 MINIMAL F R A G M E N T S H A D E R void main() { } // Setting Each Pixel To Red gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); 45

MINIMAL V E R T E X S H A D E R void main() { } // Transforming The Vertex gl_position = modelviewmatrix * position; view coordinate system defined by Three.JS x y z 1.0 MINIMAL F R A G M E N T S H A D E R void main() { } // Setting Each Pixel To Red gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); 46

MINIMAL V E R T E X S H A D E R void main() { } // Transforming The Vertex gl_position = modelviewmatrix * position; view coordinate system defined by Three.JS x y z 1.0 MINIMAL F R A G M E N T S H A D E R void main() { } // Setting Each Pixel To Red gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); Red Green Blue Alpha 47

V E R T E X S H A D E R E X A M P L E 2 uniform float uvertexscale; attribute vec3 vcolor; varying vec3 fcolor; void main() { gl_position = vec4(position.x fcolor = vcolor; * uvertexscale, position.y, 0.0,1.0); } 48

C O N C E P T S uniform same for all vertices varying computed per vertex, automatically interpolated for fragments attribute some values per vertex available only in Vertex Shader 49

C O N C E P T S uniform same for all vertices varying Vertex Shader Fragment Shader computed per vertex, automatically interpolated for fragments attribute JS + Three.JS Vertex Shader FragmentShader JS + Three.JS VertexShader some values per vertex available only in Vertex Shader 50

V E R T E X S H A D E R 51

F R A G M E N T S H A D E R 52

A T T A C H I N G S H A D E R S var remotematerial = new THREE.ShaderMaterial({ uniforms: { remoteposition: remoteposition, },}); //here goes loading shader files into shaders[] remotematerial.vertexshader = shaders['glsl/remote.vs.glsl']; remotematerial.fragmentshader = shaders['glsl/remote.fs']; var remotegeometry = new THREE.SphereGeometry(1, 32, 32); var remote = new THREE.Mesh(remoteGeometry, remotematerial); scene.add(remote); 53

PIPELINE: MORE DETAILS 54

O P E N G L R E N D E R I N G P I P E L I N E 55

PIPELINE: MORE DETAILS 56

MODELING AND VIEWING TRANSFORMATIONS Placing objects - Modeling transformations Map points from object coordinate system to world coordinate system Looking from the camera - Viewing transformation Map points from world coordinate system to camera (or eye) coordinate system 57

58

MODELING TRANSFORMATIONS: OBJECT PLACEMENT 59

VIEWING TRANSFORMATION: LOOKING FROMA CAMERA 60

MODELING & VIEWING TRANSFORMATIONS 61

MODELING & VIEWING TRANSFORMATIONS Other transformations (not handled by rendering pipeline): Freeform deformation 62

MODELING & VIEWING TRANSFORMATION Linear transformations Rotations, scaling, shearing Can be expressed as 3x3 matrix E.g. scaling (non uniform): x' 2 0 y' 0 3 z' 0 0 0 x 0 y 1 z 63

MODELING & VIEWING TRANSFORMATION Affine transformations Linear transformations + translations Can be expressed as 3x3 matrix + 3 vector E.g. scale+ translation: x' 2 0 0 x t x y' 0 3 0 y t 0 1 z y z' 0 t z Another representation: 4x4 homogeneous matrix 64

MATRICES Object coordinates -> World coordinates Model Matrix One per object World coordinates -> Camera coordinates View Matrix One per camera 65

PIPELINE: MORE DETAILS 66

PERSPECTIVE TRANSFORMATION Purpose: Project 3D geometry to 2D image plane Simulates a camera Camera model: Pinhole camera (single view point) More complex camera models exist, but are less common in CG 67

PERSPECTIVE PROJECTION 68

PERSPECTIVE TRANSFORMATION In computer graphics: Image plane conceptually in front of center of projection Perspective transformation is one of projective transformations Linear & affine transformations also belong to this class All projective transformations can be expressed as 4x4 matrix operations 69

PIPELINE: MORE DETAILS 70

CLIPPING Removing invisible geometry Geometry outside viewing frustum Plus too far or too near one Optimization 71

PIPELINE: MORE DETAILS 72

SCAN CONVERSION/RASTERIZATION Convert continuous 2D geometry to discrete Raster display discrete grid ofelements Terminology Screen Space: Discrete 2D Cartesian coordinate system of the screen pixels 73

SCAN CONVERSION 74

SCAN CONVERSION 75

SCAN CONVERSION Problem: Line is infinitely thin, but image has finite resolution Results in steps rather than a smooth line Jaggies Aliasing One of the fundamental problems in computer graphics 76

SCAN CONVERSION 77

COLOR INTERPOLATION Linearly interpolate per-pixel color from vertex color values Treat every channel of RGB color separately color t s 78

COLOR INTERPOLATION Example: red green blue t t t s s s 79

PIPELINE: MORE DETAILS 80

TEXTURING (s 0,t 0 ) (s 2,t 2 ) t (s 1,t 1 ) s 81

TEXTURING (s 0,t 0 ) (s 2,t 2 ) t (s 1,t 1 ) s 82

TEXTURE MAPPING 83

DISPLACEMENT MAPPING 84

TEXTURING Issues: Computing 3D/2D map (low distortion) How to map pixel from texture (texels) to screen pixels Texture can appear widely distorted inrendering Magnification / minification of textures Filtering of textures Preventing aliasing (anti-aliasing) 85

PIPELINE: MORE DETAILS 86

LIGHTING 87

COMPLEX LIGHTING AND SHADING 88

PIPELINE: MORE DETAILS 89

WITHOUT HIDDEN LINE REMOVAL 90

HIDDEN LINE REMOVAL 91

HIDDEN SURFACE REMOVAL 92

DEPTH TEST /HIDDEN SURFACE REMOVAL Remove invisible geometry Parts that are hidden behind other geometry Possible Implementations: Pixel level decision Depth buffer Object space decision E.g. intersection order for ray tracing 93

PIPELINE: MORE DETAILS 94

BLENDING Blending: Fragments -> Pixels Draw from farthest to nearest No blending replace previous color Blending: combine new & old values with some arithmetic operations Frame Buffer : video memory on graphics board that holds resulting image & used to displayit 95

REFLECTION/SHADOWS 96