Sunday, June 08, 2008

Back to the 'Drawing Canvas'


I've been checking out the new canvas tag that's scheduled to be a part of HTML 5, the next specification of the web markup language. And I'm pretty impressed. The Mozilla guys have been doing some neat work with the Canvas and have a nice documentation ready for Canvas 2D: here. If you're reading this in Opera, Safari or Firefox, you've already got Canvas supported and running in your browser! Internet Explorer, of course, doesn't have it. But the folks at Google have written a neat thing called Ex Canvas, which allows you to just include an extra javascript file and have your code running in Internet Explorer too! I think the Canvas tag has some potential of being really accepted and supported by all the browsers, which means that its good for developers like us who crave for atleast ONE technology supported properly across all the browsers, apart from the standard (or rather, now not-so-standard) 'b'; tags etc. :-) So I think developers can actually put their money on the Canvas tag and not worry too much about support and implementation across browsers. Face it: three out of the four 'major' browsers have Canvas already running. And there is a Google hack that lets you run it in the fourth (now) so-called 'major' browser.

The other (really) interesting thing I've been checking out is the next-step: Canvas 3D! The guys at Mozilla have been working out the basics of a simple 3D library and have so far adopted a wait-and-watch strategy i.e. have implemented a basic library (which is scheduled to be shipped with the Firefox 3 release) that exposes the API of the OpenGL ES specification and makes use of hardware acceleration where possible and are watching what kind of uses the developers put it to, in order to determine the next features to add. Now this is really interesting news, as OpenGL ES is something I've been looking into for the past few days, and find it a tad better for me than the standard OpenGL implementation, as it is lighter and more streamlined. OpenGL ES by the way is OpenGL for Embedded Systems, which means that all the extra bloated code and old deprecated methods and fat around the OpenGL standard has been stripped off, leaving a light API for systems with limited resources. The guys at Opera have been working on a different approach however. They too have implemented a Canvas-3D implementation, but they don't make use of OpenGL bindings, instead provide a higher-level of abstraction allowing platform neutrality, i.e. permit non-OpenGL programmers to be able to use it too. While this is a nice idea, trouble will arise if the two major browsers decide to implement their own versions of Canvas 3D. And where does Microsoft fit in? I think they'll be willing to Open Source all their Windows code before they will ever think about implementing OpenGL (arch rival to their proprietary Direct3D) in their browser. So they might either make D3D bindings, or adopt a 'high-level/neutral' approach similar to Opera. Which essentially means that Canvas3D, as such, is still volatile and is a high-risk platform to develop for. But it is the most promising of the upcoming technologies as it incorporates hardware acceleration which will make life tonnes easier.

For instance, I wrote a simple z-buffering system in Javascript for a non-canvas based experiment, and it simply is TOO slow as the DIV hacks, as I mentioned in a previous post, are just not feasible for even a thousand triangles. Z-buffering, however, can be made to run really well in the Canvas2D platform. The Useless Pickles 3D demo crawled to a halt (0.4 fps) when I fed it with objects with slightly over 200 triangles, which is peanuts. And that 3D library/demo is the best attempt I've found so far on the internet. Agreed that when I looked under its hood, it didn't make use of anything other than simple backface culling for optimization, but even if approaches like BSP Tree with front-to-back rendering or Octrees for optimizing Frustum Culling etc are applied, there is only so much that you can do. The potential for the sort of things that can be done with Canvas & Canvas3D is far greater and I think its better to push with new technology than be really clever with the old one and remain at the stage of just proof-of-concepts.

PS: The picture at the start of the article is the Apple Mac OS X Webkit's icon. The entire concept of Canvas started with them.

