Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.

Slides:



Advertisements
Similar presentations
Programming with OpenGL - Getting started - Hanyang University Han Jae-Hyek.
Advertisements

GPGPU Programming Dominik G ö ddeke. 2Overview Choices in GPGPU programming Illustrated CPU vs. GPU step by step example GPU kernels in detail.
Perspective aperture ygyg yryr n zgzg y s = y g (n/z g ) ysys y s = y r (n/z r ) zrzr.
GLSL Basics Discussion Lecture for CS 418 Spring 2015 TA: Zhicheng Yan, Sushma S Kini, Mary Pietrowicz.
A HLSL Primer for Developers By Wolfgang F. Engel June 13th, 2003.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
Informationsteknologi Wednesday, December 12, 2007Computer Graphics - Class 171 Today’s class OpenGL Shading Language.
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.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
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.
Cg Kevin Bjorke GDC NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level,
OOP Languages: Java vs C++
GAM532 DPS932 – Week 1 Rendering Pipeline and Shaders.
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.
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.
OpenGL Shading Language (Advanced Computer Graphics) Ernest Tatum.
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.
A Crash Course in HLSL Matt Christian.
The Graphics Rendering Pipeline 3D SCENE Collection of 3D primitives IMAGE Array of pixels Primitives: Basic geometric structures (points, lines, triangles,
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
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.
CSE 690: GPGPU Lecture 6: Cg Tutorial Klaus Mueller Computer Science, Stony Brook University.
NVIDIA CONFIDENTIAL Hardware Shading for Artists.
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.
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.
David Luebke 1 11/24/2015 Programmable Graphics Hardware.
CS418 Computer Graphics John C. Hart
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
1 Advanced Topics in Functions Lecture Unitary Scope Resolution Operator Unary scope resolution operator ( :: )  Access global variable if.
OpenGL Shading Language
Advanced D3D10 Shader Authoring Presentation/Presenter Title Slide.
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Programmable Shaders Dr. Scott Schaefer.
Programmable Pipelines
OpenGL and Related Libraries
Chapter 6 GPU, Shaders, and Shading Languages
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
UMBC Graphics for Games
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
The C Language: Intro.
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
Language Definitions Chap. 3 of Orange Book.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Cg – C for Graphics Eric Vidal CS 280

History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics card processing – DirectX 8/9 vertex shaders and pixel shaders (2000, 2002) – OpenGL ARB_vertex_program/ARB_fragment_program (2002) High-level languages for graphics card processing – DirectX High Level Shading Language (HLSL) (2002) – OpenGL Shading Language (glslang) (2003) – Cg – C for Graphics (2002)

History Cg – C for Graphics – Developed in 2002 by NVIDIA Corporation in close collaboration with Microsoft – Supports OpenGL and DirectX (does not replace them) – Supported in Windows, Mac OS X and Linux – Proprietary (but language specification is open) – Cg compiler technology is open-source

Rationale Do graphics-related processing (“shading”) in graphics card – Offloads work from the main processor – Higher performance Cg is a high-level language – Easier to understand than graphics card “assembly language” (DirectX vertex/pixel shaders, OpenGL vertex/fragment programs) – Code portability across graphics cards

Features Two types of Cg programs: – Vertex programs – Fragment programs On-the-fly compilation supports several target graphics assembly language formats: – DirectX 8 vertex/pixel shaders (vs_1_1, ps_1_3) – DirectX 9 vertex/pixel shaders (vs_2_0, ps_2_x) – OpenGL vertex/fragment program extensions (arbvp1, arbfp1) – NVIDIA proprietary OpenGL extensions (vp20, fp20, vp30, fp30)

Features First class support for vector data types – float4 – vector of four floats – float4x4 – square matrix with 16 elements Same operators as C – Works with vectors as well as with scalars float scalar = 4.0; float4 vector = float4(1.0, 2.0, -1.0, 3.0), result; /* this properly scales “vector” by “scalar” */ result = scalar * vector;

Features uniform parameters input semantics (for non-uniform parameters) out, inout parameters void simpleTransform(float4 objectPosition : POSITION, float4 color : COLOR, float4 decalCoord : TEXCOORD0, float4 lightMapCoord : TEXCOORD1, out float4 clipPosition : POSITION, out float4 oColor : COLOR, out float4 oDecalCoord : TEXCOORD0, out float4 oLightMapCoord : TEXCOORD1, uniform float brightness, uniform float4x4 modelViewProjection)

Features Structures and arrays (including multidimensional arrays) All of C’s arithmetic operators boolean type Boolean/relational operators ( ||, &&, !, etc.) Increment/decrement operators ( ++, -- ) Conditional expressions ( ?, : ) Assignment expressions ( =, +=, etc.)

Features User-defined functions – But no recursive functions! Control flow constructs – do, while, for, if, break, continue – No switch and goto ! Data types – float, half, double – int – fixed

Features #include, #define, #ifdef C and C++-style comments Swizzling and write-masking float4 vec1 = float4(1.0, 2.0, 3.0, 4.0); float2 vec2 = vec1.yx; // vec2 = (2.0, 1.0); float scalar = vec1.w; // scalar = 4.0; float3 vec3 = scalar.xxx; // vec3 = (4.0, 4.0, 4.0); vec1.xw = vec3; // vec1 = (4.0, 2.0, 3.0, 4.0); discard keyword (similar to return, but no return value)

Features Built-in library functions for graphics math – abs() – log2() – mul() – dot() – normalize() – lerp() – specular() – reflect() –... and more! (No need to #include )

(Non-)Features Pointers Bitwise operations Unions Function variables String processing File I/O Memory allocation/deallocation C++ classes, templates, overloading, exceptions

Sample Programs

Applications Using Cg Unreal engine (Epic Games, Inc.) Aurora engine (Bioware Inc.) Storm engine (Blizzard Entertainment) Other game companies (Electronic Arts, Ensemble Studios, Ion Storm, LithTech, Maxis, Microsoft Games) Third party content creation tools – Alias Wavefront Maya 4.5 – Discreet 3ds max 5 – SOFTIMAGE|XSI v.3.0

Where to Get Cg Main Cg Website: – Cg Language Specification: – Cg Compiler and Toolkit: –