matrices from hell

34
Matrices from HELL Paul Taylor 2010

Upload: miriam

Post on 12-Feb-2016

59 views

Category:

Documents


0 download

DESCRIPTION

Matrices from HELL . Paul Taylor 2010. Basic Required Matrices. PROJECTION WORLD VIEW. Matrix Math (Joy!). Matrix Addition Matrix Multiplication Translation and Rotation Matrices. Matrix Addition is Easy. =. +. =. +. Matrix Multiplication Row,Colum. =. x. =. x. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Matrices from HELL

Matrices from HELL Paul Taylor 2010

Page 2: Matrices from HELL

Basic Required Matrices

• PROJECTION• WORLD• VIEW

Page 3: Matrices from HELL

Matrix Math (Joy!)

• Matrix Addition• Matrix Multiplication• Translation and Rotation Matrices

Page 4: Matrices from HELL

Matrix Addition is Easy1 2 3

4 5 6

7 8 9

A B C

D E F

G H I+ =1+A 2+B 3+C

4+D 5+E 6+F

7+G 8+H 9+I

4 0 0

0 6 0

0 0 9

3 0 0

0 1 0

0 0 0+ =7 0 0

0 7 0

0 0 9

Page 5: Matrices from HELL

Matrix Multiplication Row,Colum1 2 3

4 5 6

7 8 9

A B C

D E F

G H Ix =1A + 2D + 3G

1B + 2E + 3H

1C + 2F + 3I

4A + 5D + 6G

4B + 5E + 6H

4C + 5F + 6I

7A + 8D + 9G

7B + 8E + 9H

7C + 8F + 9I

4 0 0

0 6 0

0 0 9

3 0 0

0 1 0

0 0 0x =12 0 0

0 6 0

0 0 0

Page 6: Matrices from HELL

That’s great, what do I need them for?

Translation Matrices• Coordinates from Object Coordinates to world

CoordinatesObject Translation World

Typically we use a Matrix Multiplication

100 0 0

0 20 0

0 0 -100+ =110 0 0

0 30 0

0 0 -100

10 0 0

0 10 0

0 0 0

Page 7: Matrices from HELL

Scaling

Scalar MatricesObject Scalar (1/10) World100 0 0

0 100 0

0 0 100

0.1 0.1 0.1

0.1 0.1 0.1

0.1 0.1 0.1x =10 0 0

0 10 0

0 0 10

Page 8: Matrices from HELL

Translation by Multiplication

• This is a computationally longer way to do a simple translation

1 0 0 x

0 1 0 y

0 0 1 z

0 0 0 1

x =1 0 0 x

0 1 0 y

0 0 1 z

0 0 0 1

1 0 0 10

0 1 0 5

0 0 1 10

0 0 0 1

Page 9: Matrices from HELL

Rotational Matrices

http://en.wikipedia.org/wiki/Rotation_matrix#Dimension_threeA Rotation around the unit vector u = (ux,uy,uz)

glRotatef(Theta,x,y,z);

Page 10: Matrices from HELL

Putting it all together

Typically you will want to:TranslateRotateScale

Matrix Multiplication is the inverse to the logical order!

So:Scale then Rotate, then Translate

Page 11: Matrices from HELL

Retrieving Matrices

• This is slow!• The Video Matrices are 4x4 hence:D3DMATRIX world;world= 0 4 8 C

1 5 9 D2 6 A E3 7 B F

0 1 2 3 4 5 6 7 8 9 A B C D E F

Page 12: Matrices from HELL

DirectX 10 Has your back!

Static float rotation;D3DMATRIX world;D3DMatrixIdentity(&world);rotation = 0.001f;D3DMatrixRotationY(*world, rotation);

This creates a matrix on the PC, not on the Video Card, that’s the next step

Page 13: Matrices from HELL

Update your Shader (Effect)Matrix World;

