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

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

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

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

Stored Texture Shaders

Introduction to the OpenGL Shading Language

Preparing for Texture Access. Stored Texture Shaders. Accessing Texture Maps. Vertex Shader Texture Access

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

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

OPENGL RENDERING PIPELINE

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

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

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

Shaders. Slide credit to Prof. Zwicker

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

Introduction to Shaders.

Zeyang Li Carnegie Mellon University

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

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

Sign up for crits! Announcments

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

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

OpenGL. Shading Language. Third Edition

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

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

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

CMPS160 Shader-based OpenGL Programming

CS 354R: Computer Game Technology

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

Programmable Graphics Hardware

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

12.2 Programmable Graphics Hardware

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

Lab 9 - Metal and Glass

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

Supplement to Lecture 22

Programmable Graphics Hardware

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

Programming Graphics Hardware

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

1 of 5 9/10/ :11 PM

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

Evolution of GPUs Chris Seitz

CPSC 436D Video Game Programming

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

The Rasterization Pipeline

Mobile Application Programing: Android. OpenGL Operation

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

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

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

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

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

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

Programming Graphics Hardware

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

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

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

COMP371 COMPUTER GRAPHICS

Methodology for Lecture. Importance of Lighting. Outline. Shading Models. Brief primer on Color. Foundations of Computer Graphics (Spring 2010)

Lecture 15 of 41. Scene Graphs: State Videos 1: CGA Shorts, Demos

Mobile Application Programing: Android. OpenGL Operation

Tuesday, 23 March OpenGL Shading Language

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

CHAPTER 1 Graphics Systems and Models 3

Dave Shreiner, ARM March 2009

Introduction to the OpenGL Shading Language (GLSL)

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

0.Features of the OpenGL Shading Language

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

Intro to GPU Programming (OpenGL Shading Language) Cliff Lindsay Ph.D. Student CS WPI

0.Features of the OpenGL Shading Language

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

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

3D Programming. 3D Programming Concepts. Outline. 3D Concepts. 3D Concepts -- Coordinate Systems. 3D Concepts Displaying 3D Models

Mobile graphics API Overview

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

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

Real-time Graphics 6. Reflections, Refractions

INF3320 Computer Graphics and Discrete Geometry

Hardware Shading: State-of-the-Art and Future Challenges

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

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

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

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

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

Mobile Application Programming: Android. OpenGL Operation

Texture Mapping. Computer Graphics, 2015 Lecture 9. Johan Nysjö Centre for Image analysis Uppsala University

Computer Graphics Coursework 1

MXwendler Fragment Shader Development Reference Version 1.0

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

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

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

Advanced Deferred Rendering Techniques. NCCA, Thesis Portfolio Peter Smith

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Transcription:

Shader Programming Technical Game Development II Professor Charles Rich Computer Science Department rich@wpi.edu Reference: Rost, OpenGL Shading Language, 2nd Ed., AW, 2006 The Orange Book Also take CS 4731 Computer Graphics 1 Shader Programming graphics hardware has replaced (1 st generation) fixed functionality with programmability in: vertex processing (geometry) transformation lighting fragment (per-pixel) processing reading from texture memory procedurally computing colors, etc. OpenGL Shading Language (GLSL) is a open standard for programming such hardware other languages, e.g., RenderMan, ShaderLab, HLSL (Unreal) all have same basic principles 2 1

OpenGL Fixed Functionality Pipeline 3 OpenGL Programmable Processors 4 2

Vertex (Geometry) Processor in parallel - per vertex only! to rasterization 5 Fragment (Pixel) Processor < Interpolated from vertices in parallel - per fragment only! 6 3

GLSL Language Similar to C, C++ Builtin vector and matrix operations: vec2, vec3, vec4 mat2, mat3, mat4 Texture memory lookup sampler1d, sampler2d, sampler3d 7 Simple Shader Program Example Surface temperature coloring false color Assume temperature (user defined variable) is known at each vertex in model smoothly color surface to indicate temperature at every pixel (using interpolation) uses both a vertex and a fragment shader program working together (typical) Does coloring in parallel on GPU (much faster than using CPU) 8 4

Vertex Shader // global parameters read from application uniform float CoolestTemp; uniform float TempRange; // user-defined incoming property of this vertex attribute float VertexTemp; // output variable to communicate to the fragment shader // (via interpolation see scaling below) varying float Temperature; void main() { // communicate this vertex's temperature scaled to [0.0, 1.0] Temperature = (VertexTemp - CoolestTemp) / TempRange; } // don't move this vertex gl_position = gl_modelviewprojectionmatrix * gl_vertex; 9 Fragment Shader // global parameters read from application uniform vec3 CoolestColor; uniform vec3 HottestColor; // interpolated value from vertex shader varying float Temperature; void main() { // compute a color using built-in mix() function vec3 color = mix(coolestcolor, HottestColor, Temperature); } // set this pixel's raw color (with alpha blend of 1.0) gl_fragcolor = vec4(color, 1.0); 10 5

