Cg 2.0. Mark Kilgard

Similar documents
GeForce 8 Features for OpenGL

Cg Toolkit. Cg 2.0 January 2008 Release Notes

Cg Toolkit. Cg 2.0 May 2008 Release Notes

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

Cg Toolkit. Cg 2.2 February 2010 Release Notes

Cg Toolkit. Cg 2.2 April 2009 Release Notes

Cg Toolkit. Cg 2.1 October 2008 Release Notes

Cg Toolkit. Cg 2.1 beta August 2008 Release Notes

X. GPU Programming. Jacobs University Visualization and Computer Graphics Lab : Advanced Graphics - Chapter X 1

Introduction to Shaders.

Graphics Hardware. Graphics Processing Unit (GPU) is a Subsidiary hardware. With massively multi-threaded many-core. Dedicated to 2D and 3D graphics

Shaders (some slides taken from David M. course)

Shaders. Slide credit to Prof. Zwicker

Lecture 2. Shaders, GLSL and GPGPU

CS GPU and GPGPU Programming Lecture 7: Shading and Compute APIs 1. Markus Hadwiger, KAUST

Programmable GPUS. Last Time? Reading for Today. Homework 4. Planar Shadows Projective Texture Shadows Shadow Maps Shadow Volumes

CS427 Multicore Architecture and Parallel Computing

Programmable Graphics Hardware

Cg Toolkit. Cg 1.3 Release Notes. December 2004

Could you make the XNA functions yourself?

Programmable GPUs. Real Time Graphics 11/13/2013. Nalu 2004 (NVIDIA Corporation) GeForce 6. Virtua Fighter 1995 (SEGA Corporation) NV1

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

GPGPU. Peter Laurens 1st-year PhD Student, NSC

Rendering Subdivision Surfaces Efficiently on the GPU

Graphics Hardware, Graphics APIs, and Computation on GPUs. Mark Segal

Graphics Hardware. Instructor Stephen J. Guy

The Application Stage. The Game Loop, Resource Management and Renderer Design

Rendering Objects. Need to transform all geometry then

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Programming with OpenGL Part 3: Shaders. Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Spring 2009 Prof. Hyesoon Kim

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

12.2 Programmable Graphics Hardware

Programming Graphics Hardware

COMP371 COMPUTER GRAPHICS

Siggraph Agenda. Usability & Productivity. FX Composer 2.5. Usability & Productivity 9/12/2008 9:16 AM

Canonical Shaders for Optimal Performance. Sébastien Dominé Manager of Developer Technology Tools

Programming shaders & GPUs Christian Miller CS Fall 2011

Shader Series Primer: Fundamentals of the Programmable Pipeline in XNA Game Studio Express

CSE 167: Lecture #8: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

frame buffer depth buffer stencil buffer

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

Programmable Graphics Hardware

Tutorial on GPU Programming. Joong-Youn Lee Supercomputing Center, KISTI

Getting Started with Cg. Release 1.2 February 2004

Next-Generation Graphics on Larrabee. Tim Foley Intel Corp

A Trip Down The (2011) Rasterization Pipeline

Evolution of GPUs Chris Seitz

NVSG NVIDIA Scene Graph

Spring 2011 Prof. Hyesoon Kim

Beginning Direct3D Game Programming: 1. The History of Direct3D Graphics

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

OpenGL SUPERBIBLE. Fifth Edition. Comprehensive Tutorial and Reference. Richard S. Wright, Jr. Nicholas Haemel Graham Sellers Benjamin Lipchak

Programming with OpenGL Shaders I. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

CSE 167: Introduction to Computer Graphics Lecture #7: GLSL. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Developer Tools. Robert Strzodka. caesar research center Bonn, Germany

Cg Toolkit. Cg 1.4 rc 1 Release Notes

3D Computer Games Technology and History. Markus Hadwiger VRVis Research Center

What was removed? (1) OpenGL ES vs. OpenGL

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

Dave Shreiner, ARM March 2009

Supplement to Lecture 22

SHADER PROGRAMMING. Based on Jian Huang s lecture on Shader Programming

1.2.3 The Graphics Hardware Pipeline

2.11 Particle Systems

Cg Toolkit. Cg 1.2 Release Notes

OpenGL Status - November 2013 G-Truc Creation

DirectX10 Effects and Performance. Bryan Dudash

CHAPTER 1 Graphics Systems and Models 3

Shaders CSCI 4229/5229 Computer Graphics Fall 2017

GLSL Introduction. Fu-Chung Huang. Thanks for materials from many other people

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Graphics Hardware. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 2/26/07 1

Basics of GPU-Based Programming

Introduction. What s New in This Edition

Sung-Eui Yoon ( 윤성의 )

CS4621/5621 Fall Computer Graphics Practicum Intro to OpenGL/GLSL

A SIMD-efficient 14 Instruction Shader Program for High-Throughput Microtriangle Rasterization

Mattan Erez. The University of Texas at Austin

Motivation MGB Agenda. Compression. Scalability. Scalability. Motivation. Tessellation Basics. DX11 Tessellation Pipeline

Introduction to OpenGL

