Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진 2002. 02. 05.

Slides:



Advertisements
Similar presentations
Fragment level programmability in OpenGL Evan Hart
Advertisements

DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.
Normal Map Compression with ATI 3Dc™ Jonathan Zarge ATI Research Inc.
Understanding the graphics pipeline Lecture 2 Original Slides by: Suresh Venkatasubramanian Updates by Joseph Kider.
Graphics Pipeline.
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
Texture Mapping. Texturing  process that modifies the appearance of each point on a surface using an image or function  any aspect of appearance can.
CS-378: Game Technology Lecture #9: More Mapping Prof. Okan Arikan University of Texas, Austin Thanks to James O’Brien, Steve Chenney, Zoran Popovic, Jessica.
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.
Shading Languages GeForce3, DirectX 8 Michael Oswald.
A Crash Course on Programmable Graphics Hardware Li-Yi Wei 2005 at Tsinghua University, Beijing.
Status – Week 243 Victor Moya. Summary Current status. Current status. Tests. Tests. XBox documentation. XBox documentation. Post Vertex Shader geometry.
Skin Rendering GPU Graphics Gary J. Katz University of Pennsylvania CIS 665 Adapted from David Gosselin’s Power Point and article, Real-time skin rendering,
Status – Week 277 Victor Moya.
Status – Week 276 Victor Moya. Hardware Pipeline Command Processor. Command Processor. Vertex Shader. Vertex Shader. Rasterization. Rasterization. Pixel.
ARB Fragment Program in GPULib. Summary Fragment program arquitecture New instructions.  Emulating instructions not supported directly New Required GL.
Status – Week 281 Victor Moya. Objectives Research in future GPUs for 3D graphics. Research in future GPUs for 3D graphics. Simulate current and future.
1 Copyright © 2001 Intel Corporation. * Other names and brands may be claimed as the property of others. Meltdown 2001 Optimizing DirectX* Graphic Applications.
Mohan Sridharan Based on slides created by Edward Angel GLSL I 1 CS4395: Computer Graphics.
Vertex & Pixel Shaders CPS124 – Computer Graphics Ferdinand Schober.
Compilation, Architectural Support, and Evaluation of SIMD Graphics Pipeline Programs on a General-Purpose CPU Mauricio Breternitz Jr, Herbert Hum, Sanjeev.
GPU Graphics Processing Unit. Graphics Pipeline Scene Transformations Lighting & Shading ViewingTransformations Rasterization GPUs evolved as hardware.
Cg Kevin Bjorke GDC NVIDIA CONFIDENTIAL A Whole New World with Cg Graphics Program Written in Cg “C” for Graphics Compiled & Optimized Low Level,
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.
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.
A Crash Course in HLSL Matt Christian.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Blending, Modern Hardware.
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.
Computer Graphics The Rendering Pipeline - Review CO2409 Computer Graphics Week 15.
GAM532 DPS932 – Week 2 Vertex Shaders. The Shader Pipeline Vertex Processing Primitive Assembly / Processing Rasterization Fragment Process Pixel Output.
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.
A Few Things about Graphics Jian Huang Computer Science University of Tennessee.
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
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.
Graphics Graphics Korea University cgvr.korea.ac.kr Lighting, Fogging, Alpha Blending & Progressive Meshes Byeong-Seon Jeong
Lab: Vertex Shading Chris Wynn Ken Hurley. Objective Hands-On vertex shader programming Start with simple programs … Part 1: Textured-Lit Teapot.
David Luebke 1 1/25/2016 Programmable Graphics Hardware.
09/25/03CS679 - Fall Copyright Univ. of Wisconsin Last Time Shadows Stage 2 outline.
Current Student – University of Wisconsin – Stout Applied Mathematics and Computer Science: Software Development Associate Degree in Computer Programming.
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.
Mesh Skinning Sébastien Dominé. Agenda Introduction to Mesh Skinning 2 matrix skinning 4 matrix skinning with lighting Complex skinning for character.
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.
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.
Vertex Program Modules
Programmable Shaders Dr. Scott Schaefer.
Programmable Pipelines
A Crash Course on Programmable Graphics Hardware
Graphics Processing Unit
Chapter 6 GPU, Shaders, and Shading Languages
The Graphics Rendering Pipeline
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 Programmable Hardware
Graphics Processing Unit
Where does the Vertex Engine fit?
Programming with OpenGL Part 3: Shaders
RADEON™ 9700 Architecture and 3D Performance
Computer Graphics Introduction to Shaders
CIS 441/541: Introduction to Computer Graphics Lecture 15: shaders
CS 480/680 Computer Graphics GLSL Overview.
CS 480/680 Fall 2011 Dr. Frederick C Harris, Jr. Computer Graphics
Presentation transcript:

