This scene has a triangle count of 2.

Relief Mapping Terrain demo
You are looking at a flat plane consists of 2 triangles running in the Blender 2.5 Game Engine.  There is no run-time subdivision, no geometry shader, using only a minimum pass-through vertex shader, all the magic is happening in the pixel shader.  The terrain is completely 3D looking, you can fly around it, view it from different angles, there is lights, shadows, bumps, shiny lakes, and even a height-based fog.  Below is a video of the technique in motion:

Isn’t Relief Mapping great?

Apart from all games that will inevitably take advantage of this technique, another application I can think of that will reap huge benefit from this is the loading and displaying of large-scale terrain visualization at virtually no CPU overhead.  A 4096×4096 DEM texture can be easily displayed at 60fps.  Whereas if the same data were to be converted to real geometry, most computers will die trying to render those 33million triangles.

The effect is achieved by a rather complex fragment shader (pixel shader) that effectively does ray-casting on each pixel to determine the location and visibility of each pixel.  The shader requires at least 2 textures.  A diffuse color texture; and a normal-height texture that contains the surface normal stored in the RGB channel and the height value stored in the Alpha channel.  Supplied with a miminum of these two textures, the shader is able to reconstruct the 3D surface like you saw.  (I also used a specular texture to control the specularity of the lakes, but this is optional)

Download the demo (4MB)

iPhone Photography

I recently got an iPhone 3GS, the camera that’s built into the phone is a pretty big disappointment for someone who shoots dSLR for the past year.  Super-noisy at base ISO 100, no manual control, shutter lag… it’s a mess.  Granted, big lenses and big cameras are super cool, and they take amazing pictures.  But this post is about living with, and taking advantage of the tiny camera on a camera phone.

Lesson 1: Know the limit of your camera, and try to work around it.
Vancouver sunset
Small cameras are known for their low dynamic range, so to get the most out of this sunset, I took two images at different exposure and merged them together with Pro HDR, right on the phone.  This increased the dynamic range dramatically, making it equal to that of a dSLR.  Then a bit of contrast and saturation boost completed the look.

Lesson 2: Post Processing
i am {not} on a boat
This picture came out very bland at first, but a few tweaks in Lightroom 3made it marginally passable.  There are enough apps in the Apple Appstore to edit your photo into oblivion and back.  Some of my favorite apps are Pro HDR, TiltShiftGen and Best Camera. Of course, for the most control, you’d have to use a desktop-based tool like Lightroom or Aperture.

Lesson 3: Color
Metrotown through iPhone
What the tiny camera lacks in light-gathering ability, it makes up by upping the vibrancy and contrast.  iPhone photos are usually a lot more vibrant and contrasty than what you get out of a high-end dSLR.  Use this to your advantage to capture some eye popping pictures.

Lesson 4: Bokeh
Untitled
You CAN throw the background out of focus even on a tiny sensor like the iPhone camera, but only if you are shooting in macro.  Just be patient with the focus, it can take a while to get the razor sharp image that you wanted.

That’s all for now, I am still discovering the capability of the iPhone camera.  Let me know if you have any tips regarding digital photography.

The perfect laptop!

I was window-shopping for laptops today and discovered the amazing Asus UL30 series.  It’s truly an amazing piece of engineering: it’s thin, it’s light, it’s fast, has an insane battery life, and pretty cheap.  Let me break down the specs for you non-geeks:

Core 2 Duo SU7300 Processor:
It has a 1.3Ghz (up to 1.7Ghz with TurboBoost technology), ultra-low-voltage processor manufactured on 45nm technology.  Which really just means the processor can do a LOT of work while barely sipping on your precious battery.  Honestly, it’s unbelievable how fast this processor is while using less than 10W of power.  [Compare with a 13 MacBook Pro: slightly slower, but uses 1/3rd the power)

Nvidia G210M 512MB and Intel 4500 Graphics:
This .93 inch thin laptop has TWO graphics cards.  The Nvidia G210 is probably the fastest graphics card available on a 13 inch laptop.  It's build on 40nm technology, and uses a max of 14W of power, which is still impressive for a graphics card of this caliber.  The Intel is slower, but uses even less power.  You can toggle between the 2 to trade off performance for battery life. [Compare with a 13" MacBook Pro:  The Asus is twice as fast, while using the same amount of juice]

