Top Banner
DirectX 8 and GeForce3 Christian Schär & Sacha Saxer
32

DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Dec 14, 2015

Download

Documents

Annette Sydney
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

DirectX 8 and GeForce3

Christian Schär & Sacha Saxer

Page 2: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Overview

• DirectX

• Direct3D 8

Vertex Shader

Pixel Shader

Hardware Support

• Conclusions

• Future

Page 3: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

DirectX Components

• DirectDraw

• Direct3D

• DirectSound

• DirectMusic

• DirectShow

• DirectInput

• DirectPlay

2D Graphics API

3D Graphics API

Sound API

Music API

Multimedia Streams API

Input API

Network API

Page 4: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Direct3D

• Hardware Abstraction Layer

• Classic Rendering Pipeline

• Vertex Shader

• Pixel Shader

• D3DX

Page 5: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Hardware Abstraction Layer

Page 6: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Classic Rendering Pipeline

CreateVertexBuffer();

SetVertexShader();

SetStreamSource();

DrawPrimitive();

Page 7: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader

• Small assembly language program

• Replaces the Transformation and Lighting Engine

• Responsible for World and View transformations

• Is executed once per vertex

• Has no neighborhood information

• Prepares data for the Pixel Shader

Page 8: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Modified Rendering Pipeline

Page 9: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader Architecture16 Input registers (r/o)

96 Constant registers (r/o)

12 Temp registers (r/w)

1 Address register (w/o)

Output registers

Max. 128 instructions

Page 10: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader Assembly

Input:vn

Vertex

c[n]Constants

anAddress

rn• Temp

Output:oPos

PositionoTn

TextureoDn

ColoroFog/oPts

Page 11: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader Instructions

mov r, s0 add r, s0, s1 sub r, s0, s1 mul r, s0, s1 mad r, s0, s1, s2 rcp r, s0.w rsq r, s0.w

; copy

; sum

; difference

; multiply

; multiply-add

; reciprocal

; reciprocal sqrt

Page 12: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader Instructions

dp3 r, s0, s1 dp4 r, s0, s1 min r, s0, s1 max r, s0, s1 slt r, s0, s1 sge r, s0, s1

; 3D dot product

; 4D dot product

; per component

; per component

; 1.0 if less than

; 1.0 if greater/equal

Page 13: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Vertex Shader Instructions

expp r, s0.w logp r, s0.w lit r, s0, s1 dst r, s0, s1

; partial prec.

; partial prec.

; lighting fn

; distance fn

Page 14: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Register modifier

Component Modifier r.{x} {y} {z} {w} r.[xyzw][xyzw][xyzw][xyzw] -r

DescriptionDestination mask

Source swizzle

Source negation

Page 15: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Sample Vertex Shader

vs.1.1m4x4 r0, v0, c[CV_WORLD_0]m4x4 oPos, r0, c[CV_VIEWPROJ_0]m3x3 r1, v3, c[CV_WORLD_0]

dp3 r1.x, r1, c[CV_LIGHT]max r1.1, r1.x, c[CV_ZERO].xmul r1, r1.x, c[CV_DIFUSE]add r1, r1, c[CV_AMBIENT]min r1, r1, c{CV_ONE].x

mov oD0.x, r1.xmov oD0.y, r1.xmov oD0.z, r1.x

Page 16: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Pixel Shader

• Small assembly language program

• Replaces the Texturing and Lighting Engine

• Is executed once per pixel

• Has no neighborhood information

• Does further calculations on the Vertex Shader’s output

• The output is the color of the pixel

Page 17: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Modified Rendering Pipeline

Page 18: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Pixel Shader Architecture

TexAddrOp 0

TexAddrOp 1

TexAddrOp 2

TexAddrOp 3

TriangleRasterizer

8 Texture BlendOps

Specular / FogComputed

Alpha Blending

Dx8 Pixel Shaders

Page 19: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Pixel Shader Assembly

Input:vn

Vertex color

tnTexture

cnConstants

Output:rn

Temp r0

Output color

Page 20: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Pixel Shader Instructions

mov r, s0 add r, s0, s1 sub r, s0, s1 mul r, s0, s1 mad r, s0, s1, s2

; copy

; sum

; difference

; multiply

; multiply-add

Page 21: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Pixel Shader Instructions

dp3 r, s0, s1 lrp r, s0, s1, s2 cnd r, r0.a, s1, s2

sub r0, v0, v1_biascnd r0, r0.a, c0, c1

; 3D dot product

; lin. interp. blend

; r= r0.a>0.5 ? s1 : s2

; r= v0 > v1 ? c0 : c1

Page 22: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Texture Instructions

tex t texbem t texbeml t, s texcoord t texkill t texm3x2pad t, s texm3x2tex t, s texm3x3pad t, s texm3x3tex t, s texm3x3spec t, s0, s1 texm3x3vspec t, s texreg2ar t, s texreg2gb t, s

; normal sample; bumped env. mapping; … with Luminance; sample tex. coords.; black, if coords < 0; Matrix multiplications;;; ; … +refl. +env. map.;; use s.ar as coords.; use s.gb as coords.

Page 23: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Sample Texture Instructions

tex t

texm3x2pad t0, s texm3x2tex t1, s

tex t0 texm3x3pad t1, t0 texm3x3pad t2, t0 texm3x3spec t3, t0, c0

mov r0, t3

; put texture col. into t

; 3x2 matrix multiplication

; get normal vector from t0; eye-ray vector from c0; cube env. texture from t3; do env. mapping

; output color

Page 24: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Modifiers

Component Modifier r.{a} {rgb} 1-r -r r_bias r_bx2

DescriptionSource/Destination mask

Invert

Negate

-0.5

-0.5, *2

Page 25: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Modifiers

Instruction Modifier _x2 _x4 _d2 _sat

Descriptionmultiply result by 2

multiply result by 4

divide result by 2

cramp result

Page 26: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Sample Pixel Shader

ps.1.1

tex t1

mov r0, t1 ; use texture color

mov r0.a, v0 ; get diffuse lighting from

; vertex interpolation

Page 27: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

D3DX Mesh Optimizing

• adjacency required

• sort by attribute

• compact

• progressive meshes

Page 28: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

D3DX Progressive Meshes

• different levels of detail (LOD)• half edge collapse• cloning by sharing of vertex buffers• streamable• save method

• OptimizeBaseLOD• TrimByVertices/TrimByFaces

Page 29: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

D3DX Skinned Meshes

• vertex data, bone data with vertex indices• support for .X files• export filters for Maya, 3D Studio Max available• up to 4 indices per vertex• up to 12 indices per face• up to 256 bone palettes• ConvertToBlendedMesh() reduces to this constraints• ConvertToIndexBlendedMesh() same, but less subsets• Uses GeForce’s restricted skinning support by rendering a

prefix in hardware.

Page 30: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

Conclusions

• very flexible tool

• hardware accelerated

• low level interface (assembly)

• vertex shaders theoretically applicable to point-sampled geometry

• rendering of shadows needs lots of work

Page 31: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

What’s next?

• subdivision surfaces in hardware(TruForm technology by ATI)

• displacement maps

Page 32: DirectX 8 and GeForce3 Christian Schär & Sacha Saxer.

References

• MSDN (Microsoft Developer Network)

• NVIDIA Whitepapers– Introduction to Vertex Shaders– Introdction to Pixel Shaders

http://msdn.microsoft.com/directx

http://partners.nvidia.com/Developer