Real-time Graphical Shader Programming with Cg (HLSL)

Slides:



Advertisements
Similar presentations
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
Advertisements

COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Lecture 38: Chapter 7: Multiprocessors Today’s topic –Vector processors –GPUs –An example 1.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
Introduction to Shader Programming
Cg: C for Graphics Jon Moon Based on slides by Eugene Lee.
Vertex & Pixel Shaders CPS124 – Computer Graphics Ferdinand Schober.
Cg Overview Cg is the High Level language from NVIDIA for programming GPUs, developed in close collaboration with Microsoft Cg is 100% compatible with.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Cg Kevin Bjorke GDC NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level,
High Performance in Broad Reach Games Chas. Boyd
Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
CS 480/680 Computer Graphics Course Overview Dr. Frederick C Harris, Jr. Fall 2012.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
CHAPTER 4 Window Creation and Control © 2008 Cengage Learning EMEA.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Geometric Objects and Transformations. Coordinate systems rial.html.
Advanced Computer Graphics March 06, Grading Programming assignments Paper study and reports (flipped classroom) Final project No written exams.
GPU Shading and Rendering Shading Technology 8:30 Introduction (:30–Olano) 9:00 Direct3D 10 (:45–Blythe) Languages, Systems and Demos 10:30 RapidMind.
Programmable Pipelines. 2 Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Chris Kerkhoff Matthew Sullivan 10/16/2009.  Shaders are simple programs that describe the traits of either a vertex or a pixel.  Shaders replace a.
A Crash Course in HLSL Matt Christian.
Week 3 - Monday.  What did we talk about last time?  Graphics rendering pipeline  Rasterizer Stage.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
Real-Time Shading Using Programmable Graphics Hardware Introduction, Setup and Examples Wan-Chun Ma National Taiwan University.
1 Dr. Scott Schaefer Programmable Shaders. 2/30 Graphics Cards Performance Nvidia Geforce 6800 GTX 1  6.4 billion pixels/sec Nvidia Geforce 7900 GTX.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Real-Time High Quality Rendering CSE 291 [Winter 2015], Lecture 4 Brief Intro to Programmable Shaders
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
CS 480/680 Intro Dr. Frederick C Harris, Jr. Fall 2014.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
CS662 Computer Graphics Game Technologies Jim X. Chen, Ph.D. Computer Science Department George Mason University.
Programmable Pipelines Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University.
The Cg Runtime Cyril Zeller. Cg Pipeline Graphics programs are written in Cg and compiled to low-level assembly code... Cg Runtime API...
NVIDIA FX Composer 2 Shader Authoring for Everyone Philippe Rollin Aravind Kalaiah.
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.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
Ray Tracing using Programmable Graphics Hardware
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.
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.
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.
Computer Science – Game DesignUC Santa Cruz Tile Engine.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/XX13 – GLSL Lecture 13: OpenGL Shading Language (GLSL) COMP 175: Computer Graphics April 12, 2016.
How to use a Pixel Shader CMT3317. Pixel shaders There is NO requirement to use a pixel shader for the coursework though you can if you want to You should.
COMPUTER GRAPHICS CHAPTER 38 CS 482 – Fall 2017 GRAPHICS HARDWARE
Programmable Shaders Dr. Scott Schaefer.
Programmable Pipelines
Graphics Processing Unit
Introduction to OpenGL
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
Introduction to Computer Graphics with WebGL
Day 05 Shader Basics.
UMBC Graphics for Games
Graphics Processing Unit
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
Introduction to OpenGL
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
CIS 6930: Chip Multiprocessor: GPU Architecture and Programming
Presentation transcript:

Real-time Graphical Shader Programming with Cg (HLSL) Concepts and language fundamentals

Presentation Outline Objectives Resources Shaders at a glance Graphics pipeline History Cg/HLSL Programming CgFX

Objectives Understand purposes/uses of shaders Be able to discuss shaders intelligently Be able to program/use shaders

Resources Reading Material Software *Cg Tutorial from NVIDIA *Cg Toolkit (compilers, etc.) *Cg Tutorial (editable examples from Cg Tutorial) SDK9, SDK10.5 (detailed samples) FX Composer (content authoring) NVIDIA developer’s site has more (* required or highly recommended)