RSX Best Practices. Mark Cerny, Cerny Games David Simpson, Naughty Dog Jon Olick, Naughty Dog

Accelerating Realism with the (NVIDIA Scene Graph)

Teaching Cg. This presentation introduces Cg ( C for graphics ) and explains why it would be useful when teaching a computer graphics course.

DirectX10 Effects. Sarah Tariq

NVIDIA FX Composer. Developer Presentation June 2004

Optimal Shaders Using High-Level Languages

CS770/870 Spring 2017 Open GL Shader Language GLSL

CS770/870 Spring 2017 Open GL Shader Language GLSL

OpenGL Programmable Shaders

Lecture 13: OpenGL Shading Language (GLSL)

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

CS451Real-time Rendering Pipeline

CS770/870 Fall 2015 Advanced GLSL

printf Debugging Examples

CS GPU and GPGPU Programming Lecture 3: GPU Architecture 2. Markus Hadwiger, KAUST

Shaders CSCI 4239/5239 Advanced Computer Graphics Spring 2014

Graphics Processing Unit Architecture (GPU Arch)

EECS 487: Interactive Computer Graphics

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Transcription:

Cg 2.0 Mark Kilgard

What is Cg? Cg is a GPU shading language C/C++ like language Write vertex-, geometry-, and fragmentprocessing kernels that execute on massively parallel GPUs Productivity through a high-level language Supports NVIDIA, ATI, and Intel graphics Supports OpenGL and Direct3D Cg also run-time system for shaders Run-time makes best use of available GPU Use OpenGL or Direct3D Effect system for meta-shading

Why Cg? Cg = cross-platform shaders Same Cg shader source compiles to: Multi-vendor OpenGL extensions ARB_vertex_program & ARB_fragment_program.) NVIDIA-specific OpenGL extensions GeForce 8 s NV_gpu_program4 DirectX 9 assembly shaders Shader Models 1.x, 2.x, and 3.x OpenGL Shading Language (GLSL) cross-compile! DirectX 9 HLSL cross-compile! Sony s support for Cg for PlayStation 3 Multi-OS: Vista, XP, 2000, MacOS X, Linux, Solaris Sophisticated CgFX effects system Compatible with Microsoft s FX in DirectX 9 Abstraction no other GPU standard shading language has Interfaces and un-sized arrays

Why Cg 2.0? Keeps current with DirectX 10-class functionality New profiles for GeForce 8 Geometry shaders Bind-able uniform buffers, a.k.a. constant buffers Texture arrays New HLSL 9 cross-compile profiles Performance improvements Compiler improvements New examples show of Cg 2.0 and GeForce 8 Greatly expanded documentation

Primary Cg 2.0 Features 100% compatibility with Cg 1.5 New GeForce 8 (G80) OpenGL profiles gp4vp (vertex), gp4gp (geometry), gp4fp (fragment) Per-primitive (geometry) programs Vertex attribute arrays Primitive types: point, line, line adjacency, triangle, triangle adjacency Bind-able buffers for uniform parameters Texture arrays & texture buffer objects Interpolation modifiers (flat, centroid, non-perspective) True 32-bit integer variables and operators New HLSL9 profiles hlslv (vertex), hlslf (fragment) Run-time or compile-time translation of Cg to optimized HLSL

Other Cg 2.0 Features New compiler back-end for DX10-class unified, scalar GPU architecture Improved FX compatibility for CgFX More efficient parameter update API via buffers Updated documentation New Cg language specification New CgFX standard state manual pages New Cg standard library manual pages New Cg runtime API manual pages Updated examples Geometry shaders, uniform buffers, interpolation modifiers, etc.

Cg 2.0 Support for GeForce 8 OpenGL New G80 profiles New programmable gp4vp: NV_gpu_program4 vertex program domain gp4gp: NV_gpu_program4 geometry program gp4fp: NV_gpu_program4 fragment program New Cg language support int variables really are integers now Temporaries dynamically index-able now All G80 texturing operations exposed New samplers, new standard library functions New semantics Instance ID, vertex ID, bind-able buffers, viewport ID, layer Geometry shader support Attrib arrays, emitvertex & restartstrip library routines Profile modifiers for primitive input and output type

Geometry Pass Through Example Length of attribute arrays depends on the input primitive mode, 3 for TRIANGLE Semantic ties uniform parameter to a buffer, compiler assigns offset uniform float4 flatcolor : BUFFER[0] ; TRIANGLE void passthru(attribarray<float4> position : POSITION, AttribArray<float4> texcoord : TEXCOORD0) { flatattrib(flatcolor:color); for (int i=0; i<position.length; i++) { emitvertex(position[i], texcoord[i],float3(1,0,0):texcoord1); } } Makes sure flat attributes are associated with the proper provoking vertex convention Bundles a vertex based on parameter values and semantics

