Saturday, February 11, 2012

[How-To] use Blinn specular reflectance for UE3 materials

This tutorials shows how to rebuild the blinn specular by using materials with MLM_Custom lighting model:

Whilst the Unreal Engine 3 is supposed to be a next-gen game engine it won't give you the possibility to use the blinn specular model by default. A major downside of phong is that it will always produce a blobby specular highlight, no matter of the light source angle. If you think of an oceans water reflections at sundown or streetlights at a rainy night this is a real disadvantage.

Starting with a simple material (including specular and normal map) using UDKs default Phong model:

This same material can be rebuild using the custom lighting as follows:

It's obvious that phong specularity takes a calculation of the reflection vector into account. The default Lambert lighting can be easily achieved by multiplying the diffuse color/texture with the dot product of light and normal vector. If you don't need a normal map use a Constant3Vector of (0,0,1) instead.

The heart of blinn specularity is the halfway vector between camera and light vector:

A dot product of this halfway vector and the normal vector is beeing exponentiated with the specular power afterwards. It's very important to normalize the normal map before using it for the blinn specular calculation, otherwise heavy artfacts might occure. This is really necessary, no matter if you have already done the normalization before importing the normal map.
Due to the different calculation, blinn specular needs a 4 times higher specular exponent than phong. But from my own experience I have to say that a 3 times or even 2 times bigger specular power looks better and more comparable.

Last but not least here's a phong / blinn specular comparison screen, taken at a fairly small angle between light source and objects surface:

As you can see blinn will give you a distinct elongated specular highlight whilst phong retaines the blob look.

No comments:

Post a Comment