Computer Graphics Practical Lesson 10

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

The Programmable Graphics Hardware Pipeline Doug James Asst. Professor CS & Robotics.
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.
Cg: C for Graphics Jon Moon Based on slides by Eugene Lee.
The programmable pipeline Lecture 10 Slide Courtesy to Dr. Suresh Venkatasubramanian.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Vertex & Pixel Shaders CPS124 – Computer Graphics Ferdinand Schober.
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.
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
Antigone Engine Kevin Kassing – Period
REAL-TIME VOLUME GRAPHICS Christof Rezk Salama Computer Graphics and Multimedia Group, University of Siegen, Germany Eurographics 2006 Real-Time Volume.
GPU Programming Robert Hero Quick Overview (The Old Way) Graphics cards process Triangles Graphics cards process Triangles Quads.
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.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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...
OpenGL Shader Language Vertex and Fragment Shading Programs.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
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.
OpenGL Shading Language
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS The GPU.
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.
GLSL Review Monday, Nov OpenGL pipeline Command Stream Vertex Processing Geometry processing Rasterization Fragment processing Fragment Ops/Blending.
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.
Ying Zhu Georgia State University
Week 3 - Monday CS361.
Programmable Pipelines
A Crash Course on Programmable Graphics Hardware
Graphics Processing Unit
Deferred Lighting.
Chapter 6 GPU, Shaders, and Shading Languages
CS451Real-time Rendering Pipeline
Lecture 18 and 19 GPU and Programmable Shaders
Real-time Computer Graphics Overview
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
Day 05 Shader Basics.
UMBC Graphics for Games
Chapter VI OpenGL ES and Shader
Graphics Processing Unit
Introduction to Shaders
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
© 2012 Elsevier, Inc. All rights reserved.
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
03 | Creating, Texturing and Moving Objects
CS 480/680 Computer Graphics GLSL Overview.
OpenGL Background CS 4722.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Computer Graphics Practical Lesson 10 Shaders and CG

What is shader? Shaders are programs that allow program the GPU pipeline and enable flexibility in the graphic pipeline. They can be programmed using language OpenGL Shading Language, or GLSL. We will focus on language of NVIDIA – CG Please download and install NVIDIA CG TOOLKIT ver 2.0 or above.

Shaders Types Vertex Shaders – process vertices, position, texture but not creating vertices. The output goes to the next stage in the pipeline. Geometry Shaders – add or remove vertices from the mesh. Add volume to existing meshes. Pixel Shaders (a.k.a. fragment shader ) – process pixels, lighting and related effects.

CG Each shader code is written in separate file with extension CG. It is compiled during runtime. Each shaper runs on different part of the pipeline, which enables high degree of flexibility. With this technology, programmers started performing computations on the GPU , which is the base for CUDA.

CG Objects CG contains special objects to work with this external code: CGprogram – contains runtime code of a shader. CGprofile – detect hardware profile, allow detecting which commands are valid. CGparameter – parameter for shader.

Loading Shader Program To load shader program we call cgCreateProgramFromFile To prepare it for running: cgGLLoadProgram Now we need to init its parameters using cgGetNamedParameter To use shader we call the function:

Using shaders To enable usage of shaders: cgGLEnableProfile(profile); CGprofile profile = cgGLGetLatestProfile(CG_GL_VERTEX); cgGLEnableProfile(profile); CGprofile profile = cgGLGetLatestProfile(CG_GL_FRAGMENT); To run shder itself: cgGLBindProgram

CG special types In addition to standard types of C – float and int, there are special types in CG to store color, normal and other graphic structs: float3 – store normal and position. float4 – store position ( we need 4 values to be able to multiple matrix with them ). float4x4 – to store matrices like model matrix and ect’

CG special types(cont’) The fields of structs can be accessed by x,y,z,w Alternatively – r,g,b,a We can copy several fields of source field: float4(0.0f,iColor.gba);

Shaders input and output We define 2 structs for shaders, in vertices shader VertIn for input and VertOut for output. struct VertIn{ float4 iPosition : POSITION; float3 iNormal : NORMAL; float4 iColor : COLOR0; { The label after the ‘:’ mark define data source.

Shader main function This function is called for every vertex that reaches vertex shader, and every pixel on fragment shader. Input struct contains information of specific object that current instance run on. It always returns instance of output struct. The output of a shader in an early stage of the pipeline is the input of the shader of a later stage.

Passing parameters Some parameters are created automatically, from input arrays received by vertex arrays: POSITION, NORMAL We can define parameters of ourselves using commands: cgGLSetParameter4f cgGLSetStateMatrixParameter