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.

Implementation of the 'Threshold Whole Square Method'

So here's the 'C' implementation of the 'Threshold Whole Square Method' I talked about (here). This one is only for 'long' data-type, but I've written a generic one that can deal with float types too, but I'll post that one later.

Code:

long lsqr(long n) {
if (n > 1)
{
long twoBase = 1, i;
for (i = 1; twoBase <= n; i++)
{
twoBase <<= 1;
}
twoBase >>= 1;
long k = (long)(n - twoBase);
long sqrN = (long)(twoBase << i - 2);
return (k == 0 ? sqrN : sqrN + lsqr(k) + ((k * twoBase) << 1));
}
else
return n;
}


Basically, the variable twoBase is the nearest threshold which is a power of 2, so that it can be used as 'n' in the formula mentioned in that other post. This is done as the whole square of this number can be calculated very cheaply by a simple left shift operation. After that, the difference between the given number and this threshold is calculated to determine 'k', i.e. the offset. Then a simple application of the formula gives the result. The advantage of this method is that the we need to effectively calculate the whole-square of just a very small number (the offset 'k'), instead of the conventional calculation of the entire number 'n'. This make this method marginally faster than the compiler's method, but this one can only be used for 'long' data types and should be used carefully.

Quick calculation of whole squares using "Threshold Method"


Not a big deal, millions might have already guessed it or might be using it. Just found it useful to mentally calculate the square of the next number quickly, if you know the square of a basic 'check-point' number like 10, 15, 20, 25, 30 etc.

The standard formula I use for such a technique is:

sqr(n+k) = sqr(n) + sqr(k) + 2*k*n
For e.g.: sqr(29) = sqr(25+4) = 625 + 16 + 2*4*25 = 625 + 216 = 841


Thus the above sqr(n+k) method of finding squares is very useful for quick calculation of squares using the left shifts in even multiples to find the value of the nearest power of 2 and then adding 'k' to determine the desired whole square quickly for computer algorithms as well as human calculations.

For humans, it is easy to calculate with the nearest multiple of 10 or 5 as 'n' and 'k' as the extra required to achieve the number (like in the previous example). For computers, it will be quick to take the nearest power of 2 as 'n', as they can quickly calculate the square of that n by left shifting. I did write an 'C' implementation of such a "Threshold Whole Square" algorithm, which can be found here.

Shashank

PS: The ball in the picture is called a "Spherical Cube". Its made of 6 squares. Yes, they are squares, even though they don't look like one. :-)

Saturday, May 24, 2008

Squack3D


Alright, hence starts my first Technical project for the vacations. For those interested, my internship is now officially "Work-from-home" status, so I need not go to office everyday, but just pop in now and then for reviews. :-)

This project I'm embarking on is basically just a learning-experience type thing, don't really think it has much value as such. Anyhow, the project is called "Squack3D" (for lack of a better name), and is a very very stripped-down elementary 3D engine, that tries to offer the simplest 3D functionality for games that could be incredibly large to incredibly small. But the point is that the graphic needs of those games will have to be really basic, with no fancy effects etc. The second objective is to have the engine run at super-lightning speed, so that its really good at whatever limited functionality it gives. The third objective is to incorporate Procedural development techniques right into the basic fabric of the 3D engine which will reduce a lot of effort on the part of the game developers to develop stochastic algorithms etc for basic things.

Let me summarize the objectives:
  1. A highly stripped-down engine focusing on very basic graphics and primitives giving games and applications with low-fi graphic expectations a very small and suitable 3D engine
  2. Super-fast rendering and processing
  3. Inherent support for Procedural generation of content
  4. Ready-made templates for basic applications and games
  5. Free! In all the senses.
Shashank
PS: The scene in the picture is NOT from my engine however! :-) Its from a software called Terragen.
PPS: Your browser isn't rendering my blog incorrectly, I have indeed stripped all styling and graphics from my blog for simplicity and elegance with this new design. :-)

Monday, May 19, 2008

This is how I look when I'm forcibly woken up...


Dee Snider, from "Twisted Sister".

An awesome heavy-metal band of the 80s, never-mind their make-up. ;-)

(That's a guy in the picture, BTW. That's Dee Snider).

Saturday, May 17, 2008

The Lore of the Inverse Square Root function


This one is for all the 3D geeks!

I had posted some useful optimizations for Graphic programmers earlier, and one of the optimizations I had suggested was one I saw in the Quake 3 source code, which performs the inverse square root, i.e 1 / sqrt(x). In 3D Graphics, the question of who came up with the 'magic' constant
0x5f3759df continues to be a question that 3D geeks still seek to answer! Most attribute it to the legendary programmer John Carmack, the man behind the Quake, Doom and all id Software Game Engines. However there are several other people attributed to it, and John himself refused to take claim for the creation of the constant in the mail:

-----Original Message-----
From: John Carmack
Sent: 26 April 2004 19:51
Subject: Re: Origin of fast approximated inverse square root

At 06:38 PM 4/26/2004 +0100, you wrote:

>Hi John,
>
>There's a discussion on Beyond3D.com's forums about who the author of
>the following is:
>
>float InvSqrt (float x){
> float xhalf = 0.5f*x;
> int i = *(int*)&x;
> i = 0x5f3759df - (i>>1);
> x = *(float*)&i;
> x = x*(1.5f - xhalf*x*x);
> return x;
>}
>
>Is that something we can attribute to you? Analysis shows it to be
>extremely clever in its method and supposedly from the Q3 source.
>Most people say it's your work, a few say it's Michael Abrash's. Do
>you know who's responsible, possibly with a history of sorts?

Not me, and I don't think it is Michael. Terje Matheson perhaps?

John Carmack

Why this is so important could be understood by the fact that Chris Lomont, a professor at Purdue took up the task of deriving that constant by mathematical means for the initial approximation of the Newton Raphson method (that the magic code uses), and his 'mathematically and theoretically' brilliant approximation constant turned out to perform WORSE than the constant found in the Quake III source code. So the question that arises is how John Carmack, or the author who originally wrote the code managed to figure out the magic approximation. That could be pretty useful I think for designing other fast mathematical functions.

So this article on Beyond3D.com does a great job of tracing down the original author, or atleast a major contributor, after a great deal of digging around. Check it out:
Origin of Quake III's Fast Inverse Sqrt()

Thursday, May 15, 2008

The Creativity-Killer : Office life


Don't get me wrong. Its not because I'm really unhappy at the fact that my vacations are getting ruined as I have to "WORK" in the office 10 hrs a day everyday (read) but truly a realisation that I came about due to this effort.

The "office life" destroys your creativity, forcing you to do continually work piecemeal on mostly dumb projects that you know will never revolutionize anyone's life, but basically does the routine that people need. Yes, this kind of routine work has to be done by someone, but if you're like me, you will not be the one to get stuck in this zombie culture of waking up in the morning, slaving for 10 hours, and then returning towards late evening, too tired to do anything but slouch on a chair drinking tea and writing about how dumb you feel. One simply doesn't have the time or energy to think about ANYTHING else after returning from office. All one seeks to do is to relax and sleep soon. Gotta sleep early.. office in the morning remember? In short, even if you are good, the routine office life will bring you down to its levels of mundaneness and dumbness and make you feel generally really stupid and out of touch.

This is the typical routine every office worker follows, and my statements are meant for those select few who desire to break away from the system and be different. If you are fine with serving people's routine needs, that is perfectly genuine too. Do not mistake me. I am talking about those people who can be intensely creative, know that they can do better things for people, have confidence in themselves that they can create things that will make better and revolutionize the life of others as well as theirs. The first casualty when you get stuck in the drill of conventional life is your sense of Independent thinking.