Shader Execution Vertex shader is run once per vertex Vertex values are interpolated to get fragment values Fragment shader is run once per pixel Many such executions can happen in parallel No communication or ordering between parallel executions no vertex-to-vertex no pixel-to-pixel 11 Another Example: Adding Noise Using shader to change geometry (!) Moving vertices randomly a bit to simulate roughness More complicated vertex shader No-op fragment shader 12 6

Vertex Shader uniform vec3 LightPosition; // global application parameters uniform vec3 SurfaceColor; uniform vec3 Offset; varying vec4 Color; // output color for pixel shader uniform float ScaleIn; // for this shader only uniform float ScaleOut; // for this shader only void main() { vec3 normal = gl_normal; // move vertex randomly vec3 vertex = gl_vertex.xyz + noise3(offset + gl_vertex.xyz * ScaleIn) * ScaleOut; // redo default color calculation based on new vertex location normal = normalize(gl_normalmatrix * normal); vec3 position = vec3(gl_modelviewmatrix * vec4(vertex,1.0)); vec3 lightvec = normalize(lightposition - position); float diffuse = max(dot(lightvec, normal), 0.0); if (diffuse < 0.125) diffuse = 0.125; Color = vec4(surfacecolor * diffuse, 1.0); } gl_position = gl_modelviewprojectionmatrix * vec4(vertex,1.0); 13 No-Op Fragment Shader varying vec4 Color; void main() { gl_fragcolor = Color; } 14 7

Procedural Textures - Stripes 15 Fragment Shader for Stripes uniform vec3 StripeColor; // global application parameters uniform vec3 BackColor; // that define striping pattern uniform vec3 Width; uniform float Fuzz; uniform float Scale; varying vec3 DiffuseColor; // inputs from vertex shader varying vec3 SpecularColor; void main() { float scaledt = fract(gl_texcoord[0].t * Scale); } float frac1 = clamp(scaledt / Fuzz, 0.0, 1.0); float frac2 = clamp((scaledt Width) / Fuzz, 0.0, 1.0); frac1 = frac1 * (1.0 - frac2); frac1 = frac1 * frac1 * (3.0 - (2.0 * frac1)); vec3 finalcolor = mix(backcolor, StripeColor, frac1) finalcolor = finalcolor * DiffuseColor + SpecularColor; gl_fragcolor = vec4(finalcolor, 1.0); 16 8

Lots More You Can Do With Shaders Procedural Textures patterns (stripes, etc.) bump mapping Lighting Effects Shadows Surface Effects refraction, diffraction Animation morphing particles 17 Lots More... Anti-aliasing Non-photorealistic effects hatching, meshes technical illustration Imaging sharpen, smooth, etc. Environmental effects (RealWorldz) terrain sky ocean 18 9

4/12/17 Screen shot of the SolidWorks application, showing a jigsaw rendered with OpenGL shaders to simulate a chrome body, galvanized steel housing, and cast iron blade. (Courtesy of SolidWorks Corporation) 19 Different glyphs applied to a cube using the glyph bombing shader described in Section 10.6. (3Dlabs, Inc.) 20 10

The lattice shader presented in Section 11.3 is applied to the cow model. (3Dlabs, Inc.) 21 A simple box and a torus that have been bump-mapped using the procedural method described in Section 11.4. (3Dlabs, Inc.) 22 11

A variety of materials rendered with Ward's BRDF model (see Section 14.3) and his measured/fitted material parameters. 23 Brick shader with and without antialiasing. On the left, the results of the brick shader presented in Chapter 6. On the right, results of antialiasing by analytic integration using the brick shader described in Section 17.4.5. (3Dlabs, Inc.) 24 12

A variety of screen shots from the 3Dlabs RealWorldz demo. Everything in this demo is generated procedurally using shaders written in the OpenGL Shading Language. This includes the planets themselves, the terrain, atmosphere, clouds, plants, oceans, and rock formations. Planets are modeled as mathematical spheres, not height fields. These scenes are all rendered at interactive rates on current generation graphics hardware 25 Shader Programming - Summary Seems to lie on the boundary between art and tech programming is hard-core (parallel algorithms) but intended result is often mostly aesthetic 26 13