1© 2007 cgrl presentation title first and last name presenters title demos and real-time computer...

37
1 © 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research Lab

Upload: jayson-curtis

Post on 13-Jan-2016

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

1© 2007 CGRL

Presentation Title

First and Last NamePresenters Title

Demos and Real-time Computer GraphicsNg Chu MingAlumni, Computer Graphics Research Lab

Page 2: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

2© 2007 CGRL

Overview of Talk

Introduction to Demos Origins of the Demoscene Demoparties Classic works Different type of demos Tricks and Techniques Conclusion

Page 3: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

3© 2007 CGRL

Introduction to DemosceneDemos : What are they?

Not Commercial or Game Demos! Demos are…

“the last bastion of passionate, crazed, enthusiast-only programming, crafted purely for the hell of it by inspired teenagers working entirely in their spare time. The teens create jaw-dropping audiovisual effects beyond the dreams of most multimedia designers. “ – Wired Magazine

New digital artform Demos are a fusion of…

Art Music Design Great Coding

Page 4: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

© 2006 Autodesk

What are Demos?...

Lets see…..

Page 5: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

5© 2007 CGRL

Page 6: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

6© 2007 CGRL

Origins of the DemosceneDemos : How it all started…

Started in early 1980s due to software crackers

Cracker signature Originated from ‘crack screens’…

From text… To splash screens… 2D animation… … finally 3D animated effects and

music Eventually, many cracker groups started to

release intro-like programs separately

Page 7: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

7© 2007 CGRL

Origins of the DemosceneDemos : Today, in the state of the art…

3D realtime ray tracing Procedural Textures Multiple Effects and transitions Executable compression Design and storyboarding

Page 8: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

8© 2007 CGRL

Demo PartiesDemos : the now worldwide phenomenon…

Assembly ’06 (Helsinki, Finland) Mother of all demo parties The very first and longest

running for 15 years Sponsored by big names like

EA, Microsoft, AMDCreative, ATI, Nokia, ASUS

Now a worldwide phenomenen

A Demoparty in almost every continent/country The Party (Denmark), Breakpoint (Germany), The

Gathering (Norway)… 33 demo competitions over 23 Countries… Even Singapore had one, The Scene in 1996

Page 9: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

© 2006 Autodesk

Demo Show case:

Classic and defining works …in DemoScene history.

Page 10: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

10© 2007 CGRL

Classic and Defining works 2nd Reality by Future Crew

Produced and presented at Assembly 1993 But… What is it like in 1993?

386 PCs running DOS 16bit. 64k limit. NO OpenGL/Direct3D etc!

Page 11: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

11© 2007 CGRL

Classic and Defining works 2nd Reality by Future Crew

Till today, it is still considered the greatest demo ever produced

Listed by Slashdot.org as Top 10 hacks of all time, alongside Mars Pathfinder Ken Thompson's "cc hack“ Perl The Apollo 13 Mission Rescue

2nd Reality facts Coded in FULL Assembly language Dolby Surround And group members were just 18-20 years old!

Page 12: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

© 2006 Autodesk

2nd Reality.

Play DVD here

Page 13: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

© 2006 Autodesk

Types of Demos…

4kb, 64kb, Full fledged demos…

Page 14: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

14© 2007 CGRL

Types of Demos 4 Kilobyte Intros Yes, 4096 bytes. Equivalent to…

512 chars of text… What it means…

No APIs to call Code _EVERYTHING_ yourself,

down to the last plotpixel

Alright… Just how small is 4Kb!?

Page 15: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

15© 2007 CGRL

Types of Demos 4 Kilobyte Intros Okay… Lets take a look at…

Page 16: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

16© 2007 CGRL

Types of Demos 4 Kilobyte Intros Yes, 4096 bytes. Equivalent to…

512 chars of text…

Alright… Just how small is 4Kb!?

Ok… Fine. So, What can you do in 4Kb?

Page 17: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

