A Crash Course in HLSL Matt Christian.

Slides:



Advertisements
Similar presentations
Exploration of advanced lighting and shading techniques
Advertisements

POST-PROCESSING SET09115 Intro Graphics Programming.
Exploration of bump, parallax, relief and displacement mapping
Bump Mapping CSE 781 Roger Crawfis.
Graphics Pipeline.
CP411 Computer Graphics, Wilfrid Laurier University Introduction # 1 Welcome to CP411 Computer Graphics 2012 Instructor: Dr. Hongbing Fan Introduction.
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.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
Introduction to Shader Programming
GLSL I May 28, 2007 (Adapted from Ed Angel’s lecture slides)
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
IN4151 Introduction 3D graphics 1 Introduction to 3D computer graphics part 2 Viewing pipeline Multi-processor implementation GPU architecture GPU algorithms.
Status – Week 277 Victor Moya.
Graphics Systems I-Chen Lin’s CG slides, Doug James’s CG slides Angel, Interactive Computer Graphics, Chap 1 Introduction to Graphics Pipeline.
The Graphics Pipeline CS2150 Anthony Jones. Introduction What is this lecture about? – The graphics pipeline as a whole – With examples from the video.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
CSE 381 – Advanced Game Programming Shading.
Shading Languages By Markus Kummerer. Markus Kummerer 2 / 19 State of the Art Shading.
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.
SET09115 Intro Graphics Programming
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
Introduction to Nikola Mihaylov, Sep 1, 2008.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
Programmable Pipelines. Objectives Introduce programmable pipelines ­Vertex shaders ­Fragment shaders Introduce shading languages ­Needed to describe.
Real-time Graphical Shader Programming with Cg (HLSL)
Geometric Objects and Transformations. Coordinate systems rial.html.
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.
Computer Graphics An Introduction. What’s this course all about? 06/10/2015 Lecture 1 2 We will cover… Graphics programming and algorithms Graphics data.
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.
CS 450: COMPUTER GRAPHICS REVIEW: INTRODUCTION TO COMPUTER GRAPHICS – PART 2 SPRING 2015 DR. MICHAEL J. REALE.
1 Introduction to Computer Graphics SEN Introduction to OpenGL Graphics Applications.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
COMPUTER GRAPHICS CSCI 375. What do I need to know?  Familiarity with  Trigonometry  Analytic geometry  Linear algebra  Data structures  OOP.
Advanced Computer Graphics Advanced Shaders CO2409 Computer Graphics Week 16.
Eighty-color-channel lighting Zoltán Márton Cecília Sik Lányi University of Pannonia Egyetem u. 10.
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.
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.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
Ray Tracing using Programmable Graphics Hardware
Current Student – University of Wisconsin – Stout Applied Mathematics and Computer Science: Software Development Associate Degree in Computer Programming.
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.
GPU Computing for GIS James Mower Department of Geography and Planning University at Albany.
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.
Programmable Pipelines
Graphics Processing Unit
Deferred Lighting.
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
GLSL I Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts Director, Arts Technology Center University of New Mexico.
Introduction to Computer Graphics with WebGL
UMBC Graphics for Games
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
03 | Creating, Texturing and Moving Objects
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

A Crash Course in HLSL Matt Christian

Agenda About Me What is HLSL? What is a Shader? HLSL/Shader History Vertex Shaders Pixel Shaders Geometry Shaders HLSL/Shader History How Does It Work? HLSL Code Segments

Agenda (Cont’d) Shader Examples Implementing a Simple Shader Shader Overview Engine Implementation Post Processing Shaders Conclusion Web Links Extras

About Me Student at University of Wisconsin – Stout Studying Applied Mathematics and Computer Science: Software Development Graduated with honors from Northcentral Technical College Associates Degree in Computer Programming – 2006 Avid gamer and general game development junkie

What is HLSL? Microsoft’s HLSL (High Level Shader Language) is a simple language used to write shaders. Used with DirectX to provide high-end graphics Slightly comparable to a high-level C++

What is a Shader? A shader is a program (code file) that is executed on the GPU (Graphics Processing Unit; ‘graphics card’) to manipulate the data before it is drawn to the screen. Can be written in numerous shader-specific languages: HLSL (DirectX), GLSL (OpenGL), Cg (nVidia), Assembly Math-Heavy (Algorithms)

Vertex Shaders Shader run on per-vertex level Examples: Color Texture Position Do not change the data type

