preparing sushi - amd

48
Preparing Sushi - ATI Research, Inc. EGDC 2001 1 1 Alex Vlachos Alex Vlachos AVlachos AVlachos @ @ ati ati .com .com EGDC 2001 EGDC 2001 Preparing Preparing Sushi Sushi How Hardware Guys Write How Hardware Guys Write a 3D Graphics Engine a 3D Graphics Engine

Upload: others

Post on 26-May-2022

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 11

Alex VlachosAlex VlachosAVlachosAVlachos@@atiati.com.com

EGDC 2001EGDC 2001

Preparing Preparing SushiSushiHow Hardware Guys WriteHow Hardware Guys Write

a 3D Graphics Enginea 3D Graphics Engine

Page 2: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 22

OutlineOutline• What is Sushi?

• Island Demo• Scene Graph• Vertex Storage• Rendering Pipeline• Shader Library• Shadow Volumes• Object Engine

• LifeFX Rachel Demo• Extras• Waterfall Demo

• Water Effects• Future Enhancements

Page 3: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 33

What is Sushi?What is Sushi?• It’s not just a tasty treat…• Project name for ATI’s demo

engine used for the Radeon 8500 demo suite.

• The engine was designed with future rendering technologies in mind.

• Will be used for future ATI product demos.

Page 4: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 44

RADEON 8500 Island DemoRADEON 8500 Island Demo

Page 5: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 55

RADEON 8500 Island DemoRADEON 8500 Island Demo

Page 6: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 66

RADEON 8500 Island DemoRADEON 8500 Island Demo

Page 7: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 77

RADEON 8500 Island DemoRADEON 8500 Island Demo

Page 8: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 88

Sushi Engine GoalsSushi Engine Goals

• Shader Driven• Cross API (DirectX & OpenGL)• Cross Platform (Windows &

Mac)• Future-looking For Several

Product Cycles

Page 9: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 99

Engine HierarchyEngine Hierarchy

Engine

WinD3D

Object

Shader Lib

D3D OGLWinOGL MacOGL

Asset Management

Page 10: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1010

Scene GraphScene Graph• Octree – Serves our goals• Our previous engine (Radeon’s Ark)

used a portal-based visibility algorithm, but that’s over engineered for graphics demos.

• Octree provides enough culling opportunities for our purposes.

Page 11: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1111

Octree DivisionsOctree DivisionsOctree Divisions

Page 12: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1212

Vertex Buffer SizeVertex Buffer Size• Don’t use a single 150MB VB!!!• These days, we assume 64MB AGP

aperture for end-users…so 150MB isn’t going to fit anywhere but system memory!

• Sushi VB’s are kept to a reasonable size (2MB). Since our shaders are so varied, so are our stream mappings, making it difficult to break the 2MB barrier.

Page 13: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1313

Optimize For State ChangeOptimize For State Change• Shared VB’s independent of which

octree leaves the polygon lives in.• Sort by shader change first, then

texture change• For most cases, this sorting works

fine, but there are extreme cases where you may want the opposite. Schedule time for experimentation.

Page 14: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1414

Vertex StorageVertex Storage

VBIB

StreamMapping

MetaBins BinsOctreeLeaves

VBIB

StreamMapping

VBIB

StreamMapping

VBIB

StreamMapping

. . .

MetaBin IDShader ID

Texture IDsMetaBin IDShader ID

Texture IDsMetaBin IDShader ID

Texture IDsMetaBin IDShader ID

Texture IDsMetaBin IDShader ID

Texture IDsMetaBin IDShader ID

Texture IDs

MetaBin IDShader ID

Texture IDs

. . .

Bin IDIB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB End

Bin IDIB StartIB EndBin ID

IB StartIB EndBin ID

IB StartIB End

. . .Within each leaf, render calls are sorted by shader state and then by texture handles

Page 15: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1515

RunRun--Time LightsTime Lights• Run-time lights are additional passes

at run-time over geometry in the light’s frustum

• Cast correct shadows using shadow volumes (later slides)

• Pulse or blink independently and adds/subtracts the correct light contribution

Page 16: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1616

Rendering PipelineRendering Pipeline• Clear Z Buffer & Stencil Buffer• Draw “ambient” geometry (+ZWrites,

+ZTest, -StencilWrites, -StencilTest)• For Each Run-Time Light

• Clear relevant area of stencil buffer, if needed!• Draw shadow volumes into stencil buffer

(-ZWrites, +ZTest, +StencilWrites, -StencilTest)• Draw geometry in light frustum and receive

shadows (-ZWrites, +ZTest, -StencilWrites, +StencilTest)

• Swap Buffers

Page 17: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1717

NonNon--Opaque PolygonsOpaque Polygons• Becomes very difficult with run-time

