Vertex and Pixel Shaders:

Similar documents
In-Game Special Effects and Lighting

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

3D buzzwords. Adding programmability to the pipeline 6/7/16. Bandwidth Gravity of modern computer systems

Where Is That Instruction? How To Implement Missing Vertex Shader Instructions

University of Toronto: CSC467F Compilers and Interpreters, Fall 2009

Project6 Lighting per-pixel shading and optimizations for Direct3D 8

Programmable Graphics Hardware

Rippling Reflective and Refractive Water

Could you make the XNA functions yourself?

1.2.3 The Graphics Hardware Pipeline

A Conceptual and Practical Look into Spherical Curvilinear Projection By Danny Oros

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

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

Chapter 3 ATI. Jason L. Mitchell

Optimal Shaders Using High-Level Languages

Basics of GPU-Based Programming

Windowing System on a 3D Pipeline. February 2005

Vertex Shader Introduction

Computer Graphics I Lecture 11

Game Architecture. 2/19/16: Rasterization

Introduction to Programmable GPUs CPSC 314. Real Time Graphics

CS 354R: Computer Game Technology

Spring 2011 Prof. Hyesoon Kim

Mattan Erez. The University of Texas at Austin

Technical Report. Mesh Instancing

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

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

Spring 2009 Prof. Hyesoon Kim

Introduction to Programmable GPUs CPSC 314. Introduction to GPU Programming CS314 Gordon Wetzstein, 09/03/09

CS451Real-time Rendering Pipeline

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

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

ECE 574 Cluster Computing Lecture 16

Hardware-Assisted Relief Texture Mapping

CS 4620 Program 3: Pipeline

Direct Rendering of Trimmed NURBS Surfaces

Shaders (some slides taken from David M. course)

CHAPTER 1 Graphics Systems and Models 3

Optimisation. CS7GV3 Real-time Rendering

Sung-Eui Yoon ( 윤성의 )

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Vertex Shader Design I

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

lecture 18 - ray tracing - environment mapping - refraction

Cg 2.0. Mark Kilgard

Shading Languages for Graphics Hardware

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

Drawing Fast The Graphics Pipeline

Hardware Shading on the ATI RADEON Jason L. Mitchell ATI Research

Evolution of GPUs Chris Seitz

Rendering Subdivision Surfaces Efficiently on the GPU

Advanced Texture-Mapping Curves and Curved Surfaces. Pre-Lecture Business. Texture Modes. Texture Modes. Review quiz

DirectX 9 Shading Jason L. Mitchell 3D Application Research Group Lead

Graphics Performance Optimisation. John Spitzer Director of European Developer Technology

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

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

Lecture 2. Shaders, GLSL and GPGPU

Computer Graphics (CS 543) Lecture 10: Soft Shadows (Maps and Volumes), Normal and Bump Mapping

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

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

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

How to Work on Next Gen Effects Now: Bridging DX10 and DX9. Guennadi Riguer ATI Technologies

A Real-Time Procedural Shading System for Programmable Graphics Hardware

Graphics Processing Units (GPUs) V1.2 (January 2010) Outline. High-Level Pipeline. 1. GPU Pipeline:

Programming Graphics Hardware

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

AGDC Per-Pixel Shading. Sim Dietrich

Real Time Rendering of Complex Height Maps Walking an infinite realistic landscape By: Jeffrey Riaboy Written 9/7/03

EMBEDDED VERTEX SHADER IN FPGA

Ultimate Graphics Performance for DirectX 10 Hardware

Shaders. Slide credit to Prof. Zwicker

Ray Casting of Trimmed NURBS Surfaces on the GPU

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Computer Graphics (CS 543) Lecture 10: Normal Maps, Parametrization, Tone Mapping

Real - Time Rendering. Pipeline optimization. Michal Červeňanský Juraj Starinský

Self-shadowing Bumpmap using 3D Texture Hardware

Graphics Hardware. Instructor Stephen J. Guy

CS 130 Final. Fall 2015

A Low Power Multimedia SoC with Fully Programmable 3D Graphics and MPEG4/H.264/JPEG for Mobile Devices

CAL Kernel Programming

Programmable Graphics Hardware

Introduction to the Direct3D 11 Graphics Pipeline

Introduction to the DirectX 9 Shader Models

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

12.2 Programmable Graphics Hardware

GpuPy: Accelerating NumPy With a GPU

Real-Time Graphics Architecture

Programming shaders & GPUs Christian Miller CS Fall 2011

Graphics Processing Unit Architecture (GPU Arch)

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Pipeline Operations. CS 4620 Lecture 14

GeForce4. John Montrym Henry Moreton

Interactive Cloth Simulation. Matthias Wloka NVIDIA Corporation

CS427 Multicore Architecture and Parallel Computing

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

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

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

Threading Hardware in G80

Software Engineering. ò Look up Design Patterns. ò Code Refactoring. ò Code Documentation? ò One of the lessons to learn for good design:

Transcription:

Vertex and Pixel Shaders: Making the world safe for Computer Graphics Adrian Perez 15-463: Computer Graphics 2 February 27 th, 2001

