Page MenuHome

Ashikhmin_final.txt

File Metadata

Author
Jorge Bernal (lordloki)
Created
Nov 13 2013, 1:07 PM

Ashikhmin_final.txt

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 18 Sep 2005 20:24:06 -0000
@@ -112,9 +112,11 @@
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;}
+float Ashikhmin_Diff(float *n, float *l, float *v, float a){return 0;}
void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b){}
void ramp_diffuse_result(float *diff, ShadeInput *shi){}
void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec){}
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 18 Sep 2005 20:24:24 -0000
@@ -537,6 +537,7 @@
if(ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(nor, lv, shi.view, ma->roughness);
else if(ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(nor, lv, shi.view, ma->param[0], ma->param[1]);
else if(ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(is, nor, shi.view, ma->darkness);
+ else if(ma->diff_shader==MA_DIFF_ASHIKHMIN) is= Ashikhmin_Diff(nor, lv, shi.view, ma->spec_shader);
}
back= 0;
@@ -568,6 +569,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->spec_shader);
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 18 Sep 2005 20:24:54 -0000
@@ -101,7 +101,9 @@
ma->param[2]= 0.5;
ma->param[3]= 0.1;
ma->rms=0.1;
- ma->darkness=1.0;
+ ma->darkness=1.0;
+ ma->roughu=100.0;
+ ma->roughv=100.0;
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.188
diff -u -r1.188 readfile.c
--- source/blender/blenloader/intern/readfile.c 18 Sep 2005 13:27:11 -0000 1.188
+++ source/blender/blenloader/intern/readfile.c 18 Sep 2005 20:25:39 -0000
@@ -4847,6 +4847,7 @@
bArmature *arm;
Mesh *me;
Scene *sce= main->scene.first;
+ Material *ma;
while(sce){
if(sce->toolsettings == NULL){
@@ -4873,6 +4874,15 @@
}
}
+
+ /* init new shader vars */
+ for (ma= main->mat.first; ma; ma= ma->id.next) {
+ if(ma->roughu==0.0) {
+ ma->roughu=100.0f;
+ ma->roughv=100.0f;
+ }
+ }
+
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 18 Sep 2005 20:25:49 -0000
@@ -85,6 +85,7 @@
float param[4]; /* size, smooth, size, smooth, for toonshader */
float rms;
float darkness;
+ float roughu, roughv;
short texco, mapto;
/* ramp colors */
@@ -159,6 +160,7 @@
#define MA_DIFF_ORENNAYAR 1
#define MA_DIFF_TOON 2
#define MA_DIFF_MINNAERT 3
+#define MA_DIFF_ASHIKHMIN 4
/* spec_shader */
#define MA_SPEC_COOKTORR 0
@@ -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 18 Sep 2005 20:26:00 -0000
@@ -171,16 +171,18 @@
struct EnvMap *RE_copy_envmap(struct EnvMap *env);
/* --------------------------------------------------------------------- */
-/* rendercore (12) */
+/* rendercore (14) */
/* --------------------------------------------------------------------- */
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 spec_shader);
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);
+float Ashikhmin_Diff( float *n, float *l, float *v, float spec_shader);
void add_to_diffuse(float *diff, ShadeInput *shi, float is, float r, float g, float b);
void ramp_diffuse_result(float *diff, ShadeInput *shi);
void do_specular_ramp(ShadeInput *shi, float is, float t, float *spec);
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 18 Sep 2005 20:26:23 -0000
@@ -860,6 +860,66 @@
return i;
}
+/* Ashikhmin anisotropic specular*/
+float Ashikhmin_Spec(float *n, float *l, float *v, float roughu, float roughv, float spec_shader)
+{
+ float i, nh, nl, nv, hv, hu, hw, hl, h[3], w[3], u[3], 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 */
+
+ /* Schlick's approximation to Fresnel fraction */
+ if (spec_shader > 1.0) spec_shader = 1.0;
+ fresnel_frac = spec_shader + ((1.0 - spec_shader) * pow((1.0 - MAX2(hv,hl)), 5));
+
+ /* Anisotropic Phong model */
+ div = 1.0 - pow(nh, 2);
+ if (div > 0.0)
+ exp = ((roughu * hu * hu) + (roughv * hw *hw)) / div;
+
+ i = nl * (sqrt((roughu + 1.0)*(roughv + 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 )
{
@@ -969,6 +1029,24 @@
return i;
}
+/* Ashikhmin diffuse */
+float Ashikhmin_Diff(float *n, float *l, float *v, float spec_shader)
+{
+ float i, nl, nv;
+
+ 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) 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;
+
+ if (spec_shader > 1.0) spec_shader = 1.0;
+
+ i = (28.0*nl/(23.0*PI)) * (1.0 - spec_shader) * (1.0 - pow((1.0 - (0.5*nl)), 5)) * (1.0 - pow((1.0 - (0.5*nv)),5));
+
+ return i;
+}
+
/* --------------------------------------------- */
/* also called from texture.c */
void calc_R_ref(ShadeInput *shi)
@@ -1581,6 +1659,7 @@
if(ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff_i(inp, vn, lv, view, ma->roughness);
else if(ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]);
else if(ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(inp, vn, view, ma->darkness);
+ else if(ma->diff_shader==MA_DIFF_ASHIKHMIN) is= Ashikhmin_Diff(vn, lv, view, ma->spec_shader);
else is= inp; // Lambert
}
@@ -1657,6 +1736,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->spec_shader);
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.143
diff -u -r1.143 buttons_shading.c
--- source/blender/src/buttons_shading.c 3 Sep 2005 10:50:21 -0000 1.143
+++ source/blender/src/buttons_shading.c 18 Sep 2005 20:27:21 -0000
@@ -2987,8 +2987,8 @@
uiBlockEndAlign(block);
}
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 *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2|Minnaert %x3|Ashikhmin %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");
@@ -3020,7 +3020,12 @@
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, 10000.0, 0, 0, "Sets the direction u of the roughness");
+ uiDefButF(block, NUMSLI, B_MATPRV, "Nv: ",90,80,150,19, &(ma->roughv), 0.0, 10000.0, 0, 0, "Sets the direction v of the roughness");
+ }
+
/* 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 18 Sep 2005 20:27: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->spec_shader);
else
specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3]);
@@ -913,6 +915,7 @@
if(mat->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(shi->vn, lv, shi->view, mat->roughness);
else if(mat->diff_shader==MA_DIFF_TOON) is= Toon_Diff(shi->vn, lv, shi->view, mat->param[0], mat->param[1]);
else if(mat->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(is, shi->vn, shi->view, mat->darkness);
+ else if(mat->diff_shader==MA_DIFF_ASHIKHMIN) is= Ashikhmin_Diff(shi->vn, lv, shi->view, mat->spec_shader);
// else Lambert
inp= (shi->refl*is + shi->emit);

Event Timeline