17© 2007 CGRL

Types of Demos 64 Kilobyte Intros What can be done in 64Kb?

Well, this is what all of us do.....

Page 18: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

18© 2007 CGRL

Types of Demos 64 Kilobyte Intros What can be done in 64Kb? But you can really have,

Procedural geometry Music Textures And even realtime raytracing with adaptive subsampling…

Page 19: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

19© 2007 CGRL

Types of Demos Full fledged demo (> 1MB in size) Well, anything goes here. Lets check out one of the winning entries in Assembly 2006

Page 20: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

20© 2007 CGRL

Types of Demos Other weird, strange, crazy, but cool stuff. 256 bytes competition

Raytracer in 256 bytes

Text Mode demo competition Textmode? You must be kidding me…

Hugi Size Coding competition How small can nibbles get?

Ans : 48 bytes!

Page 21: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

© 2006 Autodesk

Tricks and Techniques

Assembly…

fixed point math…

speed hacks…

taylor series approximations

Page 22: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

22© 2007 CGRL

Tricks and Techniques Size optimization… Assembly language

There’s no running from it Know the instruction set sizes Be aware of processor arch.

3 Levels in which the size problem is approached Algorithmic tweaks Compiler tweaks OS tweaks

Page 23: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

23© 2007 CGRL

Tricks and Techniques Size optimization : Algorithmics… Basically, think of ways to generate things on the fly Procedural textures, procedural music, code, etc…

Simple example : The texture on the right is 256x256, with 0-255 in colour

[grey scale]. Even as a .jpg [with compression] it takes a total of 6KB

to store. This is larger than many intro’s! An un-optimized procedural algo:

for(y=0;y < 256;y++)

for(x=0;x < 256; x++)

height_value=(1-(sqrt(((x-128)*(x-128))+((y-128)*(y-128)))/128))*255;

Note – even without code size optimizations, its <200 bytes in a basic C compiler – a 15 times improvement!

This is only a small example – you need to think algorithmically about, textures, geometry, music, and code!

Page 24: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

24© 2007 CGRL

Tricks and Techniques Size optimization : Compiler tools Going one level down to language tools and selection The principle is…

Don’t take what’s thrown to you out of the box Assembly

Offers the most flexibility and options to push limits Use of features in ways they weren’t first designed (more on that

later) C++

Know everything about your compiler Linker options, pragmas, etc…

Page 25: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

25© 2007 CGRL

Tricks and Techniques Size optimization : Compiler tools C++ example

#include <windows.h>

__stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)

{MessageBox(0,“Silly example",“test!",MB_OK); return 0;

}

This example, when compiled with “default” VC++ options results in a 24 KB EXE!

Page 26: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

26© 2007 CGRL

Tricks and Techniques Size optimization : Compiler tools Lets tweak it! The same program, altered just a little bit….

#pragma comment(linker,"/ENTRY:main")#pragma comment(linker,"/MERGE:.rdata=.data")#pragma comment(linker,"/MERGE:.text=.data")#pragma comment(linker,"/IGNORE:4078")#pragma comment(linker,"/OPT:NOWIN98")

#include <windows.h>

void main(){MessageBox(0,"test","test",MB_OK);}

Becomes 1KB in size!

Page 27: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

27© 2007 CGRL

Tricks and Techniques Size optimization : Compiler tools Err… So what the hell did you do? Cut out the “fluff” that the compiler includes by default:

Microsoft Visual C++ Runtime Library 4kb section alignment [not required] Merged sections in the exe:

.text (default code section),

.rdata (default read-only data section)

.data (initial data section)

Page 28: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

28© 2007 CGRL

Tricks and Techniques Size optimization : OS Tweaks… Going another level deeper… OS limitations!

This deals with OS limitations, or what a “executable” file is on that Operating system

Win32 programs have a lot of extra “fluff” in them, that you don’t need Now…. MS-DOS had a light program. It supports 2 types of programs:

