Cg Kevin Bjorke GDC 2003. NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level,

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
Advertisements

9/25/2001CS 638, Fall 2001 Today Shadow Volume Algorithms Vertex and Pixel Shaders.
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.
ATI GPUs and Graphics APIs Mark Segal. ATI Hardware X1K series 8 SIMD vertex engines, 16 SIMD fragment (pixel) engines 3-component vector + scalar ALUs.
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.
Status – Week 260 Victor Moya. Summary shSim. shSim. GPU design. GPU design. Future Work. Future Work. Rumors and News. Rumors and News. Imagine. Imagine.
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.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Cg – C for Graphics Eric Vidal CS 280. History General graphics processing languages – Renderman shading language (1988) Assembly languages for graphics.
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.
Enhancing GPU for Scientific Computing Some thoughts.
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.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진
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.
Overview [See Video file] Architecture Overview.
A Crash Course in HLSL Matt Christian.
Shading CMSC 435/634. RenderMan Light Displacement Surface Volume Imager.
Real-Time Shading Using Programmable Graphics Hardware Introduction, Setup and Examples Wan-Chun Ma National Taiwan University.
Shading CMSC 435/634.
The programmable pipeline Lecture 3.
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.
The GPU Revolution: Programmable Graphics Hardware David Luebke University of Virginia.
NVIDIA CONFIDENTIAL Hardware Shading for Artists.
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...
David Luebke 1 11/24/2015 Programmable Graphics Hardware.
OpenCL Programming James Perry EPCC The University of Edinburgh.
A User-Programmable Vertex Engine Erik Lindholm Mark Kilgard Henry Moreton NVIDIA Corporation Presented by Han-Wei Shen.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
Week 3 Lecture 4: Part 2: GLSL I Based on Interactive Computer Graphics (Angel) - Chapter 9.
David Luebke 1 1/25/2016 Programmable Graphics Hardware.
Ray Tracing using Programmable Graphics Hardware
OpenGL Shading Language
Antigone Engine. Introduction Antigone = “Counter Generation” Library of functions for simplifying 3D application development Written in C for speed (compatible.
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.
CgFX Sébastien Dominé, NVIDIA. Overview What is CgFX? CgFX runtime Production pipeline with CgFX CgFX Tools set Demo.
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.
Antigone Engine.
Programmable Pipelines
Introduction to OpenGL
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.
UMBC Graphics for Games
Introduction to Programmable Hardware
Where does the Vertex Engine fit?
Computer Graphics Practical Lesson 10
Programming with OpenGL Part 3: Shaders
Computer Graphics Introduction to Shaders
Introduction to OpenGL
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 Kevin Bjorke GDC 2003

NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level, Graphics “Assembly Code”

NVIDIA CONFIDENTIAL Cg is a C-like language, modified for GPUs Syntax, operators, functions from C Conditionals and flow control Particularly suitable for GPUs: Expresses data flow of the pipeline/stream architecture of GPUs (e.g. vertex-to-pixel) Vector and matrix operations Supports hardware data types for maximum performance Exposes GPU functions for convenience and speed: Intrinsic: (mul, dot, sqrt…) Built-in: extremely useful and GPU optimized math, utility and geometric functions (noise, mix, reflect, sin…) Language reserves keywords to support future hardware implementations (e.g. switch, case…) Compiler uses hardware profiles to subset Cg as required for particular hardware feature sets

NVIDIA CONFIDENTIAL NVIDIA Cg Usage Three ways: Cg Runtime – a thin API: ASCII.Cg shader compiled at runtime Convenient interface for setting shader parameters and constants Command line compiler generates text file output: DX / OpenGL – vertex and pixel shader files Tweak the ASM yourself Generates comments on program params & registers CgFX Effect framework with render states

NVIDIA CONFIDENTIAL Integrating Cg Options (not mutually exclusive): CgFX Manages whole rendering process Handles render states – cross API support Convenient exposure of tweakables & artist controls Cg Shaders semantics (was #pragma bind) directives to match your C++ and other custom hardware shaders Bind textures/parameters to specific HW registers Cg Runtime Thin API to compile on demand at runtime Optimizes & munges.Cg for range of target HW

NVIDIA CONFIDENTIAL Flexible Adoption Path Can use system for just fragment programs Define a connector to specify how you’ll supply data to these programs Can use system for just vertex programs Define connectors to specify how you’ll supply data to these programs; and what they have to output. Can use system with older OpenGL applications Classical glVertex(), glNormal() can still be used Use OpenGL matrix tracking to provide modelview matrix to shading program. But, must load program & supply light state

NVIDIA CONFIDENTIAL Mix and Match Any Method Vertex processing Fixed function -or- Hand-written ASM -or- Compiled Cg -or- Hand-optimized Cg ASM Fragment processing Fixed function -or- Hand-written ASM -or- Compiled Cg -or- Hand-optimized Cg ASM

NVIDIA CONFIDENTIAL Using the Cg Compiler // // Diffuse lighting // float d = dot(normalize(frag.N), normalize(frag.L)); if (d < 0) d = 0; c = d*f4tex2D(t, frag.uv)*diffuse; … DP3 r0.x, f[TEX0], f[TEX0]; RSQ r0.x, r0.x; MUL r0, r0.x, f[TEX0]; DP3 r1.x, f[TEX1], f[TEX1]; RSQ r1.x, r1.x; MUL r1, r1.x, f[TEX1]; DP3 r0, r0, r1; MAX r0.x, r0.x, 1.0; MUL r0, r0.x, DIFFUSE; TEX r1, f[TEX1], 0, 2D; MUL r0, r0, r1; … Cg program source code Shader program assembly code Application DevelopmentYour Application 1)Load/bind program 2)Specify program parameters 3)Specify vertex inputs 4)Render Cg Compiler Shader Compiler (nvasm.exe, psa.exe) Shader Binary

NVIDIA CONFIDENTIAL Using the Cg Runtime // // Diffuse lighting // float d = dot(normalize(frag.N), normalize(frag.L)); if (d < 0) d = 0; c = d*f4tex2D(t, frag.uv)*diffuse; … Cg program source code Application DevelopmentYour Application 3)Specify vertex inputs 4)Render Cg Runtime 1)Load/bind program 2)Specify parameters

NVIDIA CONFIDENTIAL Details And now for the details...

NVIDIA CONFIDENTIAL Graphics Data Flow Application Vertex Program Fragment Program Framebuffer Connector Cg Program // // Diffuse lighting // float d = dot (normalize(frag.N), normalize(frag.L)); if (d < 0) d = 0; c = d * f4tex2D( t, frag.uv ) * diffuse; …

NVIDIA CONFIDENTIAL Data types float= 32-bit IEEE floating point half= 16-bit IEEE-like floating point fixed= 12-bit fixed [-2,2) clamping (OpenGL only) bool= Boolean sampler*= Handle to a texture sampler

NVIDIA CONFIDENTIAL Array / vector / matrix declarations Declare vectors (up to length 4) and matrices (up to size 4x4) using built-in data types: float4 mycolor; float3x3 mymatrix; Declare more general arrays exactly as in C: float lightpower[4]; But, arrays are first-class types, not pointers Implementations may subset array capabilities to match HW restrictions

NVIDIA CONFIDENTIAL Extend standard arithmetic to vectors and matrices Component-wise + - * / for vectors Dot product dot(v1,v2); // returns a scalar Matrix multiplications: assuming float4x4 M and float4 v matrix-vector: mul(M, v); // returns a vector vector-matrix: mul(v, M); // returns a vector matrix-matrix: mul(M, N); // returns a matrix

NVIDIA CONFIDENTIAL New vector operators Swizzle operator extracts elements from vector a = b.xxyy; Vector constructor builds vector a = float4(1.0, 0.0, 0.0, 1.0);

NVIDIA CONFIDENTIAL “Profiles” Define Specific HW Behavior Public NVIDIA Cg Compiler has three NV2X profiles: DX8 Vertex Shader (vs1.1) DX8 Pixel Shader (ps1.1) OpenGL Vertex Program (currently based on NV_vertex_program, will move to ARB_vertex_program) Newest NVIDIA Cg Compiler currently has two NV30 profiles: Vertex program (vp2.0) Fragment Program (vp1.0) DX9 vertex/pixel shader profile support forthcoming Vertex profiles: No “half” or “fixed” data type No texture functions – It’s a vertex program! Fragment/pixel profiles: No “for” or “while” loops (unless they’re unrollable) etc.

NVIDIA CONFIDENTIAL Other profile limitations for NV30 No pointers – not supported by HW Function parameters are passed by value/result - not by reference as in C++ - use out or inout to declare output parameter - aliased parameters are written in order No unions or bit-fields No int data type

NVIDIA CONFIDENTIAL Cg Summary C-like language – expressive and efficient HW data types Vector and matrix operations Write separate vertex and fragment programs Connectors enable mix & match of programs by defining data flows Will be supported on any DX9 hardware Will support future HW (beyond NV30/DX9)

NVIDIA CONFIDENTIAL Brushed Metal Procedural texture Anisotropic lighting

NVIDIA CONFIDENTIAL Melting Ice Procedural, animating texture Bumped environment map

NVIDIA CONFIDENTIAL Toon & Fur Toon rendering without textures Antialiasing Great silhouettes without overdarkening Volume fur using ray marching Shell approach without shells Can be self-shadowing

NVIDIA CONFIDENTIAL Vegetation & Thin Film TranslucenceBacklighting Example of custom lighting Simulates iridescence

NVIDIA CONFIDENTIAL Questions?