float4 VS( float4 Pos : POSITION ) : SV_POSITION{ Pos = mul( Pos, World);

return Pos;

}float4 PS( float4 Pos : SV_POSITION ) : SV_Target{ return float4( 1.0f, 1.0f, 0.0f, 1.0f ); // Yellow, with Alpha = 1}technique10 Render{ pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); }}

Page 14: Matrices from HELL

Putting you matrix on the GPU

Create a Pointer to the GPU Matrix:ID3D10EffectMatrixVariable worldMatrixPointer;

Fill the Pointer to the GPU Matrix:Effect->GetvariableByName(“World”)->AsMatrix();

Set the Matrix on the GPU:worldMatrixPointer->SetMatrix(world);

Page 15: Matrices from HELL

Parallel Rendering

Page 16: Matrices from HELL

Parallel Rendering (Rendering Farms)

• There are Three major Type Definitions– Sort-First– Sort-Middle– Sort-Last

• These are just the outlines, in reality things need to be customised based on technical limitations / requirements

Page 17: Matrices from HELL

Sort-MiddleApplication

Sort

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Display

DisplayDisplay

Display

Fragments(Pixel Shading)

Geometry(Vertex Shading)

Page 18: Matrices from HELL

Sort-Middle

• Pros– The number of Vertex Processors is independent of the

Number of Pixel Processors• Cons– Normal Maps may mess with Polygons on overlap areas– Correcting Aliasing between Display Tiles

(RenderMan??)– Requires specific hardware– Rendering may not be balanced between Display Tiles

Page 19: Matrices from HELL

Sort-LastApplication

Composite

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Display

Fragments(Pixel Shading)

Geometry(Vertex Shading)

Page 20: Matrices from HELL

Sort-Last

• Pros– Can be easily created from networked PCs

• Cons– Each Vertex Processor requires a Pixel Processor– Unsorted Geometry means each Pixel Processor must

carry a full-size frame buffer• Limited scalability

– Composing the image requires integrating X frame buffers considering X Z-Buffers

Page 21: Matrices from HELL

Sort-Last

• Compositing can be done more efficiently (memory requirements) utilising a binary tree approach– May lead to idle processors

• Another approach is a Binary Swap architecture– Large Data Bus usage

Page 22: Matrices from HELL

Sort-FirstApplication

Sort

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Geometry(Vertex Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Fragments(Pixel Shading)

Display

DisplayDisplay

Display

Fragments(Pixel Shading)

Geometry(Vertex Shading)

Page 23: Matrices from HELL

Sort-First• Pros

– Pixel Processors only need a tile of the display buffer– Can be created utilising PC hardware– Infinitely Scalable

• Cons– We are sorting Primitives BEFORE they are translated into projected

space!!!• This requires some overhead

– Polygons crossing tiles will be sent to both pipelines– An error backup could consider a bus to move incorrectly sorted polygons to the

correct render queue (Transparency causes issues here!)

– Correcting Aliasing between Display Tiles– Rendering may not be balanced between Display Tiles

Page 24: Matrices from HELL

Parallel Processing Techniques

• Conclusively– Sort-Middle is for expensive hardware– Sort-Last is limited by scalability– Sort-First requires careful consideration on

implementation• Sort First / Sort Last COULD be run on a Cloud– Bandwidth??– Security??– What happens when you max the cloud??

Page 25: Matrices from HELL

Image Based Rendering

• Geometric Upscaling!• The process of getting 3D information out of

2D image(s)– Far outside our scope, but interesting in Research

Page 26: Matrices from HELL

RenderManhttps://renderman.pixar.com/

Page 27: Matrices from HELL

RenderMan / Reyes

• Reyes (Renders Everything You Ever Saw)• RenderMan is an implementation of Reyes– Reyes was developed by two staff at the

‘Lucasfilm's Computer Graphics Research Group’ now known as Pixar!

– RenderMan is Pixar’s current implementation of the Reyes Architecture

Page 28: Matrices from HELL

The Goals of Reyes

• Model Complexity / Diversity• Shading Complexity• Minimal Ray Tracing• Speed• Image Quality (Artefacts are Unacceptable)• Flexibility– Reyes was designed so that new technology could be

incorporated without an entire re-implementation

Page 29: Matrices from HELL

The Functionality of Reyes / RenderMan

• Objects (Polygons and Curves) are divided into Micro Polygons as needed– A Micro Polygon is a typically smaller than a pixel– In Reyes Micro Polygons are quadrilaterals– Flat shading all the Quads gives an excellent

representation of shading• These quads allow Reyes to use a Vector Based

Rendering Approach– This allows simple Parallelism

Page 30: Matrices from HELL

• Bound– Bounding Boxes

• Split– Geometry Culling & Partials

• Dice– Polygons into grids of Micro Polygons

• Shade– Shading Functions are applied to the Micro Polygons

• Functions used are Independent of Reyes

• Bust– Do Bounding and Visibility checking on each Micro Polygon

• Sample (Hide)– Generate the Render based on the remaining Micro Polygons

Page 31: Matrices from HELL

The Reyes

Pipeline

• http://en.wikipedia.org/wiki/File:Reyes-pipeline.gif

Page 32: Matrices from HELL

Interesting Facts

• Some Frames take 90 hours!!! (1/24th of a second of footage)

• On average Frames take 6 hours to render!!!!• 6 * 24 = 1 second = 144 Hours– About 2 years for a 2 hour Movie!!

Page 33: Matrices from HELL

Licensing

• $3500 us per Server• $2000us – 3500us per Client Machine• Far cheaper than expected, until you build

your cluster....

Page 34: Matrices from HELL

References

http://en.wikipedia.org/wiki/Reyes_renderinghttp://en.wikipedia.org/wiki/Rendering_equationhttp://www.steckles.com/reyes1.html