Hermite Curve Tessellation void LINE hermitecurve(attribarray<float4> position : POSITION, AttribArray<float4> tangent : TEXCOORD0, { uniform float steps) // # line segments to approx. curve emitvertex(position[0]); for (int t=1; t<steps; t++) { float s = t / steps; float ssquared = s*s; float scubed = s*s*s; float h1 = 2*scubed - 3*ssquared + 1; // calculate basis function 1 float h2 = -2*scubed + 3*ssquared; // calculate basis function 2 float h3 = scubed - 2*ssquared + s; // calculate basis function 3 float h4 = scubed - ssquared; // calculate basis function 4 } float4 p : POSITION = h1*position[0] + // multiply and sum all functions h2*position[1] + // together to build interpolated h3*tangent[0] + // point along the curve h4*tangent[1]; emitvertex(p); } emitvertex(position[1]); (Geometry shaders not really ideal for tessellation.)

True Quadrilateral Rasterization & Interpolation (1) The world is not all triangles Quads exist in real-world meshes Fully continuous interpolation over quads not linear Mean value coordinate interpolation [Floater, Hormann & Tarini] Quads can bow tie Not really a quad Good

True Quadrilateral Rasterization & Interpolation (2) Conventional hardware: How you split quad to triangles can greatly alter interpolation Both ways to split introduce interpolation discontinuities Slash split Backslash split Mean value coordinate interpolation via Cg geometry and fragment shaders

Bump Map Skinned Characters (1) Pre-geometry shader approach: CPU computes texture-space basis per skinned triangle to transform lighting vectors properly Problem: Meant skinning was done on the CPU, not GPU Bump skin GPU Rendering Key frame blended 3D model Decal skin Gloss skin

Bump Map Skinned Characters (2) Cg vertex shader does skinning Cg geometry shader computes transform from object- to texture-space based on each triangle Cg geometry shader then transforms skinned objectspace vectors (light and view) to texture space Cg fragment shader computes bump mapping using texturespace normal map Computations all stay on the GPU

Next, Geometry Shader-Generated Shadows with Stenciled Shadow Volumes Cg geometry shader computes possible silhouette edges from triangle adjacency (visualization) Extrude shadow volumes based on triangle facing-ness and silhouette edges (visualization) Add bump mapped lighting based on stenciled shadow volume rendering (complete effect)

Geometry Shader Setup for Quadratic Normal Interpolation Linear interpolation of surface normals don t match real surfaces (except for flat surfaces) Quadratic normal interpolation [van Overveld & Wyvill] Better Phong lighting, even at low tessellation Approach Geometry shader sets up linear parameters Fragment shader combines them for quadratic result Best exploits GPU s linear interpolation resources

Cg 2.0 Bind-able Buffer API Cg API modeled after OpenGL buffer object API cgcreatebuffer creates bindable uniform buffer CGbuffer cgbuffer = cgcreatebuffer(cgcontext, sizeinbytes, NULL, CG_BUFFER_USAGE_xxx) cgsetbuffersubdata copies bytes into buffer cgsetbuffersubdata(cgbuffer, offset, sizeinbytes, data); Also cgsetbufferdata redefines entire buffer with new size Also cgmapbuffer & cgunmapbuffer gives pointer to buffer data cgsetprogrambuffer associates buffer object to program s buffer index Cg program maps uniforms to buffers with BUFFER semantic: uniform float4 someuniform[20] : BUFFER[5]; cggetparameterbufferoffset & cggetparameterindex cgsetprogrambuffer(cgprogram, cggetparameterbufferindex(cgparam, cggetnamedparameter( someuniform )), cgbuffer);

Cg 2.0 API-specific Buffers cgcreatebuffer creates API-independent buffers Cg runtime creates API-dependent buffers as needed Cg runtime fakes bind-able buffers for pre-directx 10-class (pre-g80) profiles Allows runtime to perform efficient parameter update into the API-dependent buffers cgglcreatebuffer creates API-dependent buffers for OpenGL Cg runtime creates OpenGL buffer Cg runtime will provide GLuint handle to the buffer All buffer interactions by Cg require immediate 3D APIdependent execution Expected usage Use cg buffers for batching conventional uniforms more efficiently Use cggl buffers for transform feedback, pixel buffer object read-backs, etc. when GPU is writing data into buffers

Updated Documentation New CgReferenceManual.pdf includes New Cg language specification Updated run-time API documentation Full Cg standard library CgFX states documented Command-line cgc compiler documentation Reference manual also available as Unix-style man pages Microsoft s indexed & search-able Compiled HTML CgReferenceManual.chm Raw HTML pages Includes tutorial white papers on Cg and CgFX

Greatly Expanded Examples Examples from The Cg Tutorial Twenty-two OpenGL-based examples with both C and Cg source code Using OpenGL Utility Toolkit (GLUT) Seven also available as Direct3D-based examples Using minidxut Advanced examples Vertex texturing for GeForce 6 and up vertex_texture Interfaces and un-sized arrays cgfx_interfaces Geometry shader examples for GeForce 8 Simple (gs_simple, gs_shrinky), texture-space bump mapping setup (gs_md2bump), shadow volume generation (gs_md2shadow, gs_md2shadowvol), quadrilateral rasterization (gs_interp_quad), quadratic normal interpolation (gs_quadnormal) Buffer example for GeForce 8 buffer_lighting Other GeForce 8 features Texture arrays (cgfx_texture_array, texture_array), interpolation_modifiers Examples packaged with all operating systems