A matter of bread and butter, some would say. True. You've gotta do what you've gotta do. However, when there is an opportunity, grab it. Risks are meant to be taken, some big and some small. When you have the chance to some radically better stuff, do it. I have been in IEEE Students' Chapter for the past two years, and was the Secretary at last count. But I felt that it was time to move on and do other things, even though I appeared to have a very good chance at the top job. However, it was a risk nevertheless, leaving IEEE to get back the time to do bigger things, develop new ideas that could potentially be the next big things. I feel I can do it. So risk I must. Risk the general "social standing", risk the chance of not having any work to channel one's energies. This is an example of a small risk, almost negligible. But the basic point does not change. If you want to be different, don't get stuck in any kind of routine. One must follow for a while, and move on to other things to remain fresh and dynamic.

Tuesday, May 13, 2008

The coming ages of immersive gaming?


Just found this interesting looking article about the possibilities offered by immersive large-display systems. Check this out:

Wall-sized, multi-touch 'Missile Command' -- every gamer's fantasy

To quote a few catchy phrases:

"A gentleman named Steve Mason has created a large-scale version of the game that can be played by hand using multiple contact points. The result? Extreme awesomeness." Lol! ;-)

There's a flash video on that page that demonstrates players playing the game live.

I've posted this here, as this has gotten me thinking again about the trends that games will follow in the coming few years. Yes, this particular wall-display system noted above is not really "immersive", but in all essence, I would get completely immersed in such a game! Wouldn't you? ;-) Don't get me wrong, I'm not calling the above game display system "immersive"!

Having been involved in a lot of personal game-development projects, I find it extremely fascinating to note that we are indeed moving closer and closer to the age of true Virtual Reality, where the technology blurs the barriers between what we really believe to be "real", and what we don't. I for one would be the first to question what we indeed are, returning to the age old question of "why are we here?", and "HOW are we here and conscious about it?". Anyhow, the concept of Virtual Reality really raises a lot of interesting questions- technical, business-related, ethical, psychological and philosophical.

More on this soon. Promise.

9 hr 45 minutes a day. 6 days a week. 33 days.

That's the duration of my summer internship. There goes my vacation, can see it fleeing away while I sit in the office.

Have a confidentiality agreement with them, don't want to talk about them anyway. My poor vacation...

Monday, May 12, 2008

Yet another 'Airport Blues' saga


This time around, hanging around Bangalore's Great Airport, I discovered some harsh truths of life. Life is like the Cafe Coffee Day Espresso that you get at the Bangalore Airport. You do not ever get what you wanted, its hideously expensive, it has no sugar, is black and really awful. Stirring it up makes no difference really, ultimately you end up with the same old stuff and its better to drink it up in one quick gulp than one prolonged struggle and bitter taste. And it always tasted better in the good ol' days.

I can say without doubt that THAT was simply the worst coffee I ever had in my life, and saying that would be a gross understatement. I was waiting to pick up my mom, and due to a series of (un)fortunate events ended up reaching the Airport really quickly, and an hour and half early. Bangalore Airport is seriously not the best place to hang out, and they take great pains to maintain and further that reputation. No chairs or waiting lounges at the Arrivals gate. Just one Cafe Coffee Day outlet with smirking faces serving you bad coffee. So I managed to find a seat in the Departures section, and then was sprayed all over with insecticide. The stupid bugger chose to make his grand entry right at the moment I sat down, and sprayed those fumigated kerosene-like smelling fumes all over me, and the people all around me too. Luckily its meant only for mosquitoes and small insects, not animals.

Oh, and I am alive, kicking and have finally returned back to this blog.
Auf Weidersehen!

PS: I speak German now.

PPS: I simply cannot understand how people manage to drink Black Coffee! My theory is that people find themselves awakened by sipping Black Coffee because each sip is so horrible and bitter that it shocks them awake. That's how I stayed awake for 1.5 hours at the airport, and just managed to finish half of my coffee (which was originally half a cup anyway). Gruesome really.