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.

Slides:



Advertisements
Similar presentations
Accelerating Real-Time Shading with Reverse Reprojection Caching Diego Nehab 1 Pedro V. Sander 2 Jason Lawrence 3 Natalya Tatarchuk 4 John R. Isidoro 4.
Advertisements

Exploration of advanced lighting and shading techniques
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 1/16 Deferred Lighting Deferred Lighting – 11/18/2014.
COMPUTER GRAPHICS CS 482 – FALL 2014 NOVEMBER 10, 2014 GRAPHICS HARDWARE GRAPHICS PROCESSING UNITS PARALLELISM.
Using effects within a SpriteBatch or as a post render effect
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.
Damon Rocco.  Tessellation: The filling of a plane with polygons such that there is no overlap or gap.  In computer graphics objects are rendered as.
Rasterization and Ray Tracing in Real-Time Applications (Games) Andrew Graff.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics April 19, 2007.
Introduction to Shader Programming
Z-Buffer Optimizations Patrick Cozzi Analytical Graphics, Inc.
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.
Computer Graphics Introducing DirectX
1 KIPA Game Engine Seminars Jonathan Blow Seoul, Korea November 29, 2002 Day 4.
CHAPTER 4 Images XNA Game Studio 4.0. Objectives Find out how the Content Manager lets you add pictures to Microsoft XNA games. Discover how pictures.
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.
Real-time Graphical Shader Programming with Cg (HLSL)
Geometric Objects and Transformations. Coordinate systems rial.html.
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.
Introduction to XNA Graphics Programming Asst. Prof. Rujchai Ung-arunyawee COE, KKU.
به نام خدا تنظیم کننده : فرانه حدادی استاد : مهندس زمانیان تابستان 92.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
11 Making a Sprite Session 4.2. Session Overview  Describe the principle of a game sprite, and see how to create a sprite in an XNA game  Learn more.
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.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Havok FX Physics on NVIDIA GPUs. Copyright © NVIDIA Corporation 2004 What is Effects Physics? Physics-based effects on a massive scale 10,000s of objects.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
Maths & Technologies for Games Graphics Optimisation - Batching CO3303 Week 5.
COMPUTER GRAPHICS CS 482 – FALL 2015 SEPTEMBER 29, 2015 RENDERING RASTERIZATION RAY CASTING PROGRAMMABLE SHADERS.
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.
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 write a Pixel Shader CMT3311. Aim The aim of these slides is to introduce you to enough HLSL that you get a general understanding of pixel shaders.
Our Graphics Environment Landscape Rendering. Hardware  CPU  Modern CPUs are multicore processors  User programs can run at the same time as other.
Lecture Rendering pipeline, shaders and effects 1Elias Holmlid.
Computer Graphics Graphics Hardware
COMPUTER GRAPHICS CHAPTER 38 CS 482 – Fall 2017 GRAPHICS HARDWARE
Ying Zhu Georgia State University
Week 3 - Monday CS361.
Week 7 - Wednesday CS361.
Control Unit Lecture 6.
Programmable Pipelines
Computer Graphics Index Buffers
Graphics Processing Unit
Deferred Lighting.
Introduction to OpenGL
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Static Image Filtering on Commodity Graphics Processors
Graphics Processing Unit
Computer Graphics Graphics Hardware
CS5500 Computer Graphics April 17, 2006 CS5500 Computer Graphics
The Challenge of Cross - Language Interoperability
Computer Graphics Practical Lesson 10
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
Introduction to OpenGL
Computer Graphics Introducing DirectX
Presentation transcript:

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 get a general idea about shaders because examples you come across will use them These slides introduce you to how to use a pixel shader

Programming the Graphics Processing Unit (GPU) Massive increase in graphics performance in recent years Comes from increasing capabilities of graphics hardware And the ability to write programs that run on the GPU Baseline of XNA for 3D is that you have to use either a built in effect or write your own pixel and vertex shaders – little programs that run on the GPU written in the language HLSL

High Level Shading Language HLSL Is a C-like little language for writing pixel and vertex shaders (though you can write in assembly language instead) A pixel shader is applied to each pixel A vertex shader is applied to each vertex In directx 10 we also have geometry shaders that can even do some physics on the GPU – but we are stuck at direct 9c with the xbox360 For 2D graphics we can use pixel shaders to apply effects to our graphics e.g. blurring or making the image wavy.

Pixel shaders Because pixel shaders are virtually always used in conjunction with vertex shaders it is hard to find information just about pixel shaders But you can find lots of example shaders out there e.g. from Nvidia erlibrary/webpages/shader_library.html

In this example I got post_sepia.fx from the NVidia site and commented out the vertex shader part – probably this will not work with most examples

Pixel shaders Often referred to as post processing i.e. you generate the image first and then apply some effect to it You can modify every single pixel of an image The general way we will do this is –Draw to a texture in memory rather than to the screen –Then draw the texture to the screen modifying it in some way through a pixel shader program Actually we have a lot of steps to implement this simple concept first we will consider how to use and effect (shader) file in XNA

Shader terminology In HLSL a shader file is referred to as an effect An effect can have a number of techniques in it – these are different functions to support different graphics card capabilities A technique can have a number of passes. Usually there is only one pass but the output of one pass may be fed into or combined with the next pass. –e.g. pass 1 might blur the image, pass 2 could convert it to greyscale while a third pass could do an edge detection

Effects

XNA code to use an effect You need to add the effect file to your project – the content pipeline automatically compiles it for you In XNA you have to define an Effect and an EffectPass You need to load the effect file Then in draw –you begin the effect –You assign the EffectPass to the pass you want –You begin the pass –You draw your graphics –You then end the pass and end the effect

define an Effect and an EffectPass as class variables Load the effect file in LoadGraphicsContent()

Begin, draw and end. As this is 2D a spriteBatch is used for drawing

XNA code to draw to a texture and then draw to screen through a shader program You have to define a 2d render target You have to initialise it You draw to it You send it to the back buffer You clear it You use a spriteBatch to draw it You do the steps described previously for the effect to ensure that it is processed by your effect (shader program)

Define and initialise a renderTarget

Draw function becomes:

Use a pixel shader You are now ready to use any pixel shader that does not need to have variables passed to it In the next slides some pixel shaders are developed