|
|
Archive for 2007
The other day at work I needed a command line tool to compare some images (whether they mostly match, used in unit/functional tests). For unknown reason I could not get ImageMagick’s compare to work like I wanted, so I just wrote my own.
I used stb_image library from Sean Barrett - and it just rocks! Here’s the code to load a PNG image from file:
int width, height, bpp;
unsigned char* rgb = stbi_load( "myimage.png", &width, &height, &bpp, 3 );
// rgb is now three bytes per pixel, width*height size. Or NULL if load failed.
// Do something with it...
stbi_image_free( rgb );
That’s it! Basically a single line to load the image (and of course the library has similar functions to load from a block of memory, etc.). And the whole “library” is a single file - just add to your project and there it is. In comparison, loading a PNG file using de-facto libpng takes more than 100 lines of code (and some time to read the docs).
Small is beautiful.
…and the way we do graphics related unit/functional/compatibility testing deserves a separate article. Sometime in the future!
Posted on 2007-05-28 14:11 in code, work | No Comments »
Is it just me, or 4k intros really evolved by leaps and bounds in the last few years? I remember the time when 4k stuff was like “ok, that’s cool for a 4k” - but if it weren’t four kilobytes, nobody would watch it. Then in around 2004 came Yellow Rose of Texas, San Angeles Observation and Micropolis - and they were beautiful and interesting by themselves already. In case of Micropolis, it has a city and a big robot - who can resist that? The fact that they are in 4 kilobytes makes that even more interesting.
Fast forward to 2007. Of course every decent 4k intro has music now. Some do have separate scenes, with greets and stuff like “the real demos” (sprite-o-mat). Others have ambient occlusion and interesting lighting (Galiwm, kinderplomber). Some have raytracing in the pixel shaders (4kmdr). And so on.
Woo-hoo! I expect the 4k scene to bring some real jewels in the next couple of years.
Posted on 2007-05-19 19:56 in demos | 3 Comments »
I just have to blog this: shockwave.com just launched a Unity web game - MegaPixel. It’s a pure, abstract, and mega-fun FPS. It’s set up in a very small space (the levels are basically boxes with several smaller boxes inside), and it pretty much uses a single texture for the whole game, and it does not use much more than particle effects for everything (the levels, enemies, weapons and everything else is just particles). Pure genius.
I like it! That says a lot, because last time I played FPS was ages ago. Finally, someone made a game that I can like again. How much I’m biased because it’s made with Unity… decide for yourselves :)
Now the killer part: the game is designed and developed solely by a 15 year old - Forest “Yoggy” Johnson. How cool is that?
Enough talking, just go and play it. And remember that you didn’t see cool until you get to the robot level!
Posted on 2007-05-19 0:22 in games, unity | 6 Comments »
I’m always puzzled why people think that some interesting effect is “shaders”. The most recent example I saw is this message on Dir3d mailing list - it’s about NVIDIA’s skin rendering demo (*).
The most interesting effects are in fact not achieved by the use of shaders - rather it’s the complex interplay of render-to-textures, postprocessing them, using them somewhere else, postprocessing that, using them somewhere else again, combine the intermediate results in various interesting ways, and finally get something that represents the colors on the screen.
So the effect is much more than the shaders; it’s more like “an orchestration of different stuff”. It’s the shaders, textures, models (often with custom data that is required for the effect to work), specially precomputed textures (more custom data for the effect), multiple render textures to store intermediate results, and finally some sort of “script” that controls the whole process.
Shaders are (relatively) small, isolated thingies that operate on small, isolated pieces of data. So they are only a small part of the whole picture, and in fact often they are the easiest part. Both to the effect author, and even for the “engine” to support.
Adding “shader support” to the engine/toolset is a piece of cake. The hard parts are:
- How shaders integrate with the lighting? Once you start doing shaders, you lose all lighting that used to be computed for you.
- How shaders integrate with various data the mesh may have or it might not? For example, to support per-vertex colors you either have to write a single (sub-optimal) shader that always assumes vertex colors are present, or write multiple shaders: when vertex colors are present, and when they are not.
- How shaders integrate with … lots of other things that were taken for granted in fixed function world. Scaled meshes. Various fog types. Texture transforms. The list goes on.
- How do you expose the rest of the “stuff” that makes interesting effects possible? Shaders alone are nothing. You need render-to-texture with various interesting formats. You need to store custom data in the meshes. You need to store custom data in the textures, in various interesting formats. You need custom cameras to render intermediate results into render textures. You need a way to replace object shaders with some other shaders so that these objects can render these intermediate results. The list goes on.
- Hardware support. Once you enter shader world, you get a totally new set of inconsistencies between operating systems, graphics APIs, hardware vendors, graphics card models and driver versions. And a new bag of driver bugs of course.
So shaders do present three big challenges.
1) Shader explosion. How do you do lighting? Do you say “there shall only ever be a single directional light” (that is what most tech-demos do)? Do you try to support the general case and write some dozen shader combinations? How do you handle all other cases that were “just handled” by fixed function pipeline? Vertex formats, fog, texture transforms, etc. Congratulations, multiply your shader count by 10 or so. Or don’t multiply the shader count, but use static/dynamic branching if you have hardware support for it.
2) Platform differences. How you write shaders in the general case, when some things don’t work on AMD cards, some other things don’t work on NVIDIA cards, yet some other things don’t work in OpenGL, some other things don’t work in Direct3D, and something entirely else does not work on Mac OS X (with different things not working on PPC vs Intel, yay)? Congratulations again, multiply your already large shader count by 10 or so.
3) Shaders are just a small part of the equation. You need the whole infrastructure around them to actually enable those interesting effects.
To return to the original message about the skin rendering demo: no, “just shaders” won’t enable that. You need render textures in several formats (color & depth) at least. And some dozen shaders to do the effect for a single light type, for a single mesh configuration, and for a single hardware platform. Multiply the shader count by, hmm…, hundred or so to cover the general case.
Real life is harder than a tech demo. Real life is more than just the shaders.
(*) I’m taking the message out of the context on purpose. Nothing is wrong with noisecrime’s message, I just want to point out that just exposing shaders does not get you very far.
Posted on 2007-05-07 17:17 in rant | 9 Comments »
After a long period of silence nesnausk! releases another demo - Zenit. Check it out. This is actually almost a one-man show: the concept, modeling, animations and code was done by Paulius. I did see how the real camera looks like when fully disassembled into almost 500 parts - it’s scary!
Ah… makes me want to do some demo again. Maybe someday!
Posted on 2007-04-10 19:00 in demos | No Comments »
I have added a small article on transformation matrices - what the values in the matrix really mean. The values are coordinate system axes of course, so if you know that already, just skip it.
Posted on 2007-04-06 17:09 in papers | No Comments »
Ok, I got an USB memory stick (PQI something). Now it has two partitions on it by default, one of them to store some sort of “USB Notebook” data. I am pretty sure I really don’t need that, so I was looking around for a way to merge those partitions. I ran this “USB Notebook” application in a hope that setup wizard will let me choose “no thanks, I don’t need this stuff”. Of course, it does not have such an option.
Pressing Cancel somewhere in there results in this dialog:

