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

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

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

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

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

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

Supplement to Lecture 22

2D graphics with WebGL

Objectives. Open GL Shading Language (GLSL)

CS 432 Interactive Computer Graphics

Today s Agenda. Shaders fundamentals. Programming with shader-based OpenGL

Computer Graphics (CS 4731) & 2D Graphics Systems

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

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

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

12.2 Programmable Graphics Hardware

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

Programmable Graphics Hardware

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

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

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

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

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

Shaders. Slide credit to Prof. Zwicker

Programming with OpenGL Part 5: More GLSL. Ed Angel Professor Emeritus of Computer Science University of New Mexico

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

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

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

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

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

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

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

Lecture 09: Shaders (Part 1)

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

Some advantages come from the limited environment! No classes. Stranight ans simple code. Remarkably. Avoids most of the bad things with C/C++.

Mobile Application Programing: Android. OpenGL Operation

Shaders. Introduction. OpenGL Grows via Extensions. OpenGL Extensions. OpenGL 2.0 Added Shaders. Shaders Enable Many New Effects

Shading Language Update

Introduction to Shaders.

Programmable Graphics Hardware

The Graphics Pipeline

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

Lecture 2. Shaders, GLSL and GPGPU

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

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

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

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

The Graphics Pipeline

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Lecture 9(B): GPUs & GPGPU

Introduction to GLSL. Announcements. Agenda. Course Contents. Patrick Cozzi University of Pennsylvania CIS Fall 2012

OPENGL RENDERING PIPELINE

Introduction to the OpenGL Shading Language (GLSL)

Mobile Application Programing: Android. OpenGL Operation

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

Sign up for crits! Announcments

Objectives. Coupling GLSL to Applications Example applications

Shading Languages. Ari Silvennoinen Apri 12, 2004

Zeyang Li Carnegie Mellon University

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

GPU Programming EE Final Examination

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

Introduction to Computer Graphics. Hardware Acceleration Review

OUTLINE. Implementing Texturing What Can Go Wrong and How to Fix It Mipmapping Filtering Perspective Correction

The OpenGL Shading Language

An Overview GLUT GLSL GLEW

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

GLSL II. Objectives. Coupling GLSL to Applications Example applications

Programmable Shading. University of Texas at Austin CS354 - Computer Graphics

0.Features of the OpenGL Shading Language

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

0.Features of the OpenGL Shading Language

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

Introduction to Computer Graphics with WebGL

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

OpenGL Programmable Shaders

COMP371 COMPUTER GRAPHICS

Programmable shader. Hanyang University

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

Mobile Application Programming: Android. OpenGL Operation

Programming Graphics Hardware

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

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

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

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

The Projection Matrix

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

BCA611 Video Oyunları için 3B Grafik

Introduction to Computer Graphics with WebGL

Computer Graphics with OpenGL ES (J. Han) Chapter 6 Fragment shader

Appendix A Cg Language Specification

Fog example. Fog is atmospheric effect. Better realism, helps determine distances

Mobile graphics API Overview

Programming shaders & GPUs Christian Miller CS Fall 2011

Introduction to the OpenGL Shading Language

CS475/CS675 - Computer Graphics. OpenGL Drawing

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

Advanced Graphics. The Shader knows. Alex Benton, University of Cambridge Supported in part by Google UK, Ltd

CPSC 436D Video Game Programming

Transcription:

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

Objectives Simple Shaders - Vertex shader - Fragment shaders Programming shaders with GLSL Finish first program 2

Vertex Shader Applications Moving vertices - Morphing - Wave motion - Fractals Lighting - More realistic models - Cartoon shaders 3

Fragment Shader Applications Per fragment lighting calculations per vertex lighting per fragment lighting 4

Fragment Shader Applications Texture mapping smooth shading environment mapping bump mapping 5

Writing Shaders First programmable shaders were programmed in an assembly-like manner OpenGL extensions added for vertex and fragment shaders Cg (C for graphics) C-like language for programming shaders - Works with both OpenGL and DirectX - Interface to OpenGL complex OpenGL Shading Language (GLSL) 6

GLSL OpenGL Shading Language Part of OpenGL 2.0 and up High level C-like language New data types - Matrices - Vectors - Samplers As of OpenGL 3.1, application must provide shaders 7

Simple Vertex Shader in vec4 vposition; void main(void) { gl_position = vposition; } 8

Execution Model Vertex data Shader Program GPU Application Program gldrawarrays Vertex Shader Vertex Primitive Assembly 9

Simple Fragment Program void main(void) { gl_fragcolor = vec4(1.0, 0.0, 0.0, 1.0); } 10

Execution Model Shader Program Application Rasterizer Fragment Shader Frame Buffer Fragment Fragment Color 11

Data Types C types: int, float, bool Vectors: - float vec2, vec3, vec4 - Also int (ivec) and boolean (bvec) Matrices: mat2, mat3, mat4 - Stored by columns - Standard referencing m[row][column] C++ style constructors - vec3 a =vec3(1.0, 2.0, 3.0) - vec2 b = vec2(a) 12

Pointers There are no pointers in GLSL We can use C structs which can be copied back from functions Because matrices and vectors are basic types they can be passed into and output from GLSL functions, e.g. mat3 func(mat3 a) 13

Qualifiers GLSL has many of the same qualifiers such as const as C/C++ Need others due to the nature of the execution model Variables can change - Once per primitive - Once per vertex - Once per fragment - At any time in the application Vertex attributes are interpolated by the rasterizer into fragment attributes 14

Attribute Qualifier Attribute-qualified variables can change at most once per vertex There are a few built in variables such as gl_position but most have been deprecated User defined (in application program) - Use in qualifier to get to shader -in float temperature -in vec3 velocity 15

Uniform Qualified Variables that are constant for an entire primitive Can be changed in application and sent to shaders Cannot be changed in shader Used to pass information to shader such as the bounding box of a primitive 16

Varying Qualified Variables that are passed from vertex shader to fragment shader Automatically interpolated by the rasterizer Old style used the varying qualifier varying vec4 color; Now use out in vertex shader and in in the fragment shader out vec4 color; 17

Example: Vertex Shader const vec4 red = vec4(1.0, 0.0, 0.0, 1.0); out vec3 color_out; void main(void) { gl_position = vposition; color_out = red; } 18

Required Fragment Shader in vec3 color_out; void main(void) { gl_fragcolor = color_out; } // in latest version use form // out vec4 fragcolor; // fragcolor = color_out; 19

Passing values call by value-return Variables are copied in Returned values are copied back Three possibilities - in - out - inout (deprecated) 20

Operators and Functions Standard C functions - Trigonometric - Arithmetic - Normalize, reflect, length Overloading of vector and matrix types mat4 a; vec4 b, c, d; c = b*a; // a column vector stored as a 1d array d = a*b; // a row vector stored as a 1d array 21

Swizzling and Selection Can refer to array elements by element using [] or selection (.) operator with - x, y, z, w - r, g, b, a - s, t, p, q -a[2], a.b, a.z, a.p are the same Swizzling operator lets us manipulate components vec4 a; a.yz = vec2(1.0, 2.0); 22