Edit: I have been trying out the Google Ex-Canvas that enables code written for the Canvas tag to run in Internet Explorer too, and all I can say is: It is SLOW! Just to warm up the testing, I made it draw 60,000 (i.e. canvas size = 300 x 200) single black pixels at each position in order to fill the canvas block entirely with black (yes I know it can be done with a single fillRect command, but I'm testing things here remember?), and Firefox 3 (rc2) did it within 400 milliseconds, while Internet Explorer 6 took almost 7-8 seconds, not to mention hung while doing it. Can't expect much out an emulation, can you?

Wednesday, June 04, 2008

World Domination... and beyond!


This one is for all the Doom gamers, old or new. The Official Union Aerospace Corporation (UAC) website made by iD software's web designing team:

http://www.doomrpg.com/n.x/UAC/Home

Enjoy!
Shashank

Weekly round-up


Here's a round-up of the things that I've been working with a great deal over the past one week:
  • Google Sketchup
  • BSP Trees & 3D Rendering
  • Javascript
  • SDL & Projective Geometry
I might have something pretty interesting coming up within a few days, so if anybody who's into this stuff reads this, come back in a few days for an interesting Proof-of-Concept demonstration on this blog. It might be really dumb, but it does look pretty good to me.

Also, I was looking up into hacks of Nintendo Wiimote (thanks to my friend Roshan Shariff who got me interested into this - he's doing some pretty interesting Wiimote hacks too), and I think I'll get a Wiimote sometime soon when I save up enough for it. Till then, I'm looking into the sensors and libraries for interfacing it, and being a gamer myself AND a programmer, I can think of really nice things to use it for. :-)

Also, me and Roshan got into discussing how iD software's new game "Rage" implements the Megatexturing feature for rendering and texturing such HUGE landscapes etc, and found it to be an application of "Clipmaps", that are (as far as I understand, I'm still figuring it out), a way to use the Mipmaps concept (see below) and clip a cubical region from the Mipmap pyramid to get a series of landscape textures of decreasing quality (i.e greater zoom out).

So in effect, the "MEGA" Texture, often reaching into dimensions of 128000 x 128000 (which is really big), is used to construct the clipmap stack:
[Texture 1]
[Texture 2]
[Texture 3]
.
.
[Texture 'n']

In this, 'Texture 1' will be a say, 512 x 512 texture of the segment of texture (from the original 128000x128000 texture) that is right in front of the viewer. This one has no zoom effect, and is of therefore the best (original) quality. Then next texture, Texture 2 will also be 512 x 512 in size, but will be a "compressed/zoomed out" version of 1024 x 1024 segment of what is front of the viewer from the original texture, so this would be a 2x zoom out. Then Texture 3 would be another zoom out and so on.. and by Texture 6 (I think), the entire 128000x128000 texture will be compressed and represented by a 512 x 512 texture. Now, the renderer will just interpolate between the textures at the various levels the stack to render portions of the texture and show the required Level of Detail only. This also enables parts of textures to be streamed from an external disk when required, instead of loading the ENTIRE texture into the memory (which is dumb, not to mention almost impossible if your texture is 128k x 128k). I posted this here in order to make sure I understand properly myself, so there might be loopholes.

Useful resources:
Shashank
PS:
The picture at the start of the article is a screenshot of iD software's RAGE game, demonstrated at QuakeCon 2007 by John Carmack.

Saturday, May 31, 2008

Of Al-Google and the Silicon Valley rantings


I have two thoughts, and am too lazy to write two separate posts so I clubbed them into one.

Al-Google:
Google is funny, really. I was just taking a trip down ego-boosting lane, and did a Google search for myself, and found that searching for "Shashank Shekhar" (which sadly appears to be quite a common name nowadays) returned a reference to Me first on #15, and my current blog at #17 and my old blog at #20. Then, I did a search for just "Shashank", and Hey Presto! I jumped to #7! I thought adding descriptive keywords narrowed searches!
(PS: Yeah yeah, before you SEO geeks start giving me the reasons, the reason is that the #7 position is occupied by my old blog which is called just "Shashank's Blog", with no mention of Shekhar, so..)

My second topic is entitled: "Silicon Valley of India: A Miracle"

Well, I was reading a nice article about the coming together of the original Silicon valley, a paper actually, (here) and I agree with his explantion that the Silicon Valley came together because of a rare co-occurrence of a lot of events that catalysed such an event. The Venture Capitalists were there, the Infrastructure was there, the Research places and great Universities were there, all mostly in the same San Francisco Bay Area
in Northern California. The setting was just right for something amazing to suddenly come up. The university people came up with great ideas, the area had sufficiently high academic cultured people living around to encourage such innovation and if someone felt that some money could be made out of those ideas, the venture capitalists were there to be sold to the ideas. The spirit of risk-taking was enhanced by some early successes and the smell of money being generated. And people had garages which could be used as offices, and small rooms could be rented for the same purpose too. And employees had places to stay nearby and basic infrastructure like roads and transport pre-existing due to the existence of older residential areas in the neighbourhood. Yes, this is an over-simplification, but these points will come into play in my next paragraph.

Now how Bangalore came to become the Silicon Valley of India is indeed a puzzling thought. Lets see, Bangalore did have residential areas pre-existing, but I think that really was IT (no pun intended). No great Venture Capitalists prowling around, miserably tiny roads and basic small-town transport facilities, and most of all, no Stanford-like great Universities in the neighbourhood to fuel ideas. Therefore how the great start-ups of Bangalore came up, attracted investors, got clients, performed their day-to-day activities with the miserably lacking infrastructure is something that is nothing short of a Miracle. Even today, companies have their own internal power generators as depending on Bangalore City's own rickety power supply would effectively lose them deals worth millions of dollars everyday, they need to find ways to work around the terrible chaos existing in the cramped roads of a city that just grew too fast. Oh and when it rains (which it does for 3 hours every evening), the city halts to a standstill as it is impossible to drive with the pot-holes, broken roads and impossible to work with the power-cuts. I'm still wondering how this Miracle came about. The only possible explanation I see is that
a) The people who started the first start-ups were incredibly clever at attracting investors,
b) The Indians are willing to slave for really long hours with considerably lesser pay (which is true). Hence India is the hot-destination for a cheap-workforce, hence a great deal of investment in off-shore development.

