Originally Posted By: sivan
what I still don't really understsand is why there are more methods for specular calculations, which have different final appearance. in shader workshops (and in another tutorial at rastertek.com) a reflection vector is calculated producing imo bad results, I found better to use the halfway vector method.

Yeah, there are different methods which have different results.

I prefer blinn-phong specular lighting (looks nice and it's not very expensive).

(in case you want a couple of spec-algorithms:)
Code:
#define Specular_Phong(normal, view, light, materialPower)     pow(saturate(dot(reflect(-light, normal), view)), materialPower) // Phong Reflection Model
#define Specular_BlinnPhong(normal, view, light, materialPower)     pow(saturate(dot(normal, normalize(light + view))), materialPower * 4) // Blinn (Phong) Reflection  Model
#define Specular_TorranceSparrow(normal, view, light, materialPower)     exp(-2 * materialPower * pow(acos(saturate(dot(normal, normalize(light + view)))), 2)) // Blinn (Torrance-Sparrow/Gauss) Reflection  Model
#define Specular_TrowbridgeReitz(normal, view, light, materialPower)     pow(1 / (1 + (1 - pow(saturate(dot(normal, normalize(light + view))), 2)) * materialPower), 2) // Blinn (Trowbridge-Reitz) Reflection  Model
#define Specular_Lyon(normal, view, light, materialPower)     pow(1 - saturate(dot(normalize(light + view) - normal, normalize(light + view) - normal) * materialPower / 2), 3) // Lyon/Blinn halfway method

normal = surface normal; view = direction vec from the fragment pos to the camera; light = direction vec from the fragment pos to the light; material power = glossiness / spec exponent (needs to be modified a bit)
(all vectors have to be normalized)

Edit: @txesmi: oops, I didn't know that smirk
However, calculating the blue channel shouldn't be a problem ;P
(I think this works: z = sqrt(1 - x * x - y * y);)

Last edited by Kartoffel; 07/17/13 15:22.

POTATO-MAN saves the day! - Random