OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

Basics. OpenGL. “Hello world” George Georgiev Telerik Corporation
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
MAT 594CM S10Fundamentals of Spatial ComputingAngus Forbes Week 5 : GLSL Shaders Topics: Shader syntax, passing textures into shaders, per-pixel lighting,
What is OpenGL? Low level 2D and 3D Graphics Library Competitor to Direct3D (the rendering part of DirectX) Used in: CAD, virtual reality, scientific.
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
LAB #1: Computer Graphics Framework IGX is a set of programs which allow you to write graphics programs in C/C++ from plain text files. Benefits: 1. You.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
Overview of 3D Computer Graphics
COS 397 Computer Graphics Assoc. Prof. Svetla Boytcheva AUBG 2013 COS 397 Computer Graphics Practical Session №1 Introduction to OpenGL, GLFW and CG.
What is ? Open Graphics Library A cross-language, multi-platform API for rendering 2D and 3D computer graphics. The API is used to interact with a Graphics.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
WebGL: in-browser 3D graphics Nick Whitelegg Maritme and Technology Faculty Southampton Solent University.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics I, Fall 2008 Introduction to Computer Graphics.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1. OpenGL/GLU/GLUT  OpenGL v4.0 (latest) is the “core” library that is platform independent  GLUT v3.7 is an auxiliary library that handles window creation,
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
Lecture by: Martin Deschamps CSE 4431
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.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
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.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
OpenGL: The Open Graphics Language Introduction By Ricardo Veguilla.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
 Learn some important functions and process in OpenGL ES  Draw some triangles on the screen  Do some transformation on each triangle in each frame.
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.
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
OpenGL Shading Language
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
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.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
Introduction to OpenGL (INF 250) Veronika Solteszova et al., UiB Dept. of Informatics,
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
OpenGL: The Open Graphics Language Technology and Historical Overview By Ricardo Veguilla.
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Programmable Pipelines
OpenGL API 2D Graphic Primitives
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics
Programming with OpenGL Part 3: Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
Introduction to Computer Graphics with WebGL
OpenGL-Rendering Pipeline
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum

OpenGL  OpenGL (Open Graphics Library) is a standard specification defining a cross- language cross-platform API for writing applications that produce 3D computer graphics and 2D computer graphics as well. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. Con’t

 OpenGL was developed by  Silicon Graphics Inc. (SGI) in 1992 and is popular in the video game industry where it competes with Direct3D on Microsoft Windows platforms. OpenGL is also widely used in CAD, virtual reality, scientific visualization, information visualization, flight simulation and video game development. OpenGL con’t

 Background of OpenGL  With the recent advancements in graphics cards, new features have been added to allow for increased flexibility in the rendering pipeline at the vertex and fragment level. Programmability at this level is achieved with the use of fragment and vertex shaders. 

Details  Data Types  The OpenGL Shading Language Specification defines 22 basic data types. Some are the same as used in the C programming language, while others are specific to graphics processing.  Bool- conditional type, values may be either true or false  Int- a signed integer  Data types con’t

Data types con’t  Float- a floating point number  vec2 – a 2 component floating point vector  vec3 – a 3 component floating point vector  vec4 – a 4 component floating point vector  bvec2 – a 2 component Boolean vector  bvec3 – a 3 component Boolean vector  bvec4 – a 4 component Boolean vector  ivec2 – a 2 component vector of integers

Data types con’t  ivec3 – a 3 component vector of integers  ivec4 – a 4 component vector of integers  mat2 – a 2X2 matrix of floating point numbers  mat3 – a 3X3 matrix of floating point numbers  mat4 – a 4X4 matrix of floating point numbers  sampler1D – a handle for accessing a texture with 1 dimension  sampler2D – a handle for accessing a texture with 2 dimensions

Data types con’t sampler3D – a handle for accessing a texture with 3 dimensions samplerCube – a handle for accessing cube mapped textures sampler1Dshadow – a handle for accessing a depth texture in one dimension sampler2Dshadow – a handle for accessing a depth texture in two dimensions