Administrivia Homework 1 will be handed back on Thursday Midterm is next Tuesday Review for midterm is this Thursday.

Talk Outline Motivation for vertex/pixel shaders Vertex Shaders Implementation in DX8 Examples Pixel Shaders Implementation in DX8 Examples Integration with other areas of DX8

But First holy war update Direct3D won. Get over it. OpenGL cannot accommodate the speed at which the graphics industry is moving now. All of the extentions to do things like vertex and pixel shading are vendor-specific. Direct3D stopped sucking a few versions ago anyway.

Transformation and Lighting The way D3D used to be was fixedfunction Unlit primitives (objectspace position/normal/material/uv s) Lit primitives (objectspace position/color/uv s) Transformed-and-lit primitives (screenspace position/color/uv s)

Transformation and Lighting The Good Provided a mechanism for people to roll their own T&L (back when everybody did so) The Bad Restrictive in function. You were bound to D3D s lighting model and transformation paradigm; not a terribly big deal for awhile

Transformation and Lighting Games these days want more control over the hardware Important because otherwise, every game is going through the same code path, making them look very similar Especially important since hardware is getting unfucking-believably fast Microsoft and nvidia realized that a more generic way for applications to perform transformation and lighting was needed

Enter Vertex Shaders A Vertex Shader is essentially assembly language for the T&L engine Subset of most ASM languages: no branching, for example If hardware T&L is available, the op-codes are just downloaded to the chip and run natively The op-codes are interpreted by a surprisingly fast software implementation if T&L hardware isn t available

Enter Vertex Shaders The Good Amazingly powerful You are not bound to provide it any specific data as input, as you are writing the handling code Much more precision everything is in floating point The Bad Hard to debug and grok We re right back in assembly hacking land

Vertex Shader Registers Input Registers Output Registers Name Count R/W Name Count R/W an 1 scalar W only odn 2 vectors W only c[n] 96 vectors R/W ofog 1 scalar W only rn 12 vectors R/W opos 1 vector W only vn 16 vectors R only opts 1 scalar W only otn 4 vectors W only

Vertex Shader Instructions add Sum dp3 Three-components dot-product dp4 Four-component dot-product dst Distance vector expp Exponential 10-bit precision lit Lighting coefficients logp Logarithm 10-bit precision mad Multiply and add max Maximum min Minimum mov Move mul Multiply rcp Reciprocal rsq Reciprocal square root sge Set on greater or equal than slt Set on less than sub Subtract def Define Constants vs Version and Type exp Exponential base2 full precis. frc Fraction log Logarithm base 2 full precision m3x2 3 2 vector matrix multiply m3x3 3 3 vector matrix multiply m3x4 3 4 vector matrix multiply m4x3 4 3 vector matrix multiply m4x4 4 4 vector matrix multiply

Vertex Shader Semantics Shaders are defined in a separate source file. They are compiled into bytecode (at runtime, if you wish) and then the bytecode can be loaded onto the card. When you render, you choose a vertex shader to use Fixed-function pipeline is still available (as a hard-coded vertex shader)

Vertex Shader Examples

Vertex Shader Examples #include "Constants.h" // v0 -- position // v1 -- normal // v2 -- tex coord vs.1.0 // compute world space position dp4 r1.x, v0, c[cv_world_0] dp4 r1.y, v0, c[cv_world_1] dp4 r1.z, v0, c[cv_world_2] dp4 r1.w, v0, c[cv_world_3] // transform position dp4 opos.x, v0, c[cv_worldviewproj_0] dp4 opos.y, v0, c[cv_worldviewproj_1] dp4 opos.z, v0, c[cv_worldviewproj_2] dp4 opos.w, v0, c[cv_worldviewproj_3] // transform normal dp3 r0.x, v1, c[cv_world_it_0] dp3 r0.y, v1, c[cv_world_it_1] dp3 r0.z, v1, c[cv_world_it_2] // vector from point to eye add r2, c[cv_eye], -r1 // normalize e dp3 r2.w, r2, r2 rsq r2.w, r2.w mul r2, r2, r2.w // e dot n dp3 ot1.x, r0, r2 // normalize normal dp3 r0.w, r0, r0 rsq r0.w, r0.w mul r0, r0, r0.w // l dot n dp3 ot0.x, r0, c[cv_light_direction]

Vertex Shader Examples

