Friday, April 11, 2008

Materials and Shaders

For those of you implementing a material system, this may be useful. I'm going to share my experiences making my "uber" shader. Well to be honest, its not as "uber" as it sounds, but nevertherless, it gets the job done. I created 1 effect with all my per pixel lighting code. (CgFX, I'm using NVIDIA Cg). In that effect I simply made a permutation of passes for all the possible materials we'll be using in our game/engine. The scene manager binds the appropriate pass and efficiently batch renders everything. For example, if my material had a diffuse map, gloss map (specular map) and it was parallax mapped, then, I'd name my pass DGNP, D for diffuse, G for gloss, N for normal required, and P for height map (required for parallax mapping). So what you notice here is, all the letters in the pass' s name are in accordance with the ordering of the English Alphabet. This makes it easy for the scene manager to refer to materials based on letters.

Here are some screens, the FPS is pretty low because I had some processes and graphics applications running in the background.

Tuesday, April 8, 2008

Real time water demo

This is a real time water demo. The waves are all layered normal mapped layers. It is based on the GPU Gems 2 article by Tiago Sousa (Crytek), titled, "Generic Refraction Simulation". The shader I wrote has a few modifications and added support for geometric waves. Anyway, see the video,

Friday, April 4, 2008

The Galaxy GeForce 8600GT Factory OC


This post is dedicated towards my trusty GeForce 8600GT manufactured by Galaxy and is factory over clocked (OC). I bought this graphics card about a year and a half ago, of course, relative to the time I posted this post. Now this card has been going strong for all this time and its time I talked about it. I bought it in Chennai, India, at that time for about Rs. 9000 which is rougly $226 (USD). Which I think was a reasonable price for the time. The core clock is about 600 MHz, but what I'd like to add is "DON'T SEE SPECS". Use card specifications as a guideline, but, for the ultimate test of truth I'd suggest to run a game or two, with the graphics card/motherboard combination (motherboard is very influential in performance) or even better run a program you made that used a lot of shaders (That is if your a graphics engineer). Here are some test results for a few games, with this card and the ASUS M2N E-SLI motherboard. These aren't extensive results, just the frame rates. All games were tested on the highest possible settings with only resolution and anti aliasing varying. The frame rates were recorded using Fraps (http://www.fraps.com/). All frame rates are approximate.

Game: Doom 3
  • FPS: 84
  • Resolution: 1280x1024
  • Antialiasing: 2x

Game: Need for Speed: Most Wanted
  • FPS: 79
  • Resolution: 1280x1024
  • Antialiasing: 4x
Game: S.T.A.L.K.E.R
  • FPS: 39
  • Resolution: 1280x1024
  • Antialiasing: On (Unknown/Not sure/Don't remember)
Game: FarCry
  • FPS: 109
  • Resolution: 1280x1024
  • Antialiasing: 2x
Game: Crysis (Very High Setting)
  • FPS: 18
  • Resolution: 800x600
  • Antialiasing: 0x
Game: Crysis (Very High Setting)
  • FPS: 15
  • Resolution: 800x600
  • Antialiasing: 2x
Game: Crysis (Very High Setting)
  • FPS: 4 - 7
  • Resolution: 800x600
  • Antialiasing: 16x
Thats about it for now, I may post more about more games, such as Gears of War, Medal of Honour: Airborne etc. Pretty old for now, but good nonetheless.

Right now, if your a poor teenager, you can probably buy this card for about 104 USD, atleast here in India.

The card manufacturer site is: http://www.galaxytech.com/

Thursday, April 3, 2008

Experiments with SSAO (Screen Space Ambient Occlusion)

Its been a real long time since I last posted. So I thought I'd post something. I've been experimenting with the Screen Space Ambient Occlusion (SSAO). The fancy name that was used in Martin Mittring's (Crytek) presentation "Finding Next Gen – CryEngine 2" presented at Siggraph 2007. For those of you who've had the privilege of having played Crysis on the Very High or High settings would notice some immensely cool shading on all the geometry, even though there might not have been more than 1 light in the scene. This is thanks to a crude approximation of an approximation. (Since Ambient Occlusion is in itself an approximation to the indirect lighting problem). This is called Screen Space Ambient Occlusion and is a dynamic Ambient Occlusion method which doesn't need pre processing.

I implemented SSAO in the game engine I'm working on and the results were good, but not as spectacular as I expected. I used 2 color attachments (2 render targets for those more familiar with directX) for the initial rendering of the scene. The second color attachment I used for storing ModelView transformed direction vectors to each pixel on the screen (Eye space normalized eye vectors) and in the alpha component I stored the ModelView distance. Now whats to note here is, SSAO is not only dynamic but also is applied as a post process to the scene. So you can probably add it to your HDR/DOF pass. Just recover the 3D point at that pixel and then compare it with some 3D points around that point in a hemisphere. Then apply noise.

Inigo of RGBA demoscene group explains in this page: http://rgba.scenesp.org/iq/computer/articles/ssao/ssao.htm

But for some reason his method didn't work directly for me. For example the projection he performs in his loop for the 32 hemisphere 3D points a multiplication with
vec2(.75,1.0); but I found that (.78,1.0); works precisely. Well for me atleast.
You can always try using a gaussian blurred scene texture as a replacement for the 32
iterations. It worked as well as the SSAO in Crysis but with thick white borders.
Anyway, onto screens,

Without SSAO:


With SSAO:



SSAO Contribution to the scene looks like this:



Hope this was useful, I'll probably put some screens and details about my uber
per pixel lighting shader next time, or may be some OMNI directional light sources
that cast shadows. Its pretty old, and even my implementation was done a long time
ago.

Apart from the above algorithm, I did implement SSAO with extremely good results
(similar to Crysis and twice as fast) with a gaussian texture obtained from my
bloom pass. But unfortunately I got some ugly artifacts on the border (Outlines).
If anybody manages to fix this, please tell me!

Here are some images of SSAO which uses the Gaussian texture.

I used this equation:
AmbientOcclusion(x,y) = 255 + GaussianAverage(x,y,sigma) - PixelValue(x,y)