Pixel Shaders (Fragment Shader) Run per-pixel Examples: Lighting Values Output certain color Cannot produce complex effects due to per-pixel implementation

Geometry Shaders Manipulate graphics primitives to create new primitives (points, lines, triangles) Examples: Shadow Volumes Cube Map (Skybox) Newest Shader type, only works in DirectX 10 OpenGL Extension

Shader Examples Almost all recent video games use shaders All animated CGI movies use shaders (Pixar) Some techniques commonly used: Parallax-Mapping (Bump-Mapping) Phong Shading Cell-shading Bloom High Dynamic Range Lighting (HDR)

Parallax-Mapping

Phong Shading

Ray Tracing (Pre-Rendered)

Cell-Shading (Windwaker)

Bloom (Tron)

High Dymanic Range Lighting (FarCry)

Combination (Gears of War)

Combination (Ratatouille)

HLSL/Shader History Four Generations of GPUs Fixed-Function Pipeline Released with DirectX 7 (~2000) Transformation and Lighting (T&L) hardware Pixar RenderMan shading language Way to bypass built-in lighting Problem with render times Programmable Pipeline Introduction of programmer defined code (shaders) First consumer-level programmable GPU Began with DirectX 8 (~2001)

How Does It Work? Graphics Pipeline

HLSL Code Segments Variables Stream Structures Float4x4 (4x4 Matrix), float4 (4 row vector-matrix), float float4 ambientColor = {1.0f, 1.0f, 1.0f, 1.0f}; //Color of Ambient Light float ambientbrightness = 1.0f; //Brightness of Ambient Light Stream Structures //App to Vertex Shader struct ambientA2V { float4 Pos: POSITION; float2 TexCoord: TEXCOORD0; };

HLSL Code Segments (cont’d) Semantics String describing the type of data being passed between shader stages COLOR (Diffuse and specular color), NORMAL (Normal vector), TEXCOORD (texture coordinates) Like variable type, gives shader ‘heads up’ ‘Use this as the normal vector!’ Functions Similar to regular C/C++ functions but can specify return semantic float4 ambientPS(in ambientV2P IN) : COLOR { //Get texture float4 Color = tex2D(TextureSampler, IN.TexCoord); //Return texture * color * ambientbrightness return Color * (ambientColor * ambientbrightness); }

HLSL Code Segments (cont’d) Techniques Considered ‘classes’ called by the render engine Typically contain and run vertex, pixel, and geometry shaders using different ‘passes’ (Passes considered ‘class functions’) Different techniques can be used for different hardware configurations to support old/new hardware Intrinsic Functions Built-in, commonly used (usually math-related) functions; often similar to assembly Mul(x, y) (multiplies x * y) Abs(x) (absolute value of x)

Implementing a Simple Shader Example Setup: Shader: Ambient Light with Point Light Technique PointLight 2 passes Engine: C++ and DirectX 9.0c

Shader Overview 2 lighting algorithms Pass P0 Pass P1 Code Ambient Light Point Light Pass P0 Create Point Light Pass P1 Create Ambient Light Code

Engine Implementation Code

Post Processing Render to a target (texture) Manipulate Texture Display Texture as Render Examples Motion Blur Bloom Image Perturbation (Heat waves)

Conclusion Shaders provide current/next – gen graphics by fully utilizing the GPU using code algorithms Vertex Shader Pixel Shader Geometry Shader Relatively new, still developing Questions?

Web Links HLSL MSDN DirectX SDK Cg Book My Site http://msdn.microsoft.com/en-us/library/bb509561(VS.85).aspx DirectX SDK http://msdn.microsoft.com/en-us/directx/aa937788.aspx Cg Book http://developer.nvidia.com/object/cg_tutorial_home.html My Site http://www.insidegamer.org/Projects.aspx http://www.geekswithblogs.net/CodeBlog

Extras How does a shadow volume work? Create rays pointing from geometry to infinity Everything within this larger geometric shape is encased in shadow, everything outside is lit Determine faces aiming towards/away from lighting ‘Fringe’ creates silhouette Cast rays from silhouette vertices away from light to infinity to generate shadow volume Optional: Place caps to optimize

Shadow Volume (Doom 3)

Extras (Cont’d) How does bump mapping work? Create a heightmap texture Apply to a model prior to lighting (same as applying any texture to the model) Use trig to determine the surface normal per pixel Any lighting algorithm will calculate the new shadows based on surface normals