1© 2007 cgrl presentation title first and last name presenters title demos and real-time computer...
TRANSCRIPT
1© 2007 CGRL
Presentation Title
First and Last NamePresenters Title
Demos and Real-time Computer GraphicsNg Chu MingAlumni, Computer Graphics Research Lab
2© 2007 CGRL
Overview of Talk
Introduction to Demos Origins of the Demoscene Demoparties Classic works Different type of demos Tricks and Techniques Conclusion
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
© 2006 Autodesk
What are Demos?...
Lets see…..
5© 2007 CGRL
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
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
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
© 2006 Autodesk
Demo Show case:
Classic and defining works …in DemoScene history.
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!
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!
© 2006 Autodesk
2nd Reality.
Play DVD here
© 2006 Autodesk
Types of Demos…
4kb, 64kb, Full fledged demos…
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!?
15© 2007 CGRL
Types of Demos 4 Kilobyte Intros Okay… Lets take a look at…
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?
17© 2007 CGRL
Types of Demos 64 Kilobyte Intros What can be done in 64Kb?
Well, this is what all of us do.....
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…
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
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!
© 2006 Autodesk
Tricks and Techniques
Assembly…
fixed point math…
speed hacks…
taylor series approximations
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
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!
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…
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!
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!
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)
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)
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
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
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!
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
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
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
35© 2007 CGRL
Presentation Title
First and Last NamePresenters Title
Thank you
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
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!