Transcript slides
Demos and Real-time
Presentation
Title Computer
Graphics
First
andMing
Last Name
Ng Chu
Presenters
Title Graphics Research Lab
Alumni, Computer
© 2007 CGRL
1
Overview of Talk
Introduction to Demos
Origins of the Demoscene
Demoparties
Classic works
Different type of demos
Tricks and Techniques
Conclusion
© 2007 CGRL
2
Introduction to Demoscene
Demos : What are they?
Not Commercial or Game Demos!
Demos are…
“the last bastion of passionate, crazed, enthusiastonly 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
© 2007 CGRL
3
What are Demos?...
Lets see…..
© 2006 Autodesk
© 2007 CGRL
5
Origins of the Demoscene
Demos : 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
© 2007 CGRL
6
Origins of the Demoscene
Demos : Today, in the state of the art…
3D realtime ray tracing
Procedural Textures
Multiple Effects and transitions
Executable compression
Design and storyboarding
© 2007 CGRL
7
Demo Parties
Demos : 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, AMD
Creative, 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
© 2007 CGRL
8
Demo Show case:
Classic and defining works …
in DemoScene history.
© 2006 Autodesk
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!
© 2007 CGRL
10
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!
© 2007 CGRL
11
2nd Reality.
Play DVD here
© 2006 Autodesk
Types of Demos…
4kb, 64kb, Full fledged demos…
© 2006 Autodesk
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!?
© 2007 CGRL
14
Types of Demos
4 Kilobyte Intros
Okay… Lets take a look at…
© 2007 CGRL
15
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?
© 2007 CGRL
16
Types of Demos
64 Kilobyte Intros
What can be done in 64Kb?
© 2007 CGRL
Well, this is what all of us do.....
17
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…
© 2007 CGRL
18
Types of Demos
Full fledged demo (> 1MB in size)
Well, anything goes here.
Lets check out one of the winning entries in Assembly 2006
© 2007 CGRL
19
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?
© 2007 CGRL
Ans : 48 bytes!
20
Tricks and Techniques
Assembly…
fixed point math…
speed hacks…
taylor series approximations
© 2006 Autodesk
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
© 2007 CGRL
22
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))+((y128)*(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!
© 2007 CGRL
23
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…
© 2007 CGRL
24
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!
© 2007 CGRL
25
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!
© 2007 CGRL
26
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)
© 2007 CGRL
27
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,
.EXE files - for large exe
but no headers!
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)
© 2007 CGRL
28
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 memory
But 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, ECX
MOV EAX,[EBX] ; No AGI stall
© 2007 CGRL
29
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…
© 2007 CGRL
Using Taylor series to approx sqrt()
John Carmack’s famous Inverse Sqrt hack
30
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!
© 2007 CGRL
31
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
© 2007 CGRL
32
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
© 2007 CGRL
33
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
generation
For Commercial/Development :
Demo competitions are excellent place to recruit
Many game industry ppl used to be sceners
© 2007 CGRL
34
content
Presentation Title
Thank you
First and Last Name
Presenters Title
© 2007 CGRL
35
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 600
Use 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…
© 2007 CGRL
Using Taylor series to approx sqrt(), John Carmack’s famous Inverse
Sqrt hack
36
Tricks and Techniques
Speed hacks…
Fixed point math
Use Approximations!
Don’t Calculate what you don’t need to!
Use look up tables!
© 2007 CGRL
37