Sunday, February 26, 2012

[How-To] use Minnaert diffuse reflectance for UE3 materials

Minnaert's model is a pure diffuse reflectance model which does not affect the specular reflectance. Therefore it can be combined with any specular model, like phong, blinn, cook-torrance etc.
The special feature about the minnaert model is that it can provide a velvet look by darkening the model along it edges.


Material Setup

The UE3/UDK implementation requires a material with custom lighting:













The amount of darkening is controlled by a paramter which I named as darkening paramter in the screenshot above. This one can have any value equal or bigger than zero. A value of zero means there is no darkening at all and will result in lamberts diffuse reflectance (UDK default).



Comparison

The following screenshots show the affect of different parameter values.

Monday, February 13, 2012

[How-To] use Oren-Nayar diffuse reflectance for UE3 materials

The oren-nayar lighting model is predestined for rough surfaces like sand, broken concrete or clothing for example. It takes into account inter-reflections and therefore has a major advantage over UDKs default lambertian diffuse lighting.

The following material is based on a simplified (yet quite correct) version of the original model and a mathematical simpification suggested here.



Material Setup:















The roughness parameter should be within the 0-1 range. For values > 0 you will notice the point light shader instruction count increasing by more than 20. If the roughness is equal zero the whole shader gets simplified and is the same as UDKs default lambertian lighting.
Also notice that that you won't need to use a custom lighting material to implement the oren-nayar diffuse lighting model. In case of a custom lighting solution keep in mind that you'll need to add the lambertian lighting part to this material network (multiply diffuse by a clamped dot product if light and normal vector)
I will will add a downloadable .upk later, in case you dont have the time to build this material on your own. (I don't expect you'll do this out of laziness ;) )




Comparison

I made comparison screens of 2 different surfaces at 3 different roughness parameter values to give you a rough impression. The FPS counter illustrates the impact on performance. Don't worry about the absolute low values, I tested this with my office rig and a low-end gfx card (Geforce GT520)

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:
http://udn.epicgames.com/Three/CustomLighting.html

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.