[tuhopuu-devel] Ward isotropic gaussian specular shader
Jorge Bernal (lordloki)
jbernalmartinez at gmail.com
Thu Jan 27 18:24:55 CET 2005
Hi,
This is the implementation of Ward isotropic gaussian specular shader that is
showned in this paper:
http://radsite.lbl.gov/radiance/papers/sg92/paper.html
This shader works well to simulate plastic, principally.
regards
Jorge
-------------- next part --------------
Index: source/blender/blenkernel/bad_level_call_stubs/stubs.c
===================================================================
RCS file: /cvsroot/tuhopuu/tuhopuu3/source/blender/blenkernel/bad_level_call_stubs/stubs.c,v
retrieving revision 1.3
diff -u -r1.3 stubs.c
--- source/blender/blenkernel/bad_level_call_stubs/stubs.c 13 Jan 2005 12:25:55 -0000 1.3
+++ source/blender/blenkernel/bad_level_call_stubs/stubs.c 27 Jan 2005 17:03:31 -0000
@@ -97,6 +97,7 @@
float Blinn_Spec(float *n, float *l, float *v, float a, float b){return 0;}
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 Toon_Diff(float *n, float *l, float *v, float a, float b){return 0;}
float OrenNayar_Diff(float *n, float *l, float *v, float a, float b){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/tuhopuu/tuhopuu3/source/blender/blenkernel/intern/displist.c,v
retrieving revision 1.4
diff -u -r1.4 displist.c
--- source/blender/blenkernel/intern/displist.c 15 Jan 2005 18:12:21 -0000 1.4
+++ source/blender/blenkernel/intern/displist.c 27 Jan 2005 17:04:17 -0000
@@ -703,6 +703,8 @@
specfac= CookTorr_Spec(nor, lv, shi.view, shi.har);
else if(ma->spec_shader==MA_SPEC_BLINN)
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
specfac= Toon_Spec(nor, lv, shi.view, ma->param[2], ma->param[3]);
Index: source/blender/makesdna/DNA_material_types.h
===================================================================
RCS file: /cvsroot/tuhopuu/tuhopuu3/source/blender/makesdna/DNA_material_types.h,v
retrieving revision 1.4
diff -u -r1.4 DNA_material_types.h
--- source/blender/makesdna/DNA_material_types.h 25 Jan 2005 17:24:58 -0000 1.4
+++ source/blender/makesdna/DNA_material_types.h 27 Jan 2005 17:04:42 -0000
@@ -84,7 +84,7 @@
float roughness, refrac;
float param[4]; /* size, smooth, size, smooth, for toonshader */
short texco, mapto;
- float minnaert_darkness, pad1;
+ float minnaert_darkness, rms;
/* ramp colors */
struct ColorBand *ramp_col;
@@ -160,6 +160,7 @@
#define MA_SPEC_PHONG 1
#define MA_SPEC_BLINN 2
#define MA_SPEC_TOON 3
+#define MA_SPEC_WARDISO 4
/* dynamode */
#define MA_DRAW_DYNABUTS 1
Index: source/blender/render/extern/include/render.h
===================================================================
RCS file: /cvsroot/tuhopuu/tuhopuu3/source/blender/render/extern/include/render.h,v
retrieving revision 1.3
diff -u -r1.3 render.h
--- source/blender/render/extern/include/render.h 13 Jan 2005 12:25:55 -0000 1.3
+++ source/blender/render/extern/include/render.h 27 Jan 2005 17:04:47 -0000
@@ -176,12 +176,13 @@
struct EnvMap *RE_copy_envmap(struct EnvMap *env);
/* --------------------------------------------------------------------- */
-/* rendercore (11) */
+/* rendercore (12) */
/* --------------------------------------------------------------------- */
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 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/tuhopuu/tuhopuu3/source/blender/render/intern/source/rendercore.c,v
retrieving revision 1.5
diff -u -r1.5 rendercore.c
--- source/blender/render/intern/source/rendercore.c 25 Jan 2005 17:24:58 -0000 1.5
+++ source/blender/render/intern/source/rendercore.c 27 Jan 2005 17:05:17 -0000
@@ -779,6 +779,34 @@
return rslt;
}
+/* Ward isotropic gaussian spec */
+float WardIso_Spec( float *n, float *l, float *v, float rms)
+{
+ float i, nh, nv, nl, h[3], angle, alpha;
+
+ /* half-way vector */
+ h[0] = l[0] + v[0];
+ h[1] = l[1] + v[1];
+ h[2] = l[2] + v[2];
+ Normalise(h);
+
+ 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) nh = 0.001;
+
+ 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.001;
+
+ 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) nl = 0.001;
+
+ angle = tan(acos(nh));
+ alpha = MAX2(rms,0.001);
+
+ i=(1.0/(4*PI*alpha*alpha)) * (exp( -(angle*angle)/(alpha*alpha))/(sqrt(nv*nl)));
+
+ return i;
+}
+
/* cartoon render diffuse */
float Toon_Diff( float *n, float *l, float *v, float size, float smooth )
{
@@ -1584,6 +1612,8 @@
specfac= CookTorr_Spec(vn, lv, view, shi->har);
else if(ma->spec_shader==MA_SPEC_BLINN)
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
specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3]);
Index: source/blender/src/buttons_shading.c
===================================================================
RCS file: /cvsroot/tuhopuu/tuhopuu3/source/blender/src/buttons_shading.c,v
retrieving revision 1.5
diff -u -r1.5 buttons_shading.c
--- source/blender/src/buttons_shading.c 25 Jan 2005 17:24:58 -0000 1.5
+++ source/blender/src/buttons_shading.c 27 Jan 2005 17:06:34 -0000
@@ -2858,7 +2858,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";
+ char *str2= "Specular Shader%t|CookTorr %x0|Phong %x1|Blinn %x2|Toon %x3|WardIso %x4";
/* 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");
@@ -2889,6 +2889,8 @@
uiDefButF(block, NUMSLI, B_MATPRV, "Size:", 90, 100,150,19, &(ma->param[2]), 0.0, 1.53, 0, 0, "Sets the size of specular toon area");
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");
/* default shading variables */
uiBlockBeginAlign(block);
Index: source/blender/src/previewrender.c
===================================================================
RCS file: /cvsroot/tuhopuu/tuhopuu3/source/blender/src/previewrender.c,v
retrieving revision 1.4
diff -u -r1.4 previewrender.c
--- source/blender/src/previewrender.c 25 Jan 2005 17:24:58 -0000 1.4
+++ source/blender/src/previewrender.c 27 Jan 2005 17:06:57 -0000
@@ -877,6 +877,8 @@
specfac= CookTorr_Spec(shi->vn, lv, shi->view, shi->har);
else if(mat->spec_shader==MA_SPEC_BLINN)
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
specfac= Toon_Spec(shi->vn, lv, shi->view, mat->param[2], mat->param[3]);
More information about the tuhopuu-devel
mailing list