Graphics Graphics Korea University cgvr.korea.ac.kr 1 Using Vertex Shader in DirectX 8.1 강 신 진

CGVR Graphics Korea University cgvr.korea.ac.kr 2 Overview What is Vertex Programming? Vertex Programming Assembly Language Sample Programs Instruction Set

Graphics Graphics Korea University cgvr.korea.ac.kr 3 What is Vertex Programming? Part 1

CGVR Graphics Korea University cgvr.korea.ac.kr 4 Traditional Rendering Pipeline Traditional Graphics Pipeline frame-buffer anti-aliasing texture blending setup rasterizer transform & lighting

CGVR Graphics Korea University cgvr.korea.ac.kr 5 Vertex Shader Rendering Pipeline SetVertexShader() frame-buffer anti-aliasing texture blending setup rasterizer transform & lighting Vertex Program Switch from standard T&L mode to Vertex Program mode

CGVR Graphics Korea University cgvr.korea.ac.kr 6 What is Possible? Complete control of transform and lighting HW Complex vertex operations accelerated in HW Custom vertex lighting Custom skinning and blending Custom texture coordinate generation Custom texture matrix operations Custom vertex computations of your choice Offloading vertex computations frees up CPU

CGVR Graphics Korea University cgvr.korea.ac.kr 7 What is Possible? Custom transform, lighting, and skinning Directional Light Bump Point LightingKeyframe Interpolation

CGVR Graphics Korea University cgvr.korea.ac.kr 8 Vertex Attributes Vertex Program Vertex Output Program Parameters Temporary Registers Read/Write-able 16x4 registers 128 instructions 96x4 registers 12x4 registers Read-only Vertex Programming Conceptual Overview

CGVR Graphics Korea University cgvr.korea.ac.kr 9 Vertex Programming Conceptual Overview Vertex Attribute Registers Vertex Program Vertex Result Registers Program Parameter Registers Temporary Registers v[0] v[1] … v[15] c[0] c[1] … c[95] R0 R1 … R10 R11 oPos, oD0 r r r/w w Address Register A0.x

CGVR Graphics Korea University cgvr.korea.ac.kr 10 Sample Code Position & Constant Color reg c0= (0,0.5,1.0,2.0) reg c4-7= WorldViewProj matrix reg c8 = constant color reg v0= position ( 4x1 vector ) reg v5= diffuse color const char SimpleVertexShader0[] =“ vs.1.0 //Shader version 1.0 m4x4 oPos, v0, c4 //emit projected position mov oD0, c8 //Diffuse color = c8”

CGVR Graphics Korea University cgvr.korea.ac.kr 11 What is Vertex Programming? Vertex Program Assembly language interface to T&L unit GPU instruction set to perform all vertex math Reads an untransformed, unlit vertex Creates a transformed vertex Optionally creates  Lights a vertex  Creates texture coordinates  Creates fog coordinates  Creates point sizes

CGVR Graphics Korea University cgvr.korea.ac.kr 12 What is Vertex Programming? Vertex Program Does not create or delete vertices  1 vertex in and 1 vertex out No topological information provided  No edge, face, nor neighboring vertex info Dynamically loadable

Graphics Graphics Korea University cgvr.korea.ac.kr 13 Vertex Programming Assembly Language Part 2

CGVR Graphics Korea University cgvr.korea.ac.kr 14 Instruction Format: Opcodedst, [-]s0 [,[-]s1 [,[-]s2]];#comment Instruction name Destination Register Source0 Register Source1 Register Source2 Register Assembly Language Format

CGVR Graphics Korea University cgvr.korea.ac.kr 15 Instruction Format: Opcodedst, [-]s0 [,[-]s1 [,[-]s2]];#comment Instruction name Destination Register Source0 Register Source1 Register Source2 Register Example: MOVr1, r2 R1 x y z w R2 x y z w Assembly Language Format

CGVR Graphics Korea University cgvr.korea.ac.kr 16 Simple Example: MOVR1, R2; R1 x y z w R2 x y z w R1 x y z w 0.0 R2 x y z w beforeafter Assembly Example

CGVR Graphics Korea University cgvr.korea.ac.kr 17 Source registers can be negated: MOVR1, -R2; beforeafter R1 x y z w 0.0 R2 x y z w R1 x y z w R2 x y z w Assembly Example

CGVR Graphics Korea University cgvr.korea.ac.kr 18 Destination register can mask which components are written to… R1  write all components R1.x  write only x component R1.xw  write only x, w components Masking

CGVR Graphics Korea University cgvr.korea.ac.kr 19 Destination register masking: MOVR1.xw, -R2; beforeafter R1 x y z w 0.0 R2 x y z w R1 x y z w R2 x y z w Masking