.COM files - limited to 64kb, but no headers!.EXE files - for large exe

Coders started using executable packers. Basically, compressing the exes

Still not enough! Pack Exe files in COM files Pack .CAB files A lot of details here… (Omitted)

Page 29: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

29© 2007 CGRL

Tricks and Techniques Optimizing for speed : Processor level… Again a wide spectrum art How optimized your code is influence what you can put on your screen. Knowledge of processor instruction sets and arch. Eg,

Use of lea instruction to do muls faster xor eax, eax is faster than mov eax, 0 Address generation interlocks (AGI)

It takes one clock cycle to calculate the address needed by an instruction which accesses memoryBut if the address depends on result of an instruction in the

preceding clock cycle, you have to wait an extra clock cycle => AGI Eg.

ADD EBX,4 MOV EAX,[EBX] ; AGI pipeline stall

Solution? Interleave instructions in between…ADD EBX,4 XOR ECX, ECXMOV EAX,[EBX] ; No AGI stall

Page 30: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

30© 2007 CGRL

Tricks and Techniques Optimizing for speed : Algorithms…

Going one level up… Algorithms. Numerical methods

Better algorithms to approximate calculations Clever hacks

From the very simple, Avoid multiplications/divisions Use look up tables

To the more involved… Using Taylor series to approx sqrt() John Carmack’s famous Inverse Sqrt hack

Page 31: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

31© 2007 CGRL

Tricks and Techniques Optimizing for speed : Effect Hacks Find more clever ways to suspend your disbelief! Simple Example… Simulating Fire!

Wow!… physically based simulation! But…. It takes FOREVER!

Page 32: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

32© 2007 CGRL

Tricks and Techniques Optimizing for speed : Effects Hacks Take a look at this demo Nice, simple and Realtime! And it was already possible 10 years ago! How it was done…

Use Indexed Color Mode Set up a nice palette

Plot new pixels and just smooth the image Evolve image using flow field

Page 33: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

33© 2007 CGRL

Tricks and Techniques Optimizing for speed : Effects Hacks Take Heaven Seven by Exceed Nobody thought realtime raytracing is possible in the year

2000 But they made it possible with adaptive subsampling

And use heavily hand optimized assembly

Page 34: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

34© 2007 CGRL

Conclusion What the scene has to offer…

For educators/academics : Undergrads in today's Universities mostly don’t know the demo

scene exists The scene is an environment to foster students CG knowledge thru

competition Demo making is a good avenue to learn broad spectrum CS

techniques For example, creating a 64KB intro requires,

Cramming all code, models, textures, sound and all other data in a total of 64KB This combines skills of, real-time performance, compression programming and content

generation For Commercial/Development :

Demo competitions are excellent place to recruit Many game industry ppl used to be sceners

Page 35: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

35© 2007 CGRL

Presentation Title

First and Last NamePresenters Title

Thank you

Page 36: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

36© 2007 CGRL

Tricks and Techniques Optimizing for speed : Algorithms…

Going one level up… Algorithms. Numerical methods

Better algorithms to approximate calculations Clever hacks

From the very simple, Avoid multiplications/divisions

Use shift and add, eg in framebuffer look up.Since framebuffers are contiguous block of memory,

pixel(x, y)=fb[y * x_res + x] // say x_res = 800 x 600Use shift and add!

pixel(x, y)=fb[y << 9 + y << 8 + y << 5 + x]Even better… Lookup tables => pixel(x, y)=fb[ytable[y]+ x]

To the more involved… Using Taylor series to approx sqrt(), John Carmack’s famous Inverse

Sqrt hack

Page 37: 1© 2007 CGRL Presentation Title First and Last Name Presenters Title Demos and Real-time Computer Graphics Ng Chu Ming Alumni, Computer Graphics Research

37© 2007 CGRL

Tricks and Techniques Speed hacks… Fixed point math Use Approximations! Don’t Calculate what you don’t need to!

Use look up tables!