Operators  The OpenGL Shading Language provides many operators familiar to those with a background in using the C programming language. This gives shader developers flexibility when writing shaders. GLSL contains the operators in C and C++, with the exception of bitwise operators and pointers. C programming languageoperators in C and C++ pointersC programming languageoperators in C and C++ pointers

Functions and Control structures  Similar to the C programming language, GLSL supports loops and branching, including if, else, if/else, for, do-while, break, continue, etc. C programming languageC programming language

Con’t  User defined functions are supported, and a wide variety of commonly used functions are provided built-in as well. This allows the graphics card manufacturer the ability to optimize these built in functions at the hardware level if they are inclined to do so. Many of these functions are similar to those found in the C programming language such as exp() and abs() while others are specific to graphics programming such as smoothstep() and texture2D().

Compilation and Execution  GLSL shaders are not stand-alone applications; they require an application that utilizes the OpenGL API. C, C++, C#, Delphi and Java all support the OpenGL API and have support for the OpenGL Shading Language. OpenGL

Con’t  GLSL shaders themselves are simply a set of strings that are passed to the hardware vendor’s driver for compilation from within an application using the OpenGL API’s entry points. Shaders can be created on the fly from within an application or read in as text files, but must be sent to the driver in the form of a string

Con’t  The set of APIs used to compile, link, and pass parameters to GLSL programs are specified in three OpenGL extensions, and became part of core OpenGL as of OpenGL Version 2.0. These OpenGL APIs are found in the extensions: OpenGL Version 2.0 OpenGL Version 2.0  ARB vertex shader ARB vertex shader ARB vertex shader  ARB fragment shader ARB fragment shader ARB fragment shader  ARB shader objects ARB shader objects ARB shader objects

Example  A sample trivial GLSL Vertex Shader  void main(void) { gl_Position = ftransform(); }  A sample trivial GLSL Fragment Shader  void main(void) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); } void main(void) { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }

Example  This example will draw a green square on the screen. OpenGL has several ways to accomplish this task, but this is the easiest to understand.  glClear( GL_COLOR_BUFFER_BIT ); This statement clears the color buffer, so that the screen will start blank. This statement clears the color buffer, so that the screen will start blank.

Con’t  glMatrixMode( GL_PROJECTION ); /* Subsequent matrix commands will affect the projection matrix */ glLoadIdentity(); /* Initialise the projection matrix to identity */ glFrustum( -1, 1, -1, 1, 1, 1000 ); /* Apply a perspective- projection matrix */ These statements initialize the projection matrix, setting a 3d frustum matrix that represents the viewable area. This matrix transforms objects from camera-relative space to OpenGL's projection space. These statements initialize the projection matrix, setting a 3d frustum matrix that represents the viewable area. This matrix transforms objects from camera-relative space to OpenGL's projection space.frustum

Con’t  glMatrixMode( GL_MODELVIEW ); /* Subsequent matrix commands will affect the modelview matrix */ glLoadIdentity(); /* Initialise the modelview to identity */ glTranslatef( 0, 0, -3 ); /* Translate the modelview 3 units along the Z axis */ These statements initialize the modelview matrix. This matrix defines a transform from model-relative coordinates to camera space. The combination of the modelview matrix and the projection matrix transforms objects from model-relative space to projection screen space These statements initialize the modelview matrix. This matrix defines a transform from model-relative coordinates to camera space. The combination of the modelview matrix and the projection matrix transforms objects from model-relative space to projection screen space

Con’t  glBegin( GL_POLYGON ); /* Begin issuing a polygon */ glColor3f( 0, 1, 0 ); /* Set the current color to green */ glVertex3f( -1, -1, 0 ); /* Issue a vertex */ glVertex3f( -1, 1, 0 ); /* Issue a vertex */

Con’t  glVertex3f( 1, 1, 0 ); /* Issue a vertex */ glVertex3f( 1, -1, 0 ); /* Issue a vertex */ glEnd(); /* Finish issuing the polygon */ These commands draw a green square in the XY plane. These commands draw a green square in the XY plane.