lights• Tradeoffs lend to giving up some

correctness in rare cases.• Order of drawing lights is very

important! Simple far to near needs to be defined in more detail…

Page 18: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1818

NonNon--Opaque Draw Opaque Draw Order Based on LightsOrder Based on Lights

Page 19: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 1919

Shader LibraryShader Library• Abstracts ALL fixed function and

programmable vertex and pixel processing to editable text files!

• Multi-pass shaders• Shader fallbacks for different levels

of hardware support• Provides a shader LOD mechanism

Page 20: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2020

Fixed Function ShaderFixed Function ShaderDefineParam texture tex0 NULL

DefineParam vector4 red ( 0.7, 0.0, 0.0, 0.0 )

StartShader

StartPass

SetRenderState TEXTUREFACTOR red

SetTexture 0 tex0

SetColorOp 0 SELECTARG1 TFACTOR

SetAlphaOp 0 SELECTARG1 TFACTOR

EndPass

EndShader

Page 21: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2121

Programmable ShaderProgrammable ShaderStartVertexShader

vs.1.1

m4x4 oPos, v0, c4

mov oT0, v7

//Vertex in normalized light space

sub r0, v0, c3 //V-L

mul oT1, r0, c1.y //V-L/falloff

//Normalized light vector

sub r0, c3, v0

dp3 r0.w, r0, r0

rsq r0.w, r0.w

mul r0, r0, r0.w

dp3 oD0, r0, v3 //Goraud N.L

EndVertexShader

SetPixelShaderConstant 0 appConst

StartPixelShader

ps.1.4

texcrd r1.rgb, t1 //Vertex in norm light space

dp3 r1, r1, r1 //distance squared from light

phase

texld r0, t0 //Base

texld r1, r1 //Light attenuation

mul r0, r0, r1_x2 //Base*light

mul r0, r0, v0 // " * N.L

mul r0, r0, c0.b // " * pulseScalar

EndPixelShader

EndPass

EndShader

StartShader

Requirement VERTEXSHADERVERSION 1.1

Requirement PIXELSHADERVERSION 1.4

LightType LIGHTTYPE_POINT

StartPass

SetRenderState ZWRITEENABLE FALSE

SetRenderState ALPHABLENDENABLE TRUE

SetRenderState SRCBLEND ONE

SetRenderState DESTBLEND ONE

SetTexture 0 tex0

SetTextureStageState 0 MIPFILTER FILTER_LINEAR

SetTexture 1 lightMap

SetTextureStageState 1 MIPFILTER FILTER_NONE

SetTextureWrap 1 CLAMP CLAMP CLAMP

//SetVertexShaderConstant 0 commonConst

SetVertexShaderConstant 1 appConst

//SetVertexShaderConstant 2 worldSpaceCamPos

SetVertexShaderConstant 3 worldSpaceLightPos

SetVertexShaderConstant 4 wvp

Page 22: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2222

Shadow VolumesShadow Volumes• Dynamic vs. Static

• Static volumes are used when you have non-moving lights and non-moving geometry.

• Dynamic volumes are used if you have either a moving light or animated geometry.

Page 23: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2323

Dynamic Shadow VolumesDynamic Shadow Volumes

Shadow VolumeVisualization

Page 24: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2424

Dynamic Shadow Dynamic Shadow VolumesVolumes

• In Sushi, only animated objects & characters have dynamic volumes.

• Are computed entirely in a vertex shader, so the CPU never touches these vertices! Removes any AGP performance issues.

Page 25: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2525

Shadow VolumeShadow Volume

Sphere Sphere’sShadowVolume

Page 26: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2626

Shadow Volume Shadow Volume Extrusion SetupExtrusion Setup

A

B

A

B

Face NormalsFor Polygon A

Face NormalsFor Polygon B

Infinitely ThinFill Polygons

Original borderingpolygons .

We insert 2 degenerate polygons betweenthe original polygons which share theappropriate face normal encoded in thevertex.

Page 27: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2727

Static Shadow VolumesStatic Shadow Volumes

Page 28: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2828

Static Shadow VolumesStatic Shadow Volumes

• Shadows cast by non-moving light sources

• Scene geometry that doesn’t move• Terrain, rocks, buildings, etc.

• Great opportunity to optimize out the brute-force nature of dynamic shadow volumes!

Page 29: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 2929

Shadow Beam AlgorithmShadow Beam Algorithm

Beam Polygon 1Beam Polygon 2 Beam Polygon 3

Below is an example of applying this beam algorithm to thefirst 3 polygons of a given volume.

Page 30: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3030

Shadow Beam AlgorithmShadow Beam Algorithm1. Begin with an empty final table.2. Roughly sort all polygons back to front based on some simple test

(QSort will suffice)3. For each polygon in the rough back to front order:

