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

Stored Texture Shaders

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

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

Introduction to the OpenGL Shading Language

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

OPENGL RENDERING PIPELINE

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

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

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

Zeyang Li Carnegie Mellon University

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

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

Shaders. Slide credit to Prof. Zwicker

Introduction to Shaders.

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

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

Sign up for crits! Announcments

Introduction to Shaders for Visualization. The Basic Computer Graphics Pipeline

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

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

Programming shaders & GPUs Christian Miller CS Fall 2011

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

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

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

Programmable Graphics Hardware

Lab 9 - Metal and Glass

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

CMPS160 Shader-based OpenGL Programming

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

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

CPSC 436D Video Game Programming

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

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

Supplement to Lecture 22

12.2 Programmable Graphics Hardware

CS 354R: Computer Game Technology

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

Programming Graphics Hardware

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

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

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

1 of 5 9/10/ :11 PM

Programmable Graphics Hardware

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

Mobile Application Programing: Android. OpenGL Operation

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

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

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

The Rasterization Pipeline

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

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

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

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

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

MXwendler Fragment Shader Development Reference Version 1.0

Lecture 17: Shading in OpenGL. CITS3003 Graphics & Animation

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

Tuesday, 23 March OpenGL Shading Language

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

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

Evolution of GPUs Chris Seitz

Mobile Application Programing: Android. OpenGL Operation

CHAPTER 1 Graphics Systems and Models 3

Introduction to the OpenGL Shading Language (GLSL)

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

Programming Graphics Hardware

Dave Shreiner, ARM March 2009

INF3320 Computer Graphics and Discrete Geometry

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

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

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

Computer Graphics Coursework 1

COMP371 COMPUTER GRAPHICS

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

0.Features of the OpenGL Shading Language

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

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

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

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

Advanced Deferred Rendering Techniques. NCCA, Thesis Portfolio Peter Smith

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

Mobile graphics API Overview

Introduction to Computer Graphics with WebGL

INF3320 Computer Graphics and Discrete Geometry

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

0.Features of the OpenGL Shading Language

CS 418: Interactive Computer Graphics. Basic Shading in WebGL. Eric Shaffer

Real-time Graphics 6. Reflections, Refractions

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

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

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

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

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

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

OpenGL shaders and programming models that provide object persistence

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 IMGD 4000 (D 12) 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 IMGD 4000 (D 12) 2 1

OpenGL Fixed Functionality Pipeline IMGD 4000 (D 12) 3 OpenGL Programmable Processors IMGD 4000 (D 12) 4 2

Vertex (Geometry) Processor in parallel - per vertex only! IMGD 4000 (D 12) 5 Fragment (Pixel) Processor < Interpolated from vertices in parallel - per fragment only! IMGD 4000 (D 12) 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 IMGD 4000 (D 12) 7 Simple Shader Program Example Surface temperature coloring Assume temperature (user defined variable) is known at each vertex in model smoothly color surface to indicate temperature at every pixel (using interpolation) Use both a vertex and a fragment shader program working together (typical) Does coloring in parallel on GPU (much faster than using CPU) IMGD 4000 (D 12) 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; IMGD 4000 (D 12) 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); IMGD 4000 (D 12) 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 IMGD 4000 (D 12) 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 IMGD 4000 (D 12) 12 6

Vertex Shader uniform vec3 LightPosition; // global application parameters uniform vec3 SurfaceColor; uniform vec3 Offset; uniform float ScaleIn; uniform float ScaleOut; varying vec4 Color; // output color for pixel shader void main() { vec3 normal = gl_normal; 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); IMGD 4000 (D 12) 13 No-Op Fragment Shader varying vec4 Color; void main() { gl_fragcolor = Color; } IMGD 4000 (D 12) 14 7

Procedural Textures - Stripes IMGD 4000 (D 12) 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); vec3 finalcolor = mix(backcolor, StripeColor, frac1) finalcolor = finalcolor * DiffuseColor + SpecularColor; gl_fragcolor = vec4(finalcolor, 1.0); IMGD 4000 (D 12) 16 8

Shaders in Engines C4 material type selection (predefined shaders) shader editor (restricted functionality) no direct access to shader code Unity predefined shaders (via GUI s) can write your own in GLSL or Shaderlab (similar) IMGD 4000 (D 12) 17 Lots More You Can Do With Shaders Procedural Textures patterns (stripes, etc.) bump mapping Lighting Effects Shadows Surface Effects refraction, diffraction Animation morphing particles IMGD 4000 (D 12) 18 9

Lots More... Anti-aliasing Non-photorealistic effects hatching, meshes technical illustration Imaging sharpen, smooth, etc. Environmental effects (RealWorldz) terrain sky ocean IMGD 4000 (D 12) 19 Shader Programming Seems to lie on the boundary between art and tech programming is hard-core (parallel algorithms) but intended result is often mostly aesthetic Additional option for A in final game project: write a simple Shaderlab or GLSL shader program (and use it in your game) IMGD 4000 (D 12) 20 10

4/20/12 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)" IMGD 4000 (D 12) 21 Different glyphs applied to a cube using the glyph bombing shader described in Section 10.6. (3Dlabs, Inc.)" IMGD 4000 (D 12) 22 11

The lattice shader presented in Section 11.3 is applied to the cow model. (3Dlabs, Inc.)" IMGD 4000 (D 12) 23 A simple box and a torus that have been bump-mapped using the procedural method described in Section 11.4. (3Dlabs, Inc.)" IMGD 4000 (D 12) 24 12

A variety of materials rendered with Ward's BRDF model (see Section 14.3) and his measured/fitted material parameters." IMGD 4000 (D 12) 25 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.)" IMGD 4000 (D 12) 26 13

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" IMGD 4000 (D 12) 27 14