Shaders at a Glance What is a Shader? Program typically used for graphical effects Runs on GPU Controls shape, appearance, and motion of objects Per-Object or full-screen Responsible for handling most OpenGL and DirectX effects May be used outside of games

Shaders at a Glance Example Lighting (basic) Human Head (advanced)

Shaders at a Glance Types of Shaders Vertex Operates on all visible vertices Geometry Requires directx10 Not covered here Fragment (pixel) Operates on fragments (think pixel) basis

Modern Graphics Pipeline From chapter 1 of the Cg Tutorial

History Graphics Cards Video Graphics Array (VGA) IBM introduced in 1987 “dumb” frame buffer Pre-GPU by SGI Vertex transformation and texturing Graphics Processing Unit (GPU) NVIDIA introduced term in late 1990s

History Graphics Cards 1st Generation (<= 1998) Only basic texturing Implement DirectX 6 2nd Generation (1999-2000) Configurable Adds vertex transformation and lighting DirectX 7 3rd Generation (2001) Programmable (barely) Fragment “shaders” in assembly DirectX 8 4th Generation (>= 2002) Fully programmable with high level languages DirectX 9

Cg/HLSL Developed in collaboration C for Graphics (Cg) Same language, different implementations Borrows ideas from RenderMan C for Graphics (Cg) NVIDIA’s implementation OpenGL or Direct3D High-Level Shading Language (HLSL) Microsoft’s implementation Direct3D

Programming Compilation Compiler part of Cg runtime library Cg runtime routines prefixed with “cg” Dynamic compilation preferred Allows specific optimizations Compilation parameters include Shader program filename Entry function name (e.g. “main”) Profile name Errors Conventional Profile-dependent Program not supported by specified profile

Programming Profiles Defines the mapping from source to native code Depends on Shader program type Vertex or fragment Language features used Graphics API used GPU capabilities Basic profiles are most portable Advanced profiles allow more features May produce more efficient code

Programming Simple Example Vertex program struct outType { float4 position : POSITION; float4 color : COLOR; }; outType shadeGreen(float2 position : POSITION) { outType OUT; OUT.position = float4(position, 0, 1); OUT.color = float4(0, 1, 0, 1); // RGBA green return OUT; }

Programming Data Types Everything is floating-point float scalar; half ; double ; Everything is vector-based (even scalars) Packed arrays (more efficient than regular arrays) float4 vec4; float4x4 myMatrix; Operations optimized but random accesses not scalar = vec4.z; // Efficient scalar = vec4[3]; // Efficient scalar = data[index]; // Inefficient or unsupported Depending on the profile, float may actually mean fixed-point, locked to the range [0, +1] or [-1, +1]. Using the fixed keyword is supported by the Cg compiler, but not the HLSL compiler.

Programming Semantics Link between pipeline and Cg program Use existing or make your own Ignored by internal functions Input/Output semantics are different Represent same concept Different stages of graphics pipeline Examples float4 position : POSITION float4 color : COLOR float2 texCoord : TEXCOORD0

Programming Other Parameter Semantics out uniform

Programming Control Flow Entry functions

Programming Swizzling Swizzling Vectors float4 vec1 = float4(4.0, -2.0, 5.0, 3.0); float2 vec2 = vec1.yx; // vec2 = (-2.0, 4.0) Smearing float scalar = vec1.w; // scalar = 3.0 float3 vec3 = scalar.xxx; // vec3 = (3.0, 3.0, 3.0) Swizzling Matrices float4x4 myMatrix; // assign somewhere float4 myFloatVec4 = myMatrix._m00_m11_m22_m33; myFloatVec4 = myMatrix[0];

Programming Write Masking float4 vec1 = float4(4.0, -2.0, 5.0, 3.0); float2 vec2 = float2(-2.0, 4.0); vec1.xw = vec2; // vec1 = (-2.0, -2.0, 5.0, 4.0) Note Can use .xyzw or .rgba, but cannot mix the two in a single swizzle or mask

Programming Transformations

Programming Phong Shader

CgFX