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. :-)