CGVR Graphics Korea University cgvr.korea.ac.kr 20 There are 17 instructions in total ARL MOV MUL ADD MAD RCP RSQ DP3 DP4 DST MIN MAX SLT SGE EXP LOG LIT All Instructions

Graphics Graphics Korea University cgvr.korea.ac.kr 21 Sample Program Part 3

CGVR Graphics Korea University cgvr.korea.ac.kr 22 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 23 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 24 Step 1 Declare the vertex data struct CUSTOMVERTEX { FLOAT x, y, z; DWORD diffuseColor; }; #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE) CUSTOMVERTEX g_Vertices[]= { { -1.0f, -1.0f, 0.0f, 0xffff0000 }, { +1.0f, -1.0f, 0.0f, 0xff00ff00 }, { +1.0f, +1.0f, 0.0f, 0xff0000ff }, { -1.0f, +1.0f, 0.0f, 0xffffff00 }, };

CGVR Graphics Korea University cgvr.korea.ac.kr 25 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 26 Basic Instruction (Step 2) DP3: Three-Component Dot Product Function: Computes the three-component (x,y,z) dot product of two source vectors and replicates the result across the destination register. Syntax: DP3dest, src0, src1;

CGVR Graphics Korea University cgvr.korea.ac.kr 27 Basic Instruction (Step 2) beforeafter DP3 Example: DP3R1, R6, R6; x y z w R R1 0.0 x y z w R R1 14.0

CGVR Graphics Korea University cgvr.korea.ac.kr 28 Sample Code – 1 (Step 2) Position & Diffuse Color reg c0= (0,0.5,1.0,2.0) reg c4-7= WorldViewProj matrix reg c8 = constant color reg v0= position ( 4x1 vector ) reg v5= diffuse color const char SimpleVertexShader1[] =“ vs.1.0 //Shader version 1.0 dp4 oPos.x, v0, c4 //emit projected x position dp4 oPos.y, v0, c5 //emit projected y position dp4 oPos.z, v0, c6 //emit projected z position dp4 oPos.w, v0, c7 //emit projected w position mov oD0, v5 //Diffuse color = vertex color ”

CGVR Graphics Korea University cgvr.korea.ac.kr 29 Sample Code – 2 (Step 2) Position & Texture reg c0= (0,0.5,1.0,2.0) reg c4-7= WorldViewProj matrix reg c8 = constant color reg v0= position ( 4x1 vector ) reg v5= diffuse color reg v7= texcoords ( 2x1 vector ) const char SimpleVertexShader2[] =“ vs.1.0 //Shader version 1.0 dp4 oPos.x, v0, c4 //emit projected x position dp4 oPos.y, v0, c5 //emit projected y position dp4 oPos.z, v0, c6 //emit projected z position dp4 oPos.w, v0, c7 //emit projected w position mov oT0.xy, v7 //copy texcoords”

CGVR Graphics Korea University cgvr.korea.ac.kr 30 Sample Code – 3 (Step 2) Position & Lighting reg c0= (0,0.5,1.0,2.0) reg c4-7= WorldViewProj matrix reg c8 = constant color reg v0= position ( 4x1 vector ) reg v5= diffuse color reg v7= texcoords ( 2x1 vector ) const char SimpleVertexShader3[] = vs.1.0 //Shader version 1.0 dp4 oPos.x, v0, c4 //emit projected x position dp4 oPos.y, v0, c5 //emit projected y position dp4 oPos.z, v0, c6 //emit projected z position dp4 oPos.w, v0, c7 //emit projected w position dp3 r0.x, v3, c12 //N dot L in world space mul oD0, r0.x, v5 //Calculate color intensity mov oT0.xy, v7 //copy texcoords

CGVR Graphics Korea University cgvr.korea.ac.kr 31 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 32 Step 3 Check for vertex shader support D3DCAPS8 caps; m_pd3dDevice->GetDeviceCaps(&caps); if( D3DSHADER_VERSION_MAJOR( caps.VertexShaderVersio n ) < 1 ) return E_FAIL;

CGVR Graphics Korea University cgvr.korea.ac.kr 33 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 34 Step 4 Declare the shader registers DWORD dwDecl[] = { D3DVSD_STREAM(0), D3DVSD_REG(D3DVSDE_POSITION, D3DVSDT_FLOAT3), D3DVSD_REG( D3DVSDE_DIFFUSE, D3DVSDT_D3DCOLOR ), D3DVSD_END() };

CGVR Graphics Korea University cgvr.korea.ac.kr 35 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 36 Step 5 Create the shader TCHAR strPath[512]; LPD3DXBUFFER pCode; DXUtil_FindMediaFile( strPath, _T("VertexShader.vsh") ); D3DXAssembleShaderFromFile( strPath, 0, NULL, &pCode, NULL ); m_pd3dDevice->CreateVertexShader( dwDecl, (DWORD*)pCode- >GetBufferPointer(), &m_hVertexShader, 0 ))) pCode->Release();

