Lets learn pixel shaders - Chap 2 - Basics

Important - To move forward open another tab in your browser and open the URL http://www.iquilezles.org/apps/shadertoy/, I will refer to this tab simply as 'Shader Toy'

Chapter 2 - Basics of pixel shader with 'Shader toy'

Let us write some code, switch to the shader toy and notice that the "Deform" shader is already loaded and is running by default. On the right side bottom you see the source code, and on the left is the rendered effect. Take some time to notice the various details/controls shown to you like

1) fps, time, play/pause button, restart button on top of render area (place where the effect is played).

2) Dimensions panel - Width and height of the render area on top it. You can change it if you want.

3) The textures passed to the pixel shader are given right to the width/height box. You can pass up to 4 textures and use them in the pixel shader. The texture used in deform shader is given in the box 'unit 0'. Copy paste that URL path in a new tab and check the texture for yourself, or you can just click this link.

4) Also you can check the other shaders by going through presets drop down list. Don't forget to click 'Load'. There are some cool effects which you have no idea how to create, but at the end of this series you will learn to make most of them.

5) Most important thing we need to notice is the compile button. It is given above the source code area along with 'help' button.

n00b note - Every time we write new code, we need to press the compile button to see new source code taking effect.

6) Now let us write some code. We will begin with a blank program. Copy paste the following code in the code window.

#ifdef GL_ES
precision highp float;
uniform float time;
uniform vec2 resolution;
uniform vec4 mouse;
uniform sampler2D tex0;
uniform sampler2D tex1;
void main(void)

--- Now hit the compile button and see the output on the left side ---

7) Beautiful isn't it !
It will be a blank screen. Basically for now we have not written any code. Being a programmer I'm sure  you can notice that main function is empty. If you don't know what main() function is, then stop reading right away, don't waste your time. Grab a good C or C++ book or tutorial.

8) Now let us write our first line. If you recap I said - "pixel shaders are programs that are run for every pixel on the screen and they can do one thing, set the pixel color". So let us do that now. Inside the void main function block write the following line
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
gl_FragColor is a built-in variable through which we can write the pixel color. vec4 is a custom data type just like int, float, bool etc. But vec4 is a vector of 4 float numbers. The numbers are the colors - R, G, B and A. So here we say R, G, B are zero and Alpha is one which works out to black color. Hit compile button and make sure it is not paused on the left side, you will see the screen turning black. Now try replacing that line with the following.
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
Click compile and run again, you get the idea? As the same program is running for each pixel on the rendering area, and what we are doing is just setting it to white, the whole screen looks white.

Now how do we make things interesting? Wait for next chapter :)

Lets learn pixel shaders! - New Series - Chapter 1

This is the beginning of a series of tutorials, about pixel shaders (aka fragment shaders) with WebGL. I will start by assuming you are someone who has "absolutely no experience in graphics programming", but you should know what pixels are, what their components are. And optionally if you have basic 3d texturing knowledge, it will help a lot, but again not compulsory.

Without more blah, blah, let us start learning fellow programmers!

without which I would have never even started this! All our tutorials will be explain with reference to that web app. You will need one of the latest browser to run it.

Chapter 1 - Pre-requisite (for the n00b graphics programmer)

Pixels (skip if you know)

Everything you see on your monitor is made of pixels. If you zoom into your computer monitor, basically it is made of basic blocks (usually square shaped) called pixels. But as they are very small and closely packed, you are not able to notice them. Every monitor doesn't have the same number of pixels.

Resolution (skip if you know)

It is (number of pixels lengthwise) x (number of pixels widthwise). For eg. iPhone 3GS has a resolution of 320 x 480 when you hold the phone in portrait mode. iPhone 4 / 4S has 960 x 640 as their resolution. A full HD (High Definition) monitor has 1920 x 1080 pixels. More the resolution, more is the image detail/clarity. Will you be able to show more details with a 10x10 grid of dots or a 100x100 grid of dots? Think about it.

Pixel components (skip if you know)

Each pixel can do only one thing - "They can display a color". A pixel has three basic components - R, G and B. They are the primary colors, and combining them in various ways, we can make thousands (or millions, in latest monitors) of other colors. Usually each color is represented with one byte (8 bits, so value range is 0 - 255). So put together for each pixel you will have total of 3 x 8 bits = 24 bits or 3 bytes of color information.

For eg.
black (R = 0, G = 0, B = 0)
white (R = 255, G = 255, B = 255)

Introducing Alpha (skip if you know)

Apart from R, G and B, there is another component for a pixel, its called Alpha. Alpha = Transparency. Often pixels can be overwritten on top of each other, when that happens they are "mixed" according to their alpha levels. So R, G, B and A are the components of a pixel, which takes 32 bits per pixel. Understand there are more ways to represent a pixel, its not always 32 bits, but it is the most advanced pixel format, and enables an individual pixel to represent the max number of colours.

So, what are pixel shaders ?

Now that you know what pixels are, pixel shaders are nothing but programs, very similar to a C program. Next paragraph is very important.
A pixel shader is run for every pixel, before getting displayed on the screen. So let us say we have 1920 x 1080 pixels for a full screen game, which is a total of 2073600 pixels, which means a pixel shader is run that many times! But that is okay because they are all run on the GPU, instead of the CPU (Graphics processing unit, a special hardware dedicated to graphics, present nowadays on almost all computers).

Now that we know the basics, let us get started with
1) what can be done in a pixel shader,
2) how it can be done and
3) what information we have access to in the next chapter !

Any doubts are welcome in the comments section.

XCode 4 icon


Like me if you have installed both XCode3 and XCode4, and you wanna have both in the dock, you will find having the same icon is confusing, so here is a custom icon which you can use.

Right click XCode.app and click "Show Package Contents" and after that navigate to "Contents/Resources" and replace the existing Xcode.icns with this one.

Download Custom Xcode.icns file.

Download Android SDK standalone for offline installation

Update :- SDK for Android version (6.0) added !

How to install Android SDK without internet connection

I searched all over the internet and found no posts like this, hence I'm making one hoping it would be helpful for a lot of people.

The magic URL used to be - http://dl-ssl.google.com/android/repository/repository.xml (Outdated)
That is the XML file from which the URL for downloading the SDK packages are obtained.

Update :- The previous URL is now invalid, the new URL is given below
https://dl-ssl.google.com/android/repository/repository-5.xml (Outdated)

Update 4 :- New URL
https://dl-ssl.google.com/android/repository/repository-10.xml (thanks topcoder from comments)
For e.g. if you want to download Android SDK for version 4.0.3 for all platforms, you could look up that XML file. You will find a block under tag SDK 4.0.3 like this

<sdk:archive arch="any" os="any">

<sdk:checksum type="sha1">f2aa75133c29916b0b0b984974c2d5e46cb09e9c</sdk:checksum>

So the URL will be is http://dl-ssl.google.com/android/repository/android-15_r01.zip

If all the above sounds too complex

You can directly download from the below links. If this page does turn out to be useful, then I might update it regularly. Do leave a comment to let me know if it has helped you.

Android SDK Platform 6.0 (*** NEW ***)
All Platforms

Android SDK Platform 4.4
All Platforms

Android SDK Platform 4.2.2
All Platforms

Android SDK Platform 4.1.2
All Platforms

Android SDK Platform 4.0.3
All Platforms

Android SDK Platform 4.0
All Platforms

Android SDK Platform 3.2 revision 1
All Platforms

Android SDK Platform 3.1 revision 3
All Platforms

Android SDK Platform 3.0, revision 2
All Platforms

Android SDK Platform 2.3.3_r2
All Platforms

Android SDK Platform 2.3.1_r2
All Platforms

Android SDK Platform 2.2_r3
All Platforms

--- OLDER LINKS (Still working) ---

Android SDK Platform Honeycomb Preview, revision 1
All Platforms

Android SDK Platform 2.3.3_r1 (Offline complete download) - Approx 80 MB
All Platforms

Android SDK Platform 2.3_r1 (Offline complete download) - Approx 80 MB
All Platforms

Android SDK Platform 2.2_r2 (Offline complete download) - Approx 80 MB

Android SDK Platform 2.1_r1 (Offline complete download) - Approx 80 MB

Android SDK Platform 2.0.1_r1 (Offline complete download) - Approx 80 MB

Android SDK Platform 2.0, revision 1 (Offline complete download) - Approx 80 MB

Android SDK Platform 1.6_r2  (Offline complete download) - Approx 63 MB

Android SDK Platform 1.5_r3  (Offline complete download) - Approx 54 MB

Android SDK Docs for Android API 7, revision 1 - Approx 48 MB
All Platforms

Android SDK Tools, revision 5  (16 to 23 MB)

Pointer not declared even when declared !

A Strange problem encountered yesterday which left us puzzled for a few mins :) (Check image below)

So now, we tried everything possible. Until at last when we saw that there was a backslash after "Plist" in the comment line. As backslash is an escape sequence, it made the whole next line invalid, more like a comment.

Once we deleted that backslash, things were back to normal. But hey, aren't comments supposed to suppress anything in them including escape characters

How to ignore build directory in SVN from command line

This works for Windows/Mac/Linux, but its tested on Mac. On Windows, you can do it easily with Free TortoiseSVN Shell context menu, so this method will be useful on Mac/Linux.

Lets suppose your folder structure is

Now open terminal and cd to development. (Now if you 'ls' it wil' list Projectfolder)
type svn propset svn:ignore "build" Projectfolder/  and press Enter.

and that is it, your build folder will be ignored.