Tuesday, July 09, 2013

Parallax Occlusion Mapping without Tangent Space



After reading the blog posts from Rory and Mikkelsen, I have done an small WebGL demo on the derivative maps and extends it with the parallax occlusion maps effect.
The demo can be found here

The basic derivative map shader

The above shader does the following tasks:
  1. Fetch the pre-computed dhdv and dhdv from the gradient map.
  2. Compute the dudx, dvdx, dudy and dvdy using the dFdx() and dFdy() instruction, and use these values to transform the dhdu and dhdv to dhdx and dhdy respectively by applying chain rule.
  3. Compute the dpdx, dpdy where p is the interpolated world-space position of the current fragment.
  4. Compute the surface gradient by using dpdx, dpdy, dhdx, dhdy and the interpolated world-space normal
  5. Compute the perturbed world space normal with the surface gradient.
For the gradient maps, they are generated from a height map using this Paint.NET CodeLab script.

Parallax Occlusion Mapping

Then we add the POM support by inserting the following code to offset the texture coordinate before we fetch the pre-computed dhdv and dhdv. Since WebGL does not support texture2DGrad() nor texture2DLod() in fragment shader, we can not improvment the performance with dynamic branching.
Interestingly, currBound can be used for computing the ambient occlusion factor.
ParallaxDirection() transform the world space view vector to tangent space.

Tuesday, May 28, 2013

Life without scaffolding

After I read the tutorial from Nettuts+ , here are parts of the key step for creating a web-app without rails' scaffolding.

Creating the new project

Type in the following command
where PROJECT_NAME is the name of the new project, please notice that the -T argument tells rails not to generate the unit-testes automatically.

Installing Rspec and Capybara

Open the Gemfile inside the generated project and append the following lines: Save the file and use the following commands to install the necessary gems and initialize the /spec directory
And we can run the specs (aka unit-tests) with this command If you encounter problems like: 'undefined method `visit' for #<RSpec::Core::ExampleGroup...' while using Capybara methods, try to put the following lines in /spec/spec_helper.rb, inside the config block. (reference)

Creating Controllers

To generate a controller, for example, Tasks (rails use plural form to name controllers): Then we setup the routes for the generated controller by adding the following line to /config/routes.rb Verify the routing by the following command To add a view, for example 'index', to our controller, open /app/controllers/task_controller.rb and remember to add the template file for our view in /app/views/tasks/index.html.erb

Creating Models

To generate a model, for example, Task with 2 attributes: desc (text) and done (boolean) here is the reference of available attribute types
After that perpare our database using the following commands

Tuesday, May 21, 2013

Let's get wet

After considering the recommendations from my co-worker, I decided to learn how to build a web-app using the Ruby on Rails, since it seems to be a fast and complete solution.

In order to get started on the win32 platform, I follows the steps in the offical guide http://guides.rubyonrails.org/getting_started.html, and here is a summary of the key-steps for setting up the environment.
  • Download the ruby 1.9.3-p429 installer and DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe from http://rubyinstaller.org/ (I've tried the 2.0.0 version but there are some problems on the sqlite3 gem).
  • After the ruby installation is completed, extract the all contents (with 7-zip) in the DevKit package to C:\DevKit, and then execute the followings using the Ruby's command prompt
  • When the DevKit is configurated, restart the Ruby's command prompt.
  • Then execute to install Ruby on Rails.
Be patient and you are ready to travel on Rails :-)

References: