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

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

Introduction to the OpenGL Shading Language (GLSL)

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Supplement to Lecture 22

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

12.2 Programmable Graphics Hardware

Programmable Graphics Hardware

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

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

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

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

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

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

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

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

Introduction to the OpenGL Shading Language

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

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

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

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

OpenGL Programmable Shaders

Programmable Graphics Hardware

Sign up for crits! Announcments

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

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

Stripes, Rings, and Dots!

Introduction to Shaders.

GLSL Geometry Shaders

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

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

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

GPU Programming EE Final Examination

Using Shaders for Lighting

2D graphics with WebGL

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

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

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

Programming Graphics Hardware

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Lecture 09: Shaders (Part 1)

INF3320 Computer Graphics and Discrete Geometry

OPENGL RENDERING PIPELINE

CMPS160 Shader-based OpenGL Programming. All slides originally from Prabath Gunawardane, et al. unless noted otherwise

Graphics Shaders. Theory and Practice. Second Edition. Mike Bailey. Steve Cunningham. CRC Press. Taylor&FnincIs Croup tootutor London New York

Vertex Buffers. Mike Bailey. What is a Vertex Buffer?

Vertex Buffers. Mike Bailey. Computer Graphics VertexBuffers.pptx

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

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

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

Best practices for effective OpenGL programming. Dan Omachi OpenGL Development Engineer

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

GPU Programming EE Final Examination

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

E.Order of Operations

Programmable GPUs Outline

GLSL v1.20. Scott MacHaffie Schrödinger, Inc.

Using Shaders for Lighting

Objectives. Open GL Shading Language (GLSL)

The OpenGL Shading Language

Pipeline Operations. CS 4620 Lecture 14

COURSE 17: STATE-OF-THE-ART IN SHADING HARDWARE1 CHAPTER 6: THE OPENGL SHADING LANGUAGE 2. Randi J. Rost 3Dlabs, Inc.

Lecture 2. Shaders, GLSL and GPGPU

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

Dave Shreiner, ARM March 2009

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

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

Shading Language Update

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

GLSL Language Details

Design Focus. GLSL Language Details. Additions from C++ Additions for Graphics

A Tessellated Parametric Triangular Bézier Patch

CS 432 Interactive Computer Graphics

OpenGL Performances and Flexibility

Lab 9 - Metal and Glass

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

Vertex & Fragment shaders

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

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 3: Shaders

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

We assume that you are familiar with the following:

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

WebGL and GLSL Basics. CS559 Fall 2016 Lecture 14 October

Advanced Rendering Techniques

Shaders. Slide credit to Prof. Zwicker

Levy: Constraint Texture Mapping, SIGGRAPH, CS 148, Summer 2012 Introduction to Computer Graphics and Imaging Justin Solomon

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

CS770/870 Fall 2015 Advanced GLSL

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

Sung-Eui Yoon ( 윤성의 )

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

Introduction to Computer Graphics. Hardware Acceleration Review

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

Tuesday, 23 March OpenGL Shading Language

GLSL. OpenGL Shading Language. OpenGL 1.5 Logical Diagram. OpenGL 2.0 Logical Diagram

Transcription:

1 The Transition from RenderMan to the OpenGL Shading Language (GLSL) Mike Bailey mjb@cs.oregonstate.edu This work is licensed under a Creative Commons Attribution-NonCommercial- NoDerivatives 4.0 International License prman_to_glsl.pptx All Six RenderMan Shader Types 2 1. Displacement GLSL Vertex Shader 2. Distortion / transformation 3. Surface GLSL Fragment Shader 4. Lighting 5. Atmospheric / volumetric 6. Imaging RenderMan Built-in Microfaceting Manual or GLSL Tessellation 1

Fundamental Differences Between RenderMan Shaders and OpenGL Shaders 3 Topic RenderMan GLSL Goals 1. Image quality, 2. Speed 1. Speed, 2. Image quality Shader Types Surface, Displacement (+4 others) Vertex, Fragment, Geometry, Tessellation, Compute Surface Preprocessing Microfacets None [ ± Tessellation shaders] Recompute Normals CalculateNormal None Getting Rid of Pixels Oi = 0.; discard; Surface/Fragment shader sets R, G, B, αr, αg, αb R, G, B, A [,Z] Shader Variables Uniform, Varying Attribute, Uniform, Out, In Coordinate Systems Shader (Object), World Model (=OC), Eye ( WC) Noise Built-in Somewhat built-in or use a Texture Compile Shaders Must do yourself Driver does it for you Compiler messages Cryptic Cryptic GLSL Variable Types 4 Attribute Uniform Out / In Assigned per-vertex and passed into the vertex shader, usually with the intent to interpolate through the rasterizer. Global values, assigned and left alone for a group of primitives. Read-only accessible from all of your shaders. (Cannot be written from a shader.) Passed from one shader stage to the next shader stage. 2

GLSL Shaders Are Like C With Extensions for Graphics: 5 Types include int, ivec2, ivec3, ivec4 Types include float, vec2, vec3, vec4 Types include mat2, mat3, mat4 Types include bool, bvec2, bvec3, bvec4 Types include sampler to access textures Vector components are accessed with [index],.rgba,.xyzw, or.stpq Can ask for parallel SIMD operations (doesn t necessarily do it in hardware): vec4 a, b, c; a = b + c; Vector components can be swizzled ( c1.rgba = c2.abgr ) Type qualifiers: const, attribute, uniform, varying, in, out Variables can have layout qualifiers (more on this later) Thediscard operator is used in fragment shaders to get rid of the current fragment The discard Operator 6 if( alpha == 0. ) discard; 3