4GB DDR3 RAM:
Also, the laptop can support a max of 8GB of memory, you know… in case you need that much. [Same as Macbooks.]

13inch LED-lit Screen:
LED also means it’s uses less power than regular backlights. [same as Macbooks]

12 hour battery life:
…or so Asus claims, you can probably expect 10 hours of real world usage, and maybe 4-5 hours of gaming/heavy 3D work. [much longer than the MacBook Pros]

Design:
Not quite on par with Apple’s drool inducing one-piece aluminum finish, but it’s one of the nicer laptops I’ve seen (once you get rid of all the stickers).  The design is obviously Macbook inspired.  And it’s really light and thin.

Price:
$800 USD.  I know you can get an even faster 15″ laptop for $900, but the battery life and portability also suffers as you up the screen size.  13″ with this amount of computing power is perfect.  It also comes with all the standard bells and whistles: webcam, bluetooth, 802.11n, and a half terabyte harddrive.

The bottom line:
if you are looking for a portable powerhouse, take a closer look at this laptop.  If you want raw power and don’t care about battery life or portability, skip this.

Update: I’ve had this laptop for almost a year now and am very happy about it.  It’s light enough to be carried everywhere, and with 8 hours of up time on the integrated video card (can be stretched to 10 if you are stingy on screen brighness or wifi), I don’t even need to carry the AC adapter unless I plan an overnight trip.  My only complain is that the screen has an absolutely horrific viewing angle, color shifts are common when viewed off-axis; and black is a muddy gray at best.  But once you plug this thing into an IPS display via the build in VGA or HDMI cable, the Nvidia G210M chip is beefy enough to play StarCraft II at medium settings.

Tip: How to sculpt with 4 million polygons on a laptop

With these tips, you should able to drastically increase your polygon-count limitation while sculpting.

1. Get Blender 2.5 Alpha, also go for the 64bit version if you have 3GB or more of RAM.  2.5 is simply a lot faster and refined than Blender 2.49.  The tools and interface is also much cleaner and more intuitive.  Also, a lot of work has gone into optimizing the sculpting feature in Blender 2.5.

2. Start with a base mesh, then apply the multires modifier.  Do not use a default cube and rely on the multires modifier to do *all* the sub-division.  It’s always better to start with a base mesh with a few thousand polygons, and use multires with a sub-division level of 2-5.

3. Turn off “Double Sided” in the Object Data panel.  This will significantly speed up the redraw.

4. Delete UV texture data and Vertex Color data *might* help speed things up, but I don’t really know for sure.

5. Turn on VBO in the Preference menu.  This will further speed up drawing speed.  (Thanks Gustav!) Okay apparently it doesn’t according to another commenter, since sculpt mode already uses VBO by default.

SVN log parsing and analysis fun

A few of you asked about how I got those statistics for my previous post about Blender SVN.

For the inquiring minds, I got the SVN log with the following command

svn log -r 25000:0 --xml https://svn.blender.org/svnroot/bf-blender/branches >> log.xml
svn log -r 25000:0 --xml https://svn.blender.org/svnroot/bf-blender/trunk >> log.xml

These two SVN operation fetches the SVN logs for both the branches and the trunk of Blender and combine them into one 8 megabyte XML file.  Please do not do this often as I imagine querying all the commit logs must put a heavy strain on the Blender SVN server.

Parsing the XML for the author commit frequency is done with the following python script:

import xml.sax

authorList= {}

# create document handler
class SVNXMLHandler(xml.sax.handler.ContentHandler):
	def __init__(self):
		pass

	def startElement(self, name, attrs):
		self.hasAuthor = 0
		self.hasEntry = 0
		if name == "logentry":
			self.hasEntry = 1
			#print attrs.get('revision', ""),
		elif name == "author":
			self.hasAuthor = 1

	def characters(self, data):
		if self.hasAuthor:
			#print data
			try:
				authorList[data] += 1
			except:
				authorList[data] = 1

	def endElement(self, name):
		if name == "author": self.hasAuthor = 0
		if name == "logentry": self.hasEntry = 0