PS: The building in the picture is the Infosys Headquarters.
PPS: If you're interested in reading some interesting stuff related to Silicon Valley, check out some interesting SV blogs I follow as often as I can spare time:

Friday, May 30, 2008

3D in Javascript? Kidding me?


Yeah.. well. That's definitely true for now, I mean that's definitely NOT easy to do with the current libraries and existing frameworks. With the "Canvas" project still chugging to completion and wide-spread implementation, we seriously don't have any proper 2D & 3D drawing libraries. Sure there are some really good libraries developed by some smart people, like the Ajax3D and the Triangles Method at UselessPickles but neither of those are true 3D engines capable of seriously importing and simulating objects with even, say, thousands of triangles at real-time, which is what even basic 3D games would require.

The most bugging thing is the lack of any sort of hardware acceleration available for drawing in the browser. Wait a minute! The Most Bugging Thing is the lack of ANY standard means of drawing at all in the browser! Well, as I see it, the graphic potential for rendering 3D objects using Javascript today lies somewhere close to the graphics prevalent in the year 1995, and is in a sense, actually worse. This is because not only is the triangles rendering capability sorely limited, the overheads involved in basic Input/Output is far higher, as it passes through several layers of application layer before it reaches the Javascript layer.

Well, I did write a basic 3D proof-of-concept type script that can simulate a rotating sphere with 300 odd triangles at pretty good speeds in my system. I'm still optimizing it. I find the task of writing this 3D engine in Javascript a lot more fun as compared to writing it in C++, because its like the old days when you had to squeeze out every little bit of speed from your code and run it in really restricted capability environments.

Tuesday, May 27, 2008

Crazy World Saving Idea #312


Hand everyone in the world a music instrument, and make it compulsory for them to play some instrument or the other. Playing music helps relax, and would make the world a more peaceful place.

Of course, my first action would be to purchase the finest set of sound-absorbing earphones I can get hold of, to drown out the cacophony of the world. :-)

Shashank

Sunday, May 25, 2008

TerraGen 2 : First looks

TerraGen 2 is really cool. They've released the "Technology Preview Edition", which is not a beta, but just a preview of the cool technologies that will form the next version of TerraGen, which was years in coming. But better late than never, this edition is really good, and incorporates Procedural generation of content into its grand scheme of things, and also has the Node Network that can be used to view the overall graph of the scene. Another interesting feature is the ability to do animations, so you can view the entire scene change over a period of time, instead of the static images its predecessor generated.

So much for the pros. The one thing I found troublesome is that it is really SLOW. But its a Preview Edition right, so can't say much.

Anyhow, here are my first drawings with Terragen 2 : Technology Preview Edition, and I think I'm getting better with each drawing! :-) The interface is completely new so I've gotta completely relearn how things are done.



Something chilly! :-)




Nevada? Chambal? Looks like some place that really needs those clouds to rain!




The Edge of the World! :-)

Enjoy.

Shashank
PS: TerraGen2 is available for free download from here.