Index: source/blender/blenkernel/bad_level_call_stubs/stubs.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/bad_level_call_stubs/stubs.c,v retrieving revision 1.29 diff -u -r1.29 stubs.c --- source/blender/blenkernel/bad_level_call_stubs/stubs.c 3 Sep 2005 18:10:13 -0000 1.29 +++ source/blender/blenkernel/bad_level_call_stubs/stubs.c 25 Sep 2005 15:02:25 -0000 @@ -112,6 +112,7 @@ float CookTorr_Spec(float *n, float *l, float *v, int hard){return 0;} float Toon_Spec(float *n, float *l, float *v, float a, float b){return 0;} float WardIso_Spec(float *n, float *l, float *v, float a){return 0;} +float Ashikhmin_Spec(float *n, float *l, float *v, float a, float b, float c){return 0;} float Toon_Diff(float *n, float *l, float *v, float a, float b){return 0;} float OrenNayar_Diff(float *n, float *l, float *v, float rough){return 0;} float Minnaert_Diff(float nl, float *n, float *v, float a){return 0;} Index: source/blender/blenkernel/intern/displist.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/displist.c,v retrieving revision 1.117 diff -u -r1.117 displist.c --- source/blender/blenkernel/intern/displist.c 3 Sep 2005 17:22:28 -0000 1.117 +++ source/blender/blenkernel/intern/displist.c 25 Sep 2005 15:04:19 -0000 @@ -568,6 +568,8 @@ specfac= Blinn_Spec(nor, lv, shi.view, ma->refrac, (float)shi.har); else if(ma->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec(nor, lv, shi.view, ma->rms); + else if(ma->spec_shader==MA_SPEC_ASHIKHMIN) + specfac= Ashikhmin_Spec(nor, lv, shi.view, ma->roughu, ma->roughv, ma->ks); else specfac= Toon_Spec(nor, lv, shi.view, ma->param[2], ma->param[3]); Index: source/blender/blenkernel/intern/material.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/material.c,v retrieving revision 1.30 diff -u -r1.30 material.c --- source/blender/blenkernel/intern/material.c 25 Jul 2005 09:19:23 -0000 1.30 +++ source/blender/blenkernel/intern/material.c 25 Sep 2005 15:04:24 -0000 @@ -101,7 +101,10 @@ ma->param[2]= 0.5; ma->param[3]= 0.1; ma->rms=0.1; - ma->darkness=1.0; + ma->darkness=1.0; + ma->roughu=1.0; + ma->roughv=1.0; + ma->ks=0.4; ma->ang= 1.0; ma->ray_depth= 2; Index: source/blender/blenloader/intern/readfile.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/blenloader/intern/readfile.c,v retrieving revision 1.191 diff -u -r1.191 readfile.c --- source/blender/blenloader/intern/readfile.c 24 Sep 2005 14:19:37 -0000 1.191 +++ source/blender/blenloader/intern/readfile.c 25 Sep 2005 15:05:15 -0000 @@ -4849,6 +4849,7 @@ bArmature *arm; Mesh *me; Scene *sce= main->scene.first; + Material *ma; while(sce){ if(sce->toolsettings == NULL){ @@ -4875,6 +4876,16 @@ } } + + /* init new shader vars */ + for (ma= main->mat.first; ma; ma= ma->id.next) { + if(ma->roughu==0.0) { + ma->roughu=1.0f; + ma->roughv=1.0f; + ma->ks=0.4; + } + } + for(ob=main->object.first; ob; ob= ob->id.next) { ModifierData *md; Index: source/blender/makesdna/DNA_material_types.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_material_types.h,v retrieving revision 1.28 diff -u -r1.28 DNA_material_types.h --- source/blender/makesdna/DNA_material_types.h 27 May 2005 17:52:52 -0000 1.28 +++ source/blender/makesdna/DNA_material_types.h 25 Sep 2005 15:05:25 -0000 @@ -85,6 +85,8 @@ float param[4]; /* size, smooth, size, smooth, for toonshader */ float rms; float darkness; + float roughu, roughv; + float ks,pad6; short texco, mapto; /* ramp colors */ @@ -166,6 +168,7 @@ #define MA_SPEC_BLINN 2 #define MA_SPEC_TOON 3 #define MA_SPEC_WARDISO 4 +#define MA_SPEC_ASHIKHMIN 5 /* dynamode */ #define MA_DRAW_DYNABUTS 1 Index: source/blender/render/extern/include/render.h =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/render/extern/include/render.h,v retrieving revision 1.17 diff -u -r1.17 render.h --- source/blender/render/extern/include/render.h 25 Aug 2005 13:11:04 -0000 1.17 +++ source/blender/render/extern/include/render.h 25 Sep 2005 15:05:33 -0000 @@ -171,13 +171,14 @@ struct EnvMap *RE_copy_envmap(struct EnvMap *env); /* --------------------------------------------------------------------- */ -/* rendercore (12) */ +/* rendercore (13) */ /* --------------------------------------------------------------------- */ float Phong_Spec(float *n, float *l, float *v, int hard); float CookTorr_Spec(float *n, float *l, float *v, int hard); float Blinn_Spec(float *n, float *l, float *v, float refrac, float spec_power); float Toon_Spec( float *n, float *l, float *v, float size, float smooth); float WardIso_Spec(float *n, float *l, float *v, float rms); +float Ashikhmin_Spec( float *n, float *l, float *v, float roughu, float roughv, float ks); float OrenNayar_Diff(float *n, float *l, float *v, float rough); float Toon_Diff( float *n, float *l, float *v, float size, float smooth); float Minnaert_Diff( float nl, float *n, float *v, float darkness); Index: source/blender/render/intern/source/rendercore.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/render/intern/source/rendercore.c,v retrieving revision 1.123 diff -u -r1.123 rendercore.c --- source/blender/render/intern/source/rendercore.c 25 Aug 2005 13:11:04 -0000 1.123 +++ source/blender/render/intern/source/rendercore.c 25 Sep 2005 15:06:08 -0000 @@ -860,6 +860,69 @@ return i; } +/* Ashikhmin anisotropic specular*/ +float Ashikhmin_Spec(float *n, float *l, float *v, float roughu, float roughv, float ks) +{ + float i, nh, nl, nv, hv, hu, hw, hl, h[3], w[3], u[3], roughuend, roughvend, fresnel_frac, d, div, exp=0.0; + + /* half-way vector */ + h[0] = l[0] + v[0]; + h[1] = l[1] + v[1]; + h[2] = l[2] + v[2]; + Normalise(h); + + /* tangent & bitangent vectors */ + /* TODO: To can select main anisotropic axis */ + if ((n[0]==0.f) && (n[2]==0.f)) { + u[0] = (n[1]<0.f) ? -1.f : 1.f; + u[1] = u[2] = 0.f; + w[2] = 1.f; + w[0] = w[1] = 0.f; + } + else { + d = 1.f/sqrt(n[2]*n[2] + n[0]*n[0]); + u[0] = n[2]*d; + u[1] = 0.0; + u[2] = -n[0]*d; + Crossf(w, u, n); + Normalise(w); + } + + nh = n[0]*h[0] + n[1]*h[1] + n[2]*h[2]; /* Dot product between surface normal and half-way vector */ + if (nh<=0.0) return 0.0; + + nl = n[0]*l[0] + n[1]*l[1] + n[2]*l[2]; /* Dot product between surface normal and light vector */ + if (nl<=0.0) return 0.0; + + nv = n[0]*v[0] + n[1]*v[1] + n[2]*v[2]; /* Dot product between surface normal and view vector */ + if (nv<=0.0) nv = 0.0; + + hl = h[0]*l[0] + h[1]*l[1] + h[2]*l[2]; /* Dot product between light vector and half-way vector */ + if (hl<=0.0) hl = 0.0; + + hv = h[0]*v[0] + h[1]*v[1] + h[2]*v[2]; /* Dot product between view vector and half-way vector */ + if (hv<=0.0) hv = 0.0; + + hu = h[0]*u[0] + h[1]*u[1] + h[2]*u[2]; /* Dot product between rough u direction and half-way vector */ + hw = h[0]*w[0] + h[1]*w[1] + h[2]*w[2]; /* Dot product between rough v direction and half-way vector */ + + /* Make easier to tweak Nu & Nv parameters */ + roughuend = pow (10, roughu); + roughvend = pow (10, roughv); + + /* Schlick's approximation to Fresnel fraction */ + fresnel_frac = ks + ((1.0 - ks) * pow((1.0 - MAX2(hv,hl)), 5)); + + /* Anisotropic Phong model */ + div = 1.0 - pow(nh, 2); + if (div > 0.0) + exp = ((roughuend * hu * hu) + (roughvend * hw *hw)) / div; + + i = nl * (sqrt((roughuend + 1.0)*(roughvend + 1.0)) / (8.0 * PI * (MAX2(hv,hl) * MAX2(nv,nl)))) * pow(nh,exp) * fresnel_frac; + + return i; +} + /* cartoon render diffuse */ float Toon_Diff( float *n, float *l, float *v, float size, float smooth ) { @@ -1657,6 +1720,8 @@ specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har); else if(ma->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec( vn, lv, view, ma->rms); + else if(ma->spec_shader==MA_SPEC_ASHIKHMIN) + specfac= Ashikhmin_Spec(vn, lv, view, ma->roughu, ma->roughv, ma->ks); else specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]); Index: source/blender/src/buttons_shading.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_shading.c,v retrieving revision 1.146 diff -u -r1.146 buttons_shading.c --- source/blender/src/buttons_shading.c 22 Sep 2005 19:47:31 -0000 1.146 +++ source/blender/src/buttons_shading.c 25 Sep 2005 15:07:20 -0000 @@ -2989,7 +2989,7 @@ } else { char *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2|Minnaert %x3"; - char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3|WardIso %x4"; + char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3|WardIso %x4|Ashikhmin %x5"; /* diff shader buttons */ uiDefButS(block, MENU, B_MATPRV_DRAW, str1, 9, 180,78,19, &(ma->diff_shader), 0.0, 0.0, 0, 0, "Creates a diffuse shader"); @@ -3021,7 +3021,13 @@ uiDefButF(block, NUMSLI, B_MATPRV, "Smooth:",90, 80,150,19, &(ma->param[3]), 0.0, 1.0, 0, 0, "Sets the smoothness of specular toon area"); } if(ma->spec_shader==MA_SPEC_WARDISO) - uiDefButF(block, NUMSLI, B_MATPRV, "rms:", 90, 100,150,19, &(ma->rms), 0.0, 0.4, 0, 0, "Sets the standard deviation of surface slope"); + uiDefButF(block, NUMSLI, B_MATPRV, "rms:", 90, 100,150,19, &(ma->rms), 0.0, 0.4, 0, 0, "Sets the standard deviation of surface slope"); + if(ma->spec_shader==MA_SPEC_ASHIKHMIN) { + uiDefButF(block, NUMSLI, B_MATPRV, "Nu: ", 90,100,150,19, &(ma->roughu), 0.0, 3.0, 0, 0, "Sets the direction u of the roughness"); + uiDefButF(block, NUMSLI, B_MATPRV, "Nv: ",90,80,150,19, &(ma->roughv), 0.0, 3.0, 0, 0, "Sets the direction v of the roughness"); + uiDefButF(block, NUMSLI, B_MATPRV, "Ks: ",90,60,150,19, &(ma->ks), 0.0, 1.0, 0, 0, "Sets the material's reflectance for the normal incidence"); + } + /* default shading variables */ uiBlockBeginAlign(block); uiDefButF(block, NUMSLI, B_DIFF, "Translucency ", 9,30,301,19, &(ma->translucency), 0.0, 1.0, 100, 2, "Amount of diffuse shading of the back side"); Index: source/blender/src/previewrender.c =================================================================== RCS file: /cvsroot/bf-blender/blender/source/blender/src/previewrender.c,v retrieving revision 1.60 diff -u -r1.60 previewrender.c --- source/blender/src/previewrender.c 25 Aug 2005 13:11:04 -0000 1.60 +++ source/blender/src/previewrender.c 25 Sep 2005 15:07:35 -0000 @@ -890,6 +890,8 @@ specfac= Blinn_Spec(shi->vn, lv, shi->view, mat->refrac, (float)shi->har); else if(mat->spec_shader==MA_SPEC_WARDISO) specfac= WardIso_Spec(shi->vn, lv, shi->view, mat->rms); + else if(mat->spec_shader==MA_SPEC_ASHIKHMIN) + specfac= Ashikhmin_Spec(shi->vn, lv, shi->view, mat->roughu, mat->roughv, mat->ks); else specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3]);