Vertex Shader Examples ; Distorts vertices in eye-space to give a fish-eye lens effect #include "trees.h" #define FACTOR_KPLUS1 c[cv_constants].x #define XYZW_MAX_XZRATIO x #define XYZW_FACTOR_K y #define XYZW_ZERO z #define XYZW_ONE w vs.1.0 ; Transform position to view space dp4 r0.x, v0, c[cv_worldview_0] dp4 r0.y, v0, c[cv_worldview_1] dp4 r0.z, v0, c[cv_worldview_2] dp4 r0.w, v0, c[cv_worldview_3] ; scale x and y, set z and w to 0 mul r1, r0, c[cv_fisheyeinfo].xxzz ; compute normalized distance from camera (camera in viewspace is alwasy at (0,0,0)) ; r1.x = sqrt(x^2 + y^2)/z dp3 r1.x, r1, r1 rsq r1.y, r1.x mul r1.y, r1.y, r0.z rcp r1.x, r1.y ; and take the absolute value max r1.x, r1.x, -r1.x ; compute (k*d + 1) mad r1.z, r1.x, c[cv_fisheyeinfo].xyzw_factor_k, c[cv_fisheyeinfo].xyzw_one ; compute (k+1)/(k*d + 1) -- this is the reciprocal formula of the ; above referenced web-page because our distances are ; generally not less than 1.0! rcp r1.z, r1.z mul r1.xy, FACTOR_KPLUS1, r1.z ; only scale the original x, y with this factor mul r0.xy, r0, r1 ; transform new position to clip space dp4 opos.x, r0, c[cv_proj_0] dp4 opos.y, r0, c[cv_proj_1] dp4 opos.z, r0, c[cv_proj_2] dp4 opos.w, r0, c[cv_proj_3] ; Draw using supplied tree color mov od0.xyzw, v1 mov ot0.xy, v2

Vertex Shader Examples

One Last Example

One Last Example vs.1.0 ; Projected Textures ; Adrian Perez ; 2/27/01 ; Constants: ; c0-c3 - World+View+Projection matrix ; c4-c7 - Texture matrix 1 ; c8 - Color ; c9-1.0 ; c10 - -0.5's for adjusting the texture coordinate ; c11 - Texture position 1 (worldspace) ; c12-c15 - world->model matrix ; Transform position m4x4 opos, v0, c0 ; r3: the light positoin in worldspace mov r3, c11 ; r4: the light position in modelspace m4x4 r4, r3, c12 ; r5: subtract the model-space position to get a light vector sub r5, r4, v0 ; r8: store the temp length dp3 r8.w, r5, r5 ; r6: reciprocal square root of the scalar rsq r6.xyzw, r8 ; Set r0 to the clip-space view from the texture light m4x4 r0, v0, c4 ; Normalize r5 with r6 mul r5.xyz, r5.xyz, r6.xyz ; Fill r1 with 1's mov r1, c9 ; Compute two recriprocals to do perspective correction rcp r1.xy, r0.z ; Apply reciprocals mul r2, r0, r1 ; subtract 0.5's to adjust the texture coordinates add r2.xy, r2.xy, c10.xy ; r6: Compute a dot product to find the diffuse light dp3 r6.x, r5, v3 ; modulate r6 by the diffuse color mul r6, r6.xxxx, c8 ; Write out the color and texture mov od0, r6 mov ot0, r2

Pixel Shaders Same idea as vertex shaders, but they control how textures and colors are combined per-pixel Currently there is no hardware that implements them The GeForce3 (when it comes out) will do them, so will the XBox

Pixel Shaders The Good Explicit control of texture combining Lots of Nifty Tricks (EMBM) The Bad Designed for a more general piece of hardware; a lot of the functionality of the GeForce3 is not exposed

Pixel Shader Registers Name I/O Min. Number Max/Inst Source cn Read-only 8 2 API call rn Read/write 2 2 Written tn Read/write 4 1 Textures vn Read-only 2 1 Vertex Colors

Pixel Shader Instructions add Add cnd Conditional dp3 Three-Component Vector Dot- Product lrp Linear Interpolation Blend mad Multiply and Add mov Copy Source Into Destination mul Modulate sub Loads the difference of the two colors in the source operands. tex No Modification texbem Bump Environment Map texbeml Bump Environment Map with Luminance texcoord Texture Coordinate texkill Mask Out Pixel texm3x2pad Input to 3 2 Matrix Multiply texm3x2tex 3 2 Matrix Multiply Result texreg2ar Remapping Alpha and Red Components texreg2gb Remapping Green and Blue Components texm3x3pad Input to 3 3 Matrix Multiply texm3x3spec Specular Reflection and Environment Mapping texm3x3tex 3 3 Matrix Multiply Result texm3x3vspec Specular Reflection/Environment Mapping without Constant Eye Vector

Pixel Shader Examples Unfortunately, right now the only way to develop pixel shader apps is to use the Reference Rasterizer. So source on how to use it is pretty scarce The documentation is also pretty cryptic, it s not nearly as wellengineered as vertex shaders are

Pixel Shader Examples

Pixel Shader Examples

Other Cool Shit in DX8 N-Patches Subdivision scheme that requires no adjacency information. You provide a set of vertices and vertex normals, and it renders a smooth mesh. Neat: You send the base level mesh down to the card, and your vertex shader gets fed the subdivided vertices. This is one good way to get around the fact that you can t create new vertices in a shader Bezier surfaces Yea, yea they re not as cool as N-Patches

N-Patches

Other Cool Shit in DX8 Volume Textures Holy crap these things fucking rock Finally, an elegant way to handle explosions and rocket flares Plus a million other tricks Third texture coordinate, they behave almost exactly like 2D textures

Other Cool Shit not in DX8 Shadow Mapping Supported by the GeForce3, but the functionality is not exposed by DX8. And yes, it is exposed in OpenGL. (sigh )

Conclusion DirectX 8.0 is the fucking bomb.

Questions????