GLSL Shaders Are Missing Some C-isms: 7 No type casts (use constructors instead) Only some automatic promotion (don t rely on it) No pointers No strings No enums Can only use 1-D arrays (no bounds checking) Warning: integer division is still integer division! float f = 2 / 4; // still gives 0. The Shaders View of the Basic Pipeline 8 In general, you want to have a vertex and fragment shader as a minimum. A missing stage is OK. The output from one stage becomes the input of the next stage that is there. The last stage before the fragment shader feeds its output variables into the rasterizer. The interpolated values then go to the fragment shaders = Fixed Function = Programmable 4

GLSL Vertex Shader Inputs and Outputs 9 Standard OpenGL per-vertex Attribute variables: gl_vertex gl_normal, gl_color, etc. User-defined per-vertex in (Attribute) variables: avertex, acolor, atemperature, etc. Built-in Uniform Variables: gl_modelviewmatrix, etc. User-defined Uniform Variables: uthreshhold, etc. User-defined out (Varying): vst, vmcpos, vtemperature, etc. Special: gl_position, gl_pointsize, etc. = Must Fill! A GLSL Vertex Shader Replaces These Operations: 10 Vertex transformations Normal transformations Normal normalization (unitization) Handling of per-vertex lighting Handling of texture coordinates A GLSL Vertex Shader Does Not Replace These Operations: View volume clipping Homogeneous division (divide by w) Viewport mapping Backface culling Polygon mode Polygon offset 5

Built-in Vertex Shader Variables You Will Use a Lot: 11 vec4 gl_vertex vec3 gl_normal vec4 gl_color vec4 gl_multitexcoordi (i=0, 1, 2, ) mat4 gl_modelviewmatrix mat4 gl_projectionmatrix mat4 gl_modelviewprojectionmatrix mat4 gl_normalmatrix (this is the transpose of the inverse of the MV matrix) vec4 gl_position GLSL Fragment Shader Inputs and Outputs 12 User-defined in (Varying): vst, vmcpos, vtemperature, etc. Special in: gl_fragcoord, etc. Built-in Uniform Variables: gl_modelviewmatrix, etc. User-defined Uniform Variables: uthreshhold, etc. Special out variables: gl_fragcolor, gl_fragdepth, etc. = Must Fill! 6

A GLSL Fragment Shader Replaces These Operations: 13 Color computation Texturing Color arithmetic Handling of per-pixel lighting Fog Blending Discarding fragments A GLSL Fragment Shader Does Not Replace These Operations: Stencil test Z-buffer test Stippling Built-in Fragment Shader Variables You Will Use a Lot: 14 vec4 gl_fragcolor 7

GLSL Deprecation Transitioning from Built-in Variables 15 Variables like gl_vertex and gl_modelviewmatrix have been built-in to the GLSL language. However, starting with Desktop OpenGL 3.0, they have been deprecated in favor of you defining your own variables and passing them in from the application yourself. The built-ins still work, but be prepared for them to maybe go away some day. Also, OpenGL-ES has already completely eliminated the built-ins. What to do? I now pretend that we have created variables in an application and have passed them in. So, lines of code would be changed to look like: vec4 ModelCoords = gl_vertex ; vec4 ModelCoords = avertex ; vec4 EyeCoords = gl_modelviewmatrix * gl_vertex ; vec4 EyeCoords = umodelviewmatrix * avertex ; vec4 ClipCoords = gl_modelviewprojectionmatrix * gl_vertex ; vec4 ClipCoords = umodelviewprojectionmatrix * avertex ; vec3 TransfNorm = gl_normalmatrix * gl_normal ; vec3 TransfNorm = unormalmatrix * anormal ; Why do some of the variables begin with a? Why do some begin with u? My Own Variable Naming Convention 16 With 7 different places GLSL variables can be written from, I decided to adopt a naming convention to help recognize what variables came from what sources: Beginning letter(s) a u v tc te g f Means that the variable Is a per-vertex attribute from the application Is a uniform variable from the application Came from the vertex shader Came from the tessellation control shader Came from the tessellation evaluation shader Came from the geometry shader Came from the fragment shader This isn t part of official OpenGL it is my way of handling the confusion 8

Handling the Transition Now 17 This is how I equivalence the new names to the deprecated (but still working) ones: // uniform variables: #define umodelviewmatrix #define uprojectionmatrix #define umodelviewprojectionmatrix #define unormalmatrix #define umodelviewmatrixinverse // attribute variables: #define acolor #define anormal #define avertex #define atexcoord0 #define atexcoord1 #define atexcoord2 #define atexcoord3 #define atexcoord4 #define atexcoord5 #define atexcoord6 #define atexcoord7 gl_modelviewmatrix gl_projectionmatrix gl_modelviewprojectionmatrix gl_normalmatrix gl_modelviewmatrixinverse gl_color gl_normal gl_vertex gl_multitexcoord0 gl_multitexcoord1 gl_multitexcoord2 gl_multitexcoord3 gl_multitexcoord4 gl_multitexcoord5 gl_multitexcoord6 gl_multitexcoord7 File gstap.h This isn t part of official OpenGL it is my way of handling the transition One Additional Warning: There will be times that the Shader Compiler will appear to have gone insane 18 A uniform variable that exists, but is not actually needed by the shaders, gets eliminated by the shader compiler and appears, to the main program, to be non-existent. You will then get an error when you try to set it from the glib file, even though you are positive it exists! Glib file: Program Bad LightPos [0. 0. 10. 1.] Message: Frag file: uniform vec4 LightPos; void main( ) { gl_fragcolor = vec4( 0., 0., 1., 1. ); // LightPos never affects a pixel } BTW, a uniform variable that never gets set will not generate any sort of error it will just quietly screw up with an undefined value in your shaders. 9