Introduction to Nikola Mihaylov, Sep 1, 2008.

Slides:



Advertisements
Similar presentations
Real-Time Rendering 靜宜大學資工研究所 蔡奇偉副教授 2010©.
Advertisements

Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Bump Mapping CSE 781 Roger Crawfis.
ADVANCED SKIN SHADING WITH FACEWORKS Nathan Reed — NVIDIA March 24, 2014.
3D Graphics Rendering and Terrain Modeling
Real-Time Rendering TEXTURING Lecture 02 Marina Gavrilova.
 David Teitlebaum Program Manager Microsoft Corporation PC07.
The Programmable Graphics Hardware Pipeline Doug James Asst. Professor CS & Robotics.
Introduction to Geometry Shaders Patrick Cozzi Analytical Graphics, Inc.
Video Object Tracking and Replacement for Post TV Production LYU0303 Final Year Project Spring 2004.
Introduction to Shader Programming
Point Lighting Using Shaders Game Design Experience Professor Jim Whitehead March 13, 2009 Creative Commons Attribution 3.0 (Except copyrighted images.
A Crash Course on Programmable Graphics Hardware Li-Yi Wei 2005 at Tsinghua University, Beijing.
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.
Computer Science – Game DesignUC Santa Cruz Adapted from Jim Whitehead’s slides Shaders Feb 18, 2011 Creative Commons Attribution 3.0 (Except copyrighted.
Image Processing.  a typical image is simply a 2D array of color or gray values  i.e., a texture  image processing takes as input an image and outputs.
Procedural terrain on the GPU Chalmers University of Technology Advanced computer graphics – DAT205 David Sundelius Adam Scott.
Queensland University of Technology CRICOS No J INB382/INN382 Real-Time Rendering Techniques Lecture 13: Revision Ross Brown.
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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)
Noise and Procedural Techniques John Spitzer Simon Green NVIDIA Corporation.
Havok. ©Copyright 2006 Havok.com (or its licensors). All Rights Reserved. HavokFX Next Gen Physics on ATI GPUs Andrew Bowell – Senior Engineer Peter Kipfer.
Geometric Objects and Transformations. Coordinate systems rial.html.
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.
A Crash Course in HLSL Matt Christian.
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.
Computer Graphics Module Review CO2409 Computer Graphics.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GRAPHICS PIPELINE & SHADERS SET09115 Intro to Graphics Programming.
GPGPU Tools and Source Code Mark HarrisNVIDIA Developer Technology.
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.
Vector Graphics Multimedia Technology. Object Orientated Data Types Created on a computer not by sampling real world information Details are stored on.
Accelerated Stereoscopic Rendering using GPU François de Sorbier - Université Paris-Est France February 2008 WSCG'2008.
M. Jędrzejewski, K.Marasek, Warsaw ICCVG, Multimedia Chair Computation of room acoustics using programable video hardware Marcin Jędrzejewski.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Computer Graphics 3 Lecture 6: Other Hardware-Based Extensions Benjamin Mora 1 University of Wales Swansea Dr. Benjamin Mora.
11/5/2002 (c) University of Wisconsin, CS 559 Last Time Local Shading –Diffuse term –Specular term –All together –OpenGL brief overview.
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.
Advanced D3D10 Shader Authoring Presentation/Presenter Title Slide.
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.
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.
Lecture Rendering pipeline, shaders and effects 1Elias Holmlid.
Ying Zhu Georgia State University
Programmable Shaders Dr. Scott Schaefer.
A Crash Course on Programmable Graphics Hardware
The Graphics Rendering Pipeline
CS451Real-time Rendering Pipeline
Introduction to VRML for generating 3-D display
Introduction to Computer Graphics with WebGL
Computer Graphics Module Review
HW for Computer Graphics
Computer Graphics Module Overview
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
CS 480/680 Computer Graphics GLSL Overview.
Presentation transcript:

Introduction to Nikola Mihaylov, Sep 1,

What is Pixel Shader? a) A fantasy creature: male pixie that likes shades b) Person who likes to cast shadow on computer screens c) Any of the above d) All of the above except this answer e) Not this answer

Pixel Shader Is:  A set of software instructions  Used to calculate colors of individual pixels on screen  Typically executing on the graphics card (Graphics Processing Unit or GPU)  Executed very fast on the GPU  Primarily used to compute rendering effects  Written in shader language, e.g. HLSL – similar to C  Can be used for any computation

Demo: Grayscale Effect  Shader Inputs: Bitmap to be processed (u,v) location of pixel to be processed ○ (u,v) is used instead of (x,y) to mean that the range of values is from 0 to 1 ○ (u,v) is called “texture coordinates” float DesaturationFactor: specifies how much the bitmap is to be saturated  Shader Output: pixel color at specified location

Grayscale Effect Pixel Shader: grayscale.fx sampler2D implicitInput : register(s0); float factor : register(c0); float4 main(float2 uv : TEXCOORD) : COLOR { float4 color = tex2D(implicitInput, uv); float gray = color.r * color.g * color.b *0.11; float4 result; result.r = (color.r - gray) * factor + gray; result.g = (color.g - gray) * factor + gray; result.b = (color.b - gray) * factor + gray; result.a = color.a; return result; } Input bitmap – sampler register s0 Code-behind: ShaderEffect.RegisterPixelShaderSamplerProperty() Input bitmap – sampler register s0 Code-behind: ShaderEffect.RegisterPixelShaderSamplerProperty() Input float in c0 register. Code-behind: PixelShaderConstantCallback(0) Output: R, G, B, A: float4 Color of the pixel at (u,v) Output: R, G, B, A: float4 Color of the pixel at (u,v) Input: (u,v) coordinates of pixel in the bitmap Retrieve pixel color at location (u,v) from bitmap Grayscale code Shader code from

Using Shaders in WPF: Overview 1. Install DirectX SDK 2. Create new WPF app and add.fx file containing the shader code 3. Compile.fx file to.ps file. Set the Build Action of the.ps file to Resource Add this as pre-build event to VS in Project properties: “c:\Program Files\Microsoft DirectX SDK (June 2008)\Utilities\bin\x86\fxc" /T ps_2_0 /E main /Fo "$(ProjectDir)MyEffect.ps" "$(ProjectDir)MyEffect.fx“ 4. Override ShaderEffect class 5. Link WPF properties to shader input arguments in code-behind 6. Apply shader effect in XAML

Using Shaders in WPF: The Easy Way  Install DirectX SDK  Download and open the Shader template project from Nikola’s site:  Start coding your effect in MyEffect.fx Next: connecting WPF and the GPU in C#

GrayscaleEffect Initialization public class GrayscaleEffect : ShaderEffect { private static PixelShader _pixelShader = new PixelShader() { UriSource = new caleEffect.ps") }; public GrayscaleEffect() { PixelShader = _pixelShader; UpdateShaderValue(InputProperty); UpdateShaderValue(DesaturationFactorProperty); } public class GrayscaleEffect : ShaderEffect { private static PixelShader _pixelShader = new PixelShader() { UriSource = new caleEffect.ps") }; public GrayscaleEffect() { PixelShader = _pixelShader; UpdateShaderValue(InputProperty); UpdateShaderValue(DesaturationFactorProperty); } Call UpdateShaderValue() to set the default value of the WPF property into the shader registers, since PropertyChangedCallback() is not called when setting default value.

Register Bitmap Texture Input Property public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("In put", typeof(GrayscaleEffect), 0); public Brush Input { get { return (Brush)GetValue(InputProperty); } set { SetValue(InputProperty, value); } } public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("In put", typeof(GrayscaleEffect), 0); public Brush Input { get { return (Brush)GetValue(InputProperty); } set { SetValue(InputProperty, value); } } Register the bitmap input property in register s0..fx code: sampler2D implicitInput : register(s0); <- s0

Register Other Shader Input Properties public static readonly DependencyProperty DesaturationFactorProperty = DependencyProperty.Register("DesaturationFactor", typeof(double), typeof(GrayscaleEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0), CoerceDesaturationFactor)); public double DesaturationFactor { get { return (double)GetValue(DesaturationFactorProperty); } set { SetValue(DesaturationFactorProperty, value); } } public static readonly DependencyProperty DesaturationFactorProperty = DependencyProperty.Register("DesaturationFactor", typeof(double), typeof(GrayscaleEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0), CoerceDesaturationFactor)); public double DesaturationFactor { get { return (double)GetValue(DesaturationFactorProperty); } set { SetValue(DesaturationFactorProperty, value); } } Just another WPF DependencyProperty Link to c0 register.fx code: float factor : register(c0);

Use in XAML! <effect:GrayscaleEffect x:Name="grayscaleEffect“ DesaturationFactor="0.7"/>  Supports Bindings, Animation and everything that typical WPF property supports!

More Shaders  They can scale, twist, rotate, ripple or do anything with the image Full access to texture Customizable inputs  Can be used for realistic effects Light, Shadows Water, Fire, Rain Human faces Clouds, Terrains Projectile traces Light auras, Magic spell effects Candles and smoke Physics Many, many more MANY more

Demo: Water Reflection sampler2D input : register(s0); float val0 : register(c0); float4 main(float2 uv : TEXCOORD) : COLOR { float4 color; uv.y = uv.y + sin((uv.y-val0) * 100) * 0.03 * (1-uv.y); color = tex2D(input, uv.xy); return color; } Shader code from:

More Demos: Twirled UI, Lights and Novas  Twirl: offsets image a little bit based on cos() and sin(uv+inputValue)  Lights: same as RadialGradientBrush, only quadratic – light gets weaker with distance squared  Novas: zoom motion blur effect. Mixes colors of 2 points on the same radius but different distance from center of image.

Other Shaders  Geometry shader Can generate new primitives (geometry), for example: lines, points, triangles DirectX 10 and above  Vertex shader Modifies attributes of existing 3D vertices ○ Color ○ Texture ○ Location ○ Other

Resources  DirectX SDK on  Writing Shaders on MSDN Writing Shaders on MSDN  Pixel shader template project Pixel shader template project  NVidia Object FX Composer NVidia Object FX Composer  Grayscale Shader Effect on Anders Bursjöö’s blog Grayscale Shader Effect  Facewound.com post processing shader tutorial – short samples with preview Facewound.com post processing shader tutorial  Wave Reflection Effect on Rakesh Ravuri’s blog Wave Reflection Effect  Pixel shader Twirl UI, Lights and Blobs sampleTwirl UI, Lights and Blobs sample  Nikola’s blog: and website:

End