CGVR Graphics Korea University cgvr.korea.ac.kr 37 Vertex Shader Frame Work in DX 8.1 Step 1: Declare the vertex data Step 2: Design the shader functionality Step 3: Check for vertex shader support Step 4: Declare the shader registers Step 5: Create the shader Step 6: Render the output pixels

CGVR Graphics Korea University cgvr.korea.ac.kr 38 Step 6 Render the output pixels m_pd3dDevice->SetVertexShaderConstant( 0, &mat, 4 ); float color[4] = {0,1,0,0}; m_pd3dDevice->SetVertexShaderConstant( 4, &color, 1 ); m_pd3dDevice->SetStreamSource( 0, m_pQuadVB, sizeof(CUSTOMVERTEX) ); m_pd3dDevice->SetVertexShader( m_hVertexShader ); m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLEFAN, 0, 2 );

CGVR Graphics Korea University cgvr.korea.ac.kr 39 Demo Program

CGVR Graphics Korea University cgvr.korea.ac.kr 40 Performance For Optimal performance Be clever Exploit vector parallelism (Ex. 4 scalar adds with a vector add) Swizzle and negate away (no performance penalty for doing so) Use LIT and DST effectively

CGVR Graphics Korea University cgvr.korea.ac.kr 41 Summary – Vertex Programs Increased programmability Customizable engine for transform, lighting, texture coordinate generation, and more. Facilitates setup for per-fragment shading. Allows animation/deformation through key-frame interpolation and skinning. Accelerated in Future Generation GPUs Offloads CPU tasks to GPU yielding higher performance.

Graphics Graphics Korea University cgvr.korea.ac.kr 42 The Instruction Set Appendix

CGVR Graphics Korea University cgvr.korea.ac.kr 43 There are 17 instructions in total ARL MOV MUL ADD MAD RCP RSQ DP3 DP4 DST MIN MAX SLT SGE EXP LOG LIT All Instructions

CGVR Graphics Korea University cgvr.korea.ac.kr 44 RCP RCP: Reciprocal Function: Inverts the value of the source and replicates the result across the destination register. Syntax: RCPdest, src0.C; where ‘C’ is x, y, z, or w

CGVR Graphics Korea University cgvr.korea.ac.kr 45 RCP beforeafter RCP Example: RCPR1, R2.w; x y z w R R1 0.0 x y z w R R1 0.5

CGVR Graphics Korea University cgvr.korea.ac.kr 46 RSQ RSQ: Reciprocal Square Root Function: Computes the inverse square root of the absolute value of the source scalar and replicates the result across the destination register. Syntax: RSQdest, src0.C; where ‘C’ is x, y, z, or w

CGVR Graphics Korea University cgvr.korea.ac.kr 47 RSQ beforeafter RSQ Example: RSQR1.x, R5.x; x y z w R R1 0.0 x y z w R R

CGVR Graphics Korea University cgvr.korea.ac.kr 48 SLT SLT: Set On Less Than Function: Performs a component-wise assignment of either 1.0 or is assigned if the value of the first source is less than the value of the second. Otherwise, 0.0 is assigned. Syntax: SLTdest, src0, src1;

CGVR Graphics Korea University cgvr.korea.ac.kr 49 SLT beforeafter SLT Example: SLTR1, R2, R3; x y z w R R R1 0.0 x y z w R R R

CGVR Graphics Korea University cgvr.korea.ac.kr 50 LIT LIT: Light Coefficients Function: Computes ambient, diffuse, and specular lighting coefficients from a diffuse dot product, a specular dot product, and a specular power. Assumes: src0.x = diffuse dot product(N L) src0.y = specular dot product(N H) src0.w = power(m)

CGVR Graphics Korea University cgvr.korea.ac.kr 51 LIT LIT: Light Coefficients Syntax: LITdest, src0 Result: dest.x = 1.0 (ambient coeff.) dest.y = CLAMP(src0.x, 0, 1) = CLAMP(N L, 0, 1) (diffuse coeff.) dest.z = (see next slide…) (specular coeff.) dest.w = 1.0

CGVR Graphics Korea University cgvr.korea.ac.kr 52 LIT LIT: Light Coefficients Result: (Recall: src0.x  N L) if ( src0.x > 0.0 ) dest.z = (MAX(src0.y,0)) (ECLAMP(src0.w,-128,128)) = (MAX(N H,0)) m where m in (-128,128) otherwise, dest.z = 0.0 (dest.z is specular coeff. as defined by OpenGL)

CGVR Graphics Korea University cgvr.korea.ac.kr 53 LIT beforeafter LIT Example: LITR1, R7; x y z w R R1 0.0 R x y z w R (ambient) (diffuse) (specular) (Good to 8+ bits)