Pretty cool, I must say. Some advice I’d like to give for the application developers, if I may:
- Instead of trying to copy Aqua’s GUI, make the application actually do useful things. “I don’t need your stuff, please give me a single partition” is a pretty common use case. And please don’t make error messages like that be the topmost windows (now it stays on top even when I switch to another app).
- Either get someone to write English messages, or leave the message as is and change the caption to “All your base are belong to us”. For such an exciting error message I’d also change the button text to “YES!!!”. Let the user enjoy your software!
From the software manual: “Thanks a lot to you that are use our company’s product”. Gee, thank you that you are use your software on me!
Posted on 2007-04-03 11:48 in rant | 2 Comments »
For no good reason at all I moved my blog from Blogspot site to Wordpress here on my website. Things may be broken!
Also updated the dezign of the website & blog. Colors are for wimps, grayscale for the win!
Posted on 2007-03-25 18:59 in random | 4 Comments »
OpenGL vertex buffer functionality, I mock thee too! Why couldn’t they make the specification simple&clear, and then why can’t the implementations work as expected?
It started out like this: converting some existing code that generates geometry on the fly. It used to generate that into in-memory arrays and then Just Draw Them. Probably not the most optimal solution, but that’s fine. Of course we can optimize that, right?
So with all my knowledge how things used to work in D3D I start “I’ll just do the same in OpenGL” adventure. Create a single big dynamic vertex buffer, a single big dynamic element buffer; update small portions of it with glBufferSubData, “discard” it (=glBufferData with null pointer) when the end is reached, rinse & repeat.
Now, let’s for a moment ignore the fact that updating portions of index buffer does not actually work on Mac OS X… Everything else is fine and it actually works! Except for… it’s quite a lot slower than just doing the old “render from memory” thing. Ok, must be some OS X specific thing… Nope, on a Windows box with GeForce 6800GT it is still slower.
Now, there are three things that could have gone wrong: 1) I did something stupid (quite likely), 2) VBOs for dynamically updated chunks of geometry suck (could be… they don’t have a way to update just one chunk without one extra memory copy at least), 3) both me and VBOs are stupid. If I was me I’d bet on the third option.
What I don’t get is: D3D has had a buffer model that is simple to understand and actually works for, like, 6 years now! Why ARB_vertex_buffer_object guys couldn’t just copy that? The world would be a better place! No, instead they make a way to map only whole buffer; updating chunks is extra memory copy; there are confusing usage parameters (when should I use STREAM and when DYNAMIC?); performance costs are unclear (when is glBufferSubData faster than glMapBuffer?) etc. And in the end when an OpenGL noob like me tries to actually make them work - he can’t! It’s slow!
Posted on 2007-03-22 23:51 in opengl, rant | No Comments »
Just got back from MVP Global Summit 2007 in Seattle. Among usual things, like watching Bill’s keynote, meeting other MVPs, DirectX/XNA guys, getting a grip of some NDA information and such, here are some of the other highlights:
Amsterdam airport:
Officer: You speak English sir?
Me: Yeah.
O (takes a look at my passport): Ah, you speak Russian of course!
M: No, not really.
O: But your language is very similar to Russian, right?
M: Hm…
Well, here we know who gets the Linguist of the Year award.
Seattle-Tahoma airport, lady at checkin: “what kind of passport is that?“. It also takes 5 times to enter my last name properly, from the printed letters in the passport. Each time trying to persuade me that I did change the ticket date of course!
Seattle-Tahoma airport, security: “sir, you have been selected for additional screening“. Do they randomly select people for that quite involved process? Why this “selection” happens immediately after they take a look at my passport?
Random quotes:
Ten minutes walk is a long distance! Ten minutes of walking distance in the States is a very good reason to buy a car. At least SUV; preferably a Hummer.
DirectX SDK is the source of all sorts of high frequency goodness.
Sony is always good at announcements.
No? Rumours on the internet? Shock! Horror!
Posted on 2007-03-17 23:13 in conferences, d3d, random | 5 Comments »
|