# load and parse log
f = open('log.xml', 'r')
xml.sax.parseString(f.read(), SVNXMLHandler())

# print to console in comma delimited format
for i in authorList:
	print i,",",authorList[i]

Run the above python script like so:

python logParser.py >> crunched.csv

After a few seconds, a CSV file should be created containing all the data you need, ready to be graphed in Microsoft Office.  Yes I used Excel for the graph…

Build Blender 2.5, a visual guide

Today I will present a simple graphical guide to build Blender 2.5 on a Windows computer.  A lot of the instructions just need to be done one time, once you have a building environment setup, updating the build is a *really* simple process.  But if you just want a cutting-edge daily release, you can find those pre-compiled for you on Graphicall.org

Firstly, you will need a few piece of software: We are going to use Microsoft Visual Studio 2008 and Cmake to help us build Blender, and to fetch the source code from blender.org, we’ll also need a SVN client, I will use TortoiseSVN.

1. Get Visual Studio 2008. If you have access to a copy of Visual Studio, great!  But I heard the free Express Edition works too.  I went with a custom installation and this is all the components you’ll need to build Blender.

Custome Installation

2. Get CMake and install it.  It’s free.

3. Install TortoiseSVN, also free.

4. Once all the software are installed, we can begin to acquire the Blender source codes!  First, navigate to an empty directory and right click to do a SVN Checkout.  Use the following URL:

https://svn.blender.org/svnroot/bf-blender/trunk/blender

Put the source under C:\Blender\blender. Next, let’s also acquire the libraries needed to build Blender.  Do another check out with the following URL:

https://svn.blender.org/svnroot/bf-blender/trunk/lib/windows

Make sure you put the files under a directory like C:\Blender\lib\Windows.  If you want to make 64bit builds, also check out the 64bit libs:

 https://svn.blender.org/svnroot/bf-blender/trunk/lib/win64

Put that under C:\Blender\lib\Win64

04

Use TortoiseSVN to check-out the Blender Windows Library

Once you have done the 3 check-out, your directory structure should look like this, make sure all the folders and files are in the proper place, otherwise you will have a hard time building Blender:

Folder structure

Folder structure

5. Now that you have all the source files, it’s time to start the building process!

We are going to use CMake to generate a “solution” file for Visual Studio.  A solution is what Visual Studio would open to build the entire Blender. It’s a collection of smaller project, each project is a collection of source files.

Now open CMake, and In the top text box, type in where you put the Blender source code. (C:\Blender\blender, in my case)

In the second text box below it, select a fresh directory where you want the output file to go. I am using C:\Blender\build

Now click on Configure, this will bring up another dialog box where it asks you which generator to pick.  We are going to use Visual Studio 9 2008, or Visual Studio 9 2008 Win64, if you want to build a 64bit Blender.

CMake

Then CMake will populate the main window with a list of options that you can disable or enable.  The default selection is good, but if you want to speed up the building process, you can deselect certain options that you are not using.

Certain options might also be unavailable or broken on 64bit.  For example, if you are building a 64bit release, make sure you uncheck FFMPEG, JACK, and QUICKTIME, since there is no 64bit library for these media features yet.

CMake Options

For first timers, I would suggest unchecking all of these boxes to build a minimalist Blender.  It will be faster, smaller, and there is less chance of running into an error at compile time.  You can come back and re-enable these settings once your first build is successful.  Once you have made your selection, click on Configure at the bottom of the screen.  Then followed by clicking on Generate. These will generate the corresponding Visual Studio solution files in the directory you specified above.  (C:\blender\build\) in our case.  Close CMake.

6. Navigate to C:\blender\build, you should see the solution file you just generated.  Open “Blender.sln” with Visual Studio 2008.

Build folder

Once Visual Studio opens the solution, make sure you change the default build target from Debug to Release.  Otherwise you will end up with a debug build of Blender that is slower, bigger, and probably not helpful unless you are debugging.

Visual Studio 2008

After that, simply select Build Solution from the build menu.  After about 10 minutes of compiling and linking, a fully functional Blender installation should be ready under C:\Blender\build\Bin\Release.