A. Create a beam from each polygon (4 clip planes), clipping away all polygons inside beam that have already been added to final table. A beam consists of 3 copy planes generated from the light source and each edge of the polygon, and the 4th clip plane is the polygon’s plane equation.

B. If polygons are left in front of beam polygon, recurse only 1 deep for each polygon left in front of the original beam polygon adding polygons to final table. Else, add beam polygon to the final table.

C. Optimize mesh in final table to remove redundant tessellation caused by beam planes.

4. Solve for T-Junctions (from the light’s point of view) in final table.

This algorithm does not lend itself to infinite recursion like the Weiler-Atherton algorithm!

Page 31: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3131

Shadow Beam AlgorithmShadow Beam AlgorithmRecursion StepRecursion Step

Beam Polygon

Beam Frustum

Existing Polygon

RecursiveBeam Frustum

Remaining PolygonsOriginal Beam Recursive Beam

Page 32: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3232

Shadow Beam AlgorithmShadow Beam AlgorithmThis solves for cyclically overlapping polygons!

(Now solve for T-Junctions!)

Page 33: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3333

Object EngineObject Engine• Remember, we’re not designing a game

engine!• Play back animation that consist of:

• Skinning• Tweening (morphing, key-frame)• Skinning & Tweening simultaneously!

• Types of objects:• Globally animated (walking creature)• Locally animated (swaying plant)• Static non-animated (rocks)

Page 34: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3434

RADEON 8500 Rachel DemoRADEON 8500 Rachel Demo

Page 35: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3535

RADEON 8500 Rachel DemoRADEON 8500 Rachel Demo

Page 36: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3636

ExtrasExtras

• Anamorphic• Spherical screen projection• High resolution screen shots• Fly through paths

Page 37: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3737

AnamorphicAnamorphic• Sushi has an anamorphic mode for plasma

and HDTV displays• 16:9 aspect ratio isn’t necessarily the pixel

aspect ratio for plasma screens!• As is done in celluloid, draw into a 3:4 render

target with the aspect of your projection matrix set to 16:9 (Kung Fu movies in the 80’s).

• The display stretches the image out to 16:9 with no black letterbox bars on the screen.

• Also be aware of odd aspect ratio display modes. Some notebooks and LCDs are shipping with 1280x768 display modes, for example.

Page 38: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3838

AnamorphicAnamorphic

3:4 Render Target

16:9 Plasma Display

Page 39: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 3939

Spherical Projection Spherical Projection ScreensScreens

Viewer

150°°°°

Top View

http://www.elumens.com

Page 40: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4040

Spherical Projection Spherical Projection ScreensScreens

• The visual simulation community has made immersive displays which are like small-scale Omnimax™ screens

• Relatively simple to add to an existing engine which already has renderable texture support

• Great demo opportunities!

Page 41: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4141

High Resolution Screen ShotsHigh Resolution Screen Shots• Hit one button in-engine and dump a

screenshot at higher resolution than the GPU can actually render

• Very useful for printed media which use at least 300 dots per inch (dpi)

• Magazines and printed media usually looks lower resolution than a monitor

• Recently published in Game Programming Gems 2

Page 42: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4242

High Resolution Screen ShotsHigh Resolution Screen Shots

Page 43: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4343

Fly Through PathsFly Through Paths

• Smooth quaternion-based fly through paths provide a very nice demo mode for flying through our scenes.

• Recently published in Game Programming Gems 2

Page 44: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4444

RADEON 8500 Waterfall DemoRADEON 8500 Waterfall Demo

Page 45: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4545

RADEON 8500 Waterfall DemoRADEON 8500 Waterfall DemoReflections Refractions

Page 46: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4646

Water EffectWater Effect• Uses 2 renderable textures: reflections & refractions• Geometry is drawn in screen space into the textures.• The water surface itself is rendered using 4 crossing

sin waves (for per-vertex waves) and 2 addative bump maps (for per-pixel perturbations). Both renderable textures are utilized by fetching with perturbed texture coordinates based on the bump maps.

• A Fresnel term is used to add realism.• Additional specular highlight are added for the sun.• The water is rendered in a single pass utilizing 1.1

vertex shaders and 1.4 pixel shaders.• This allows for objects to be partially in water.

Page 47: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4747

Future EnhancementsFuture Enhancements• Shader library

• Make this even more general• Embed stream mapping and data

mapping into shader file so a recompile is never needed when adding new shaders

• Collision Detection• DX9 Features…

Page 48: Preparing Sushi - AMD

Preparing Sushi - ATI Research, Inc. EGDC 2001 4848

QuestionsQuestionsOops. This hysterical outtake was captured from the Rachel demo when we first rendered this model in real-time. Half her polygons remained in object space accidentally… We soon corrected the problem and she now looks better: