Introduction to Computer Graphics. Hardware Acceleration Review

Similar documents
Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programing: Android. OpenGL Operation

Mobile Application Programming: Android. OpenGL Operation

CS 380 Introduction to Computer Graphics. LAB (1) : OpenGL Tutorial Reference : Foundations of 3D Computer Graphics, Steven J.

LECTURE 02 OPENGL API

OpenGL refresher. Advanced Computer Graphics 2012

OPEN GL BACKGROUND. Objectives. Early History of APIs. SGI and GL. PHIGS and X. Modified from Angel 6e book slides

An Overview GLUT GLSL GLEW

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

Shaders. Slide credit to Prof. Zwicker

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

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

Early History of APIs. PHIGS and X. SGI and GL. Programming with OpenGL Part 1: Background. Objectives

INTRODUCTION TO OPENGL PIPELINE

Programming with OpenGL Part 1: Background

Computer Graphics. Bing-Yu Chen National Taiwan University

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 3: Shaders

Using OpenGL with CUDA

Lecture 09: Shaders (Part 1)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

OpenGL pipeline Evolution and OpenGL Shading Language (GLSL) Part 2/3 Vertex and Fragment Shaders

OpenGL and GLUT. COMP413 Computer Graphics. School of Computer Sci. & Eng. Kyungpook National University, Korea. Spring Semester, 2016

Computer Graphics (CS 4731) OpenGL/GLUT(Part 1)

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

compatibility mode core mode

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

CSE4030 Introduction to Computer Graphics

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

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

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

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)!

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

Computer Graphics (CS 543) Lecture 3b: Shader Setup & GLSL Introduction

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

Computer Graphics (CS 543) Lecture 1 (Part 2): Introduction to OpenGL/GLUT (Part 1)

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

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

Programmable shader. Hanyang University

Precept 2 Aleksey Boyko February 18, 2011

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

OPENGL RENDERING PIPELINE

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

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 4: Three Dimensions

gvirtualxray Tutorial 01: Creating a Window and an OpenGL Context Using GLUT

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

CS475/CS675 - Computer Graphics. OpenGL Drawing

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

Introduction to Shaders.

COMP371 COMPUTER GRAPHICS

Programming using OpenGL: A first Introduction

CS 432 Interactive Computer Graphics

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

Shading Language Update

Visualizing Molecular Dynamics

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

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

Mobile graphics API Overview

Programming Graphics Hardware

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

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

GLUT Tutorial. John Tsiombikas (Nuclear / The Lab Demos) May 6, Introduction to GLUT (OpenGL Utility Toolkit)

Dave Shreiner, ARM March 2009

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

CS 432 Interactive Computer Graphics

Programmable Graphics Hardware

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

Mobile Application Programming. OpenGL ES 3D

12.2 Programmable Graphics Hardware

From system point of view, a graphics application handles the user input, changes the internal state, called the virtual world by modeling or

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

Computer Graphics. OpenGL

Introduction to OpenGL Week 1

Objectives. Image Formation Revisited. Physical Approaches. The Programmer s Interface. Practical Approach. Introduction to OpenGL Week 1

C OMPUTER G RAPHICS Thursday

BCA611 Video Oyunları için 3B Grafik

Mobile Application Programming: Android. OpenGL ES 3D

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

CS 548: COMPUTER GRAPHICS INTRODUCTION TO OPENGL AND GLUT SPRING 2015 DR. MICHAEL J. REALE

OpenGL Basics I. Seoul National University Graphics & Media Lab

Graphics Programming

2D graphics with WebGL

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

CSE 4431/ M Advanced Topics in 3D Computer Graphics. TA: Margarita Vinnikov

Introduction to MS Visual C/C++

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

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

Introduction to OpenGL

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Introduction to the OpenGL Shading Language (GLSL)

Information Coding / Computer Graphics, ISY, LiTH. OpenGL! ! where it fits!! what it contains!! how you work with it 11(40)

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

More frames per second. Alex Kan and Jean-François Roy GPU Software

to OpenGL Introduction Pipeline Graphics pipeline OpenGL pipeline OpenGL syntax Modeling Arrays Conclusion 1 Introduction Introduction to OpenGL

Intro to OpenGL III. Don Fussell Computer Science Department The University of Texas at Austin

Transcription:

Introduction to Computer Graphics Hardware Acceleration Review

OpenGL Project Setup Create a command-line style project in Xcode 4 Select the project file and click Build Phases tab Add OpenGL.framework and GLUT.framework to Link list

OpenGL Project Setup Create a command-line style project in target IDE (or not...) Install libglut3-dev and libglew-dev using a package manager When compiling reference OpenGL, GLUT, GLEW libraries eg. gcc main.c -o a.out -I/usr/include -L/usr/lib -lglut -lglew -lgl

OpenGL Project Setup Create a command-line style project in Visual Studio 2010 Download and install GLUT - http://user.xmission.com/~nate/glut.html glut.h: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\GL\ glut32.lib: C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\ glut32.dll: C:\Windows\System32\ (or C:\Windows\SysWOW64\ for 64-bit) Download and install GLEW - http://glew.sourceforge.net/ glew.h, glxew.h, wglew.h: C:\Program Files\Microsoft Visual Studio 10.0\VC\include \GL\ glew32.lib: C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\ glew32.dll, glew32s.dll: C:\Windows\System32\ (or C:\Windows\SysWOW64\) Add OpenGL, GLUT, and GLEW library files to project link stage (opengl32.lib, glut32.lib, glew32.lib) Also see http://openglbook.com/setting-up-opengl-glew-and-freeglut-in-visual-c/

Hardware Acceleration

Hardware Acceleration

Hardware Acceleration 2 Processors

Hardware Acceleration

Hardware Acceleration 192 Processors

Data read from Scene and OBJ files Back-face Culling Homogeneous Divide Rasterizer Model View Matrix Projection Matrix Viewport Transform Fragments resulting from rasterization Raster Depth Test Texturing Lighting Blending

Data read from Scene and OBJ files Back-face Culling Homogeneous Divide Rasterizer Model View Matrix Projection Matrix Viewport Transform Fragments resulting from rasterization Raster Depth Test Texturing Lighting Blending

Data read from Scene and OBJ files OpenGL ES Primitive Processing Vertex Shader OpenGL ES Rasterizer Fragments resulting from rasterization Frame Buffer Fragment Shader OpenGL ES Fragment Processing

OpenGL Shading Language Defines a C-like language that can be compiled into GPU instructions Floating-point, Integer, and Boolean data types Vectors of these types in 2, 3, 4 sizes Matrices of floats in 2x2, 3x3, 4x4 1D-Arrays and Structures Special Texture types Operators on all these types

OpenGL Shading Language Variable storage qualifiers - attribute, uniform, varying Variable precision qualifiers - lowp, mediump, highp Control Statements - if, else Loops - for, while, do-while Jumps - break, continue, return Function Definition Pre-processor Directives

OpenGL Shading Language Built-in functions for basic mathematics, trigonometry, geometry, and texturing (eg. exp, tan, cross, texture2d) Built-in variables to represent inputs and outputs Vertex Shader gl_position (vec4, out) Fragment Shader gl_fragcoord (vec2, in) gl_fragcolor (vec4, out)

Host-GPU Data Transfer Global values are sent to the graphics processing hardware by changing the values of uniform variables defined in the shaders using glgetunifromlocation and gluniform* calls Geometry data is sent to the graphics processing hardware by using glvertexattribpointer Textures are sent to the graphics processing hardware by calling glbindtexture and glteximage2d Drawing is initiated by calling gldrawarrays

Parallelism Notes Be careful with the use of control structures, especially branches and loops, to preserve efficiency Code is executing in parallel, so processor groups must all terminate before starting a new batch of data Remember that this is a Single Instruction Multiple Data system (SIMD) with scattering & gathering restrictions Possible to do general computation using GLSL, but it is best to use parallel computation specific APIs like OpenCL or CUDA

Data read from Scene and OBJ files OpenGL ES Primitive Processing Vertex Shader OpenGL ES Rasterizer Fragments resulting from rasterization Frame Buffer Fragment Shader OpenGL ES Fragment Processing

Vertex Shader Receives a vertex from OpenGL after minimal processing Modifies incoming vertex in some way Outputs the vertex May also output additional data for the fragment shader to use

Vertex Shader attribute vec4 position; void main() { gl_position = position; }

Vertex Shader attribute vec4 position; uniform mat4 modelview; void main() { gl_position = modelview * position; }

Vertex Shader attribute vec4 position; uniform mat4 modelview; uniform mat4 projection; void main() { gl_position = projection * modelview * position; }

Vertex Shader attribute vec4 position; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying lowp vec2 texturecoordinatevarying; void main() { gl_position = projection * modelview * position; texturecoordinatevarying = texturecoordinate; }

Vertex Shader attribute vec4 position; attribute vec3 normal; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; varying lowp vec3 normalvarying; varying lowp vec2 texturecoordinatevarying; void main() { gl_position = projection * modelview * position; normalvarying = vec3(normalize(modelview * vec4(normal, 0.0))); texturecoordinatevarying = texturecoordinate; }

Vertex Shader attribute vec4 position; attribute vec3 normal; attribute vec2 texturecoordinate; uniform mat4 modelview; uniform mat4 projection; uniform vec4 lightposition; uniform vec4 lightambient; uniform vec4 lightdiffuse; varying lowp vec3 normalvarying; varying lowp vec2 texturecoordinatevarying; varying lowp vec4 diffusevarying; void main() { gl_position = projection * modelview * position; normalvarying = vec3(normalize(modelview * vec4(normal, 0.0))); texturecoordinatevarying = texturecoordinate; } vec4 lightvector = normalize(lightposition - gl_position); float lightincidence = dot(lightvector, vec4(normalvarying, 1.0)); diffusevarying = lightdiffuse * vec4(max(lightincidence, 0.0));

Data read from Scene and OBJ files OpenGL ES Primitive Processing Vertex Shader OpenGL ES Rasterizer Fragments resulting from rasterization Frame Buffer Fragment Shader OpenGL ES Fragment Processing

Fragment Shader Receives a fragment from OpenGL resulting from rasterizing a primitive Chooses a color for the fragment based on data given by vertex shader Outputs the fragment color

Fragment Shader void main() { gl_fragcolor = vec4(1.0, 1.0, 0.0, 1.0); }

Fragment Shader uniform vec4 color; void main() { gl_fragcolor = color; }

Fragment Shader varying vec4 color; void main() { gl_fragcolor = color; }

Fragment Shader uniform sampler2d textureunit; varying vec2 texturecoordinate; void main() { gl_fragcolor = texture2d(textureunit, texturecoordinate); }

Fragment Shader uniform vec4 color; uniform vec4 lightpositioneyecoords; varying vec4 positioneyecoords; varying vec3 normaleyecoords; void main() { vec3 incident = vec3(normalize(lightpositioneyecoords - positioneyecoords)); vec3 normal = normaleyecoords; float incidence = max(0.0, dot(incident, normal)); gl_fragcolor = color * incidence; }

Data read from Scene and OBJ files OpenGL ES Primitive Processing Vertex Shader OpenGL ES Rasterizer Fragments resulting from rasterization Frame Buffer Fragment Shader OpenGL ES Fragment Processing

Short Example Program #include <GL/glew.h> // Not needed on Mac #include <GL/glut.h> // <GLUT/glut.h> on Mac void draw(); int main(int argc, char** argv) {! glutinit(&argc, argv);! glutinitwindowsize(800, 600);! glutinitdisplaymode(glut_double GLUT_RGBA GLUT_DEPTH);! glutcreatewindow("opengl");! GLenum err = glewinit(); // Not needed on Mac! if (err!= GLEW_OK)!! ; // Output error message gluseprogram(0);! glutdisplayfunc(draw);! glutmainloop();! return 0; } void draw() {! glclearcolor(0.8f, 0.0f, 0.8f, 1.0f);! glclear(gl_color_buffer_bit);! glutswapbuffers(); }

Noise Procedural geometry needs smooth randomness Randomness should be repeatable based on inputs 1D, 2D, 3D, etc. versions of this are often called noise Ken Perlin created a good basis for noise functions http://mrl.nyu.edu/~perlin/doc/oscar.html http://mrl.nyu.edu/~perlin/noise/ http://www.dreamincode.net/forums/topic/66480-perlin-noise/ http://devmag.org.za/2009/04/25/perlin-noise/

Noise

Noise

OpenGL ES Reference Card http://www.khronos.org/ opengles/2_x/