OPENGL RENDERING PIPELINE

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

CPSC 436D Video Game Programming

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

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

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

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

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

CS559 Computer Graphics Fall 2015

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

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

Lecture 5 Vertex and Fragment Shaders-1. CITS3003 Graphics & Animation

Game Graphics & Real-time Rendering

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

COMP371 COMPUTER GRAPHICS

Shaders. Slide credit to Prof. Zwicker

Introduction to Shaders.

BCA611 Video Oyunları için 3B Grafik

We assume that you are familiar with the following:

Mobile Application Programing: Android. OpenGL Operation

Sign up for crits! Announcments

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

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

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

2D graphics with WebGL

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

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

Lecture 11 Shaders and WebGL. October 8, 2015

Lecture 2. Shaders, GLSL and GPGPU

Computer graphics 2: Graduate seminar in computational aesthetics

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

OpenGL shaders and programming models that provide object persistence

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

CS452/552; EE465/505. Review & Examples

Mobile Application Programming: Android. OpenGL Operation

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

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

Dave Shreiner, ARM March 2009

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

CS452/552; EE465/505. Intro to Lighting

GLSL 1: Basics. J.Tumblin-Modified SLIDES from:

Mobile Application Programing: Android. OpenGL Operation

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

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

Computer Graphics Coursework 1

CS 432 Interactive Computer Graphics

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

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

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

Programmable Graphics Hardware

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

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

WebGL A quick introduction. J. Madeira V. 0.2 September 2017

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

The Graphics Pipeline and OpenGL I: Transformations!

12.2 Programmable Graphics Hardware

Pipeline Operations. CS 4620 Lecture 14

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

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

Programming shaders & GPUs Christian Miller CS Fall 2011

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

The Graphics Pipeline

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

Zeyang Li Carnegie Mellon University

SUMMARY. CS380: Introduction to Computer Graphics Texture Mapping Chapter 15. Min H. Kim KAIST School of Computing 18/05/03.

The Graphics Pipeline

Understanding M3G 2.0 and its Effect on Producing Exceptional 3D Java-Based Graphics. Sean Ellis Consultant Graphics Engineer ARM, Maidenhead

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

HW-Tessellation Basics

Mobile graphics API Overview

Ciril Bohak. - INTRODUCTION TO WEBGL

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

Water Simulation on WebGL and Three.js

Shader Programming. Daniel Wesslén, Stefan Seipel, Examples

Objectives Shading in OpenGL. Front and Back Faces. OpenGL shading. Introduce the OpenGL shading methods. Discuss polygonal shading

The Graphics Pipeline and OpenGL I: Transformations!

Game Graphics & Real-time Rendering

Lighting and Shading II. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

The Rasterization Pipeline

Technical Game Development II. Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book IMGD 4000 (D 10) 1

3D GRAPHICS. design. animate. render

CS452/552; EE465/505. Image Formation

WebGL (Web Graphics Library) is the new standard for 3D graphics on the Web, designed for rendering 2D graphics and interactive 3D graphics.

The Basic Computer Graphics Pipeline, OpenGL-style. Introduction to the OpenGL Shading Language (GLSL)

Models and Architectures

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

Content. Building Geometry Appearance Lights Model Loaders

Introduction to the OpenGL Shading Language (GLSL)

Graphics Hardware. Instructor Stephen J. Guy

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

CSE 167. Discussion 03 ft. Glynn 10/16/2017

Information Coding / Computer Graphics, ISY, LiTH GLSL. OpenGL Shading Language. Language with syntax similar to C

Introduction to the OpenGL Shading Language

Rasterization Overview

CS 354R: Computer Game Technology

The Transition from RenderMan to the OpenGL Shading Language (GLSL)

Converts geometric primitives into images Is split into several independent stages Those are usually executed concurrently

CS451Real-time Rendering Pipeline

Introduction to Computer Graphics with WebGL

Geometry Shaders. And how to use them

Transcription:

CPSC 314 03 SHADERS, OPENGL, & JS UGRAD.CS.UBC.CA/~CS314 Textbook: Appendix A* (helpful, but different version of OpenGL) Alla Sheffer Sep 2016 OPENGL RENDERING PIPELINE 1

OPENGL RENDERING PIPELINE Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) THREE.JS 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 2

GEOMETRY Triangle meshes Set of vertices Triangle defines as vertex_index1, vertex_index2, vertex_index3} 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 ); GEOMETRY (JAVASCRIPT/THRE.JS) 3

OPENGL RENDERING PIPELINE Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) GLSL 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) 4

VERTEX SHADER VS is run for each vertex SEPARATELY By default doesn t know connectivity Input: vertex coordinates in Object Coordinate System It s main goal is to set gl_position Object coordinates -> WORLD coordinates -> VIEW coordinates VERTEX SHADER 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] 5

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 ); GEOMETRY (JAVASCRIPT/THRE.JS) Image Egon Rath 6

TRANSFORMATIONS SNEAK PEEK All the transformations are done via 4x4 matrices: 0 0 0 1 TRANSFORMATIONS SNEAK PEEK All the transformations are done via 4x4 matrices: Transformed Point Coordinates 0 0 0 1 Some weird matrix Point Coordinates 7

TRANSFORMATIONS SNEAK PEEK What does this transformation do? 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 1? TRANSFORMATIONS SNEAK PEEK What does this transformation do? 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 1 2 3 8

OPENGL RENDERING PIPELINE Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) 9

CAMERA VIEW RASTERIZATION 10

RASTERIZATION RASTERIZATION 11

RASTERIZATION - INTERPOLATION RASTERIZATION - INTERPOLATION 12

OPENGL RENDERING PIPELINE Javascript + Three.JS GLSL (automatic) (automatic) GLSL (automatic) FRAGMENT SHADER Fragment = data for drawing a pixel Has gl_fragcoord 2D window coords May set color! 13

FRAGMENT SHADER Common Tasks: texture mapping per-pixel lighting and shading Synonymous with Pixel Shader MINIMAL VERTEX SHADER } // Transforming The Vertex gl_position = modelviewmatrix * position; MINIMAL FRAGMENT SHADER // Setting Each Pixel To Red gl_fragcolor = vec4(, 0.0, 0.0, ); } 14

MINIMAL VERTEX SHADER } // Transforming The Vertex gl_position = modelviewmatrix * position; defined by Three.JS MINIMAL FRAGMENT SHADER // Setting Each Pixel To Red gl_fragcolor = vec4(, 0.0, 0.0, ); } MINIMAL VERTEX SHADER } // Transforming The Vertex gl_position = modelviewmatrix * position; defined by Three.JS MINIMAL FRAGMENT SHADER // Setting Each Pixel To Red gl_fragcolor = vec4(, 0.0, 0.0, ); } 15

MINIMAL VERTEX SHADER // Transforming The Vertex gl_position = modelviewmatrix * position; } view coordinate system defined by Three.JS MINIMAL FRAGMENT SHADER // Setting Each Pixel To Red gl_fragcolor = vec4(, 0.0, 0.0, ); } MINIMAL VERTEX SHADER // Transforming The Vertex gl_position = modelviewmatrix * position; } view coordinate system defined by Three.JS MINIMAL FRAGMENT SHADER // Setting Each Pixel To Red gl_fragcolor = vec4(, 0.0, 0.0, ); } Red Green Blue Alpha 16

VERTEX SHADER EXAMPLE 2 uniform float uvertexscale; attribute vec3 vcolor; varying vec3 fcolor; gl_position = vec4(position.x * uvertexscale, position.y, 0.0,); fcolor = vcolor; } CONCEPTS uniform same for all vertices varying computed per vertex, automatically interpolated for fragments attribute some values per vertex available only in Vertex Shader 17

CONCEPTS uniform JS + Three.JS Vertex Shader Fragment Shader same for all vertices varying Vertex Shader Fragment Shader computed per vertex, automatically interpolated for fragments attribute JS + Three.JS Vertex Shader some values per vertex available only in Vertex Shader VERTEX SHADER 18

FRAGMENT SHADER ATTACHING SHADERS 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); 19