Index: source/blender/render/intern/source/shadeoutput.c =================================================================== --- source/blender/render/intern/source/shadeoutput.c (revisjon 30814) +++ source/blender/render/intern/source/shadeoutput.c (arbeidskopi) @@ -699,6 +699,44 @@ return i; } +/* Beckmann spec */ +static float Beckmann_Spec(float *n, float *l, float *v, float slope, float gloss, int phong_hard, int tangent) +{ + float i, nh, h[3], angle, a, b, c, d; + + /* Half-way vector */ + h[0] = l[0] + v[0]; + h[1] = l[1] + v[1]; + h[2] = l[2] + v[2]; + normalize_v3(h); + + /* Dot product between surface normal and half-way vector */ + nh = n[0]*h[0] + n[1]*h[1] + n[2]*h[2]; + if (tangent) nh = sasqrt(1.0f - nh*nh); + if (nh <= 0.0f) nh = 0.001f; + + /* Use the Beckmann distribution to calculate the specular light */ + angle = saacos(nh); + a = tan(angle) / slope; + b = cos(angle); + c = b * b; + d = - (a * b); + i = exp(d) / (4.0f * slope * slope * c * c); + + /* Add phong highlight */ + if (gloss > 0.0f) { + if (nh > 0.0f) nh = spec(angle, phong_hard); + else nh = 0.0f; + i = i*(1.0f - gloss) + nh*gloss; + } + + /* Clamp */ + if (i < 0.0f) i = 0.0f; + else if (i > 1.0f) i = 1.0f; + + return i; +} + /* cartoon render diffuse */ static float Toon_Diff( float *n, float *l, float *v, float size, float smooth ) { @@ -1459,6 +1497,8 @@ specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); else if(ma->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec( vn, lv, view, ma->rms, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); + else if(ma->spec_shader==MA_SPEC_BECKMANN) + specfac= Beckmann_Spec(vn, lv, view, ma->rms, ma->param[3], 40.0f, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); else specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3], (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V)); Index: source/blender/makesdna/DNA_material_types.h =================================================================== --- source/blender/makesdna/DNA_material_types.h (revisjon 30814) +++ source/blender/makesdna/DNA_material_types.h (arbeidskopi) @@ -254,6 +254,7 @@ #define MA_SPEC_BLINN 2 #define MA_SPEC_TOON 3 #define MA_SPEC_WARDISO 4 +#define MA_SPEC_BECKMANN 5 /* dynamode */ #define MA_DRAW_DYNABUTS 1 /* deprecated */ Index: source/blender/makesrna/intern/rna_material.c =================================================================== --- source/blender/makesrna/intern/rna_material.c (revisjon 30814) +++ source/blender/makesrna/intern/rna_material.c (arbeidskopi) @@ -1312,6 +1312,7 @@ {MA_SPEC_BLINN, "BLINN", 0, "Blinn", ""}, {MA_SPEC_TOON, "TOON", 0, "Toon", ""}, {MA_SPEC_WARDISO, "WARDISO", 0, "WardIso", ""}, + {MA_SPEC_BECKMANN, "BECKMANN", 0, "Beckmann", ""}, {0, NULL, 0, NULL, NULL}}; prop= RNA_def_property(srna, "specular_shader", PROP_ENUM, PROP_NONE);