[tuhopuu-devel] Minnaert diffuse shader

Jorge Bernal jbernalmartinez at gmail.com
Sun Jan 9 12:10:17 CET 2005


Hi 
Following the suggestion of Jonathan Merritt I post this here.

I have made a patch that implement the Minnaert diffuse shader.
There are two possible models, the "official" and the nvidia's model.
The model that I implemented is the nvidia's model.
You can see a comparison of both models in this link:
http://accad.osu.edu/~bwatkins/ADC/Hw6/hw.html#minnaert
Also you can view two movies of the two models.

This shader principally is used to simulate cloth (specially velvet),
sun or moon or another light reflection over the water, and others.

you can see a comparison with lambert and oren-nayar shaders in the
same conditions of reflexion in this link:
ftp://ftp.berlios.de/pub/worldspace/tmp/blender/COMPARACION.JPG

The patch is attached to the mail 
Also you can prove a blender's build here:
ftp://ftp.berlios.de/pub/worldspace/tmp/blender/blender-2.36-linux-glibc2.3.3-i386.tar.gz

regards
jorge Bernal
-------------- next part --------------
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.20
diff -u -r1.20 stubs.c
--- source/blender/blenkernel/bad_level_call_stubs/stubs.c	27 Dec 2004 19:28:48 -0000	1.20
+++ source/blender/blenkernel/bad_level_call_stubs/stubs.c	8 Jan 2005 22:58:50 -0000
@@ -99,6 +99,7 @@
 float Toon_Spec(float *n, float *l, float *v, float a, float b){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 *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.53
diff -u -r1.53 displist.c
--- source/blender/blenkernel/intern/displist.c	27 Dec 2004 19:28:49 -0000	1.53
+++ source/blender/blenkernel/intern/displist.c	8 Jan 2005 22:59:28 -0000
@@ -673,6 +673,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(nor, lv, shi.view, ma->darkness);
 		}
 		
 		back= 0;
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.24
diff -u -r1.24 DNA_material_types.h
--- source/blender/makesdna/DNA_material_types.h	29 Dec 2004 17:04:14 -0000	1.24
+++ source/blender/makesdna/DNA_material_types.h	8 Jan 2005 22:59:40 -0000
@@ -81,6 +81,7 @@
 	/* shaders */
 	short diff_shader, spec_shader;
 	float roughness, refrac;
+	float darkness, pad1;
 	float param[4];		/* size, smooth, size, smooth, for toonshader */
 	short texco, mapto;
 	
@@ -151,6 +152,7 @@
 #define MA_DIFF_LAMBERT		0
 #define MA_DIFF_ORENNAYAR	1
 #define MA_DIFF_TOON		2
+#define MA_DIFF_MINNAERT        3
 
 /* spec_shader */
 #define MA_SPEC_COOKTORR	0
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.12
diff -u -r1.12 render.h
--- source/blender/render/extern/include/render.h	7 Jan 2005 14:11:00 -0000	1.12
+++ source/blender/render/extern/include/render.h	8 Jan 2005 22:59:47 -0000
@@ -176,7 +176,7 @@
 struct EnvMap *RE_copy_envmap(struct EnvMap *env);
 
 /* --------------------------------------------------------------------- */
-/* rendercore (10)                                                        */
+/* rendercore (11)                                                        */
 /* --------------------------------------------------------------------- */
 float Phong_Spec(float *n, float *l, float *v, int hard);
 float CookTorr_Spec(float *n, float *l, float *v, int hard);
@@ -184,6 +184,7 @@
 float Toon_Spec( float *n, float *l, float *v, float size, float smooth);
 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 *n, float *l, float *v, float darkness);
 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.102
diff -u -r1.102 rendercore.c
--- source/blender/render/intern/source/rendercore.c	8 Jan 2005 14:45:58 -0000	1.102
+++ source/blender/render/intern/source/rendercore.c	8 Jan 2005 23:00:16 -0000
@@ -865,6 +865,21 @@
 	return OrenNayar_Diff_i(nl, n, l, v, rough);
 }
 
+/* Minnaert diffuse */
+float Minnaert_Diff(float *n, float *l, float *v, float darkness)
+{
+	float i, nv, nl;
+
+	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.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;
+
+	i = nl * pow (nl, darkness) * pow ( (1.001 - nv), (1 - darkness) );
+	return i;
+}
+
 
 /* --------------------------------------------- */
 /* also called from texture.c */
@@ -1477,6 +1492,7 @@
 			/* diffuse shaders (oren nayer gets inp from area light) */
 			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(vn, lv, view, ma->darkness);
 			else is= inp;	// Lambert
 		}
 		
Index: source/blender/src/buttons_shading.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_shading.c,v
retrieving revision 1.117
diff -u -r1.117 buttons_shading.c
--- source/blender/src/buttons_shading.c	8 Jan 2005 21:16:24 -0000	1.117
+++ source/blender/src/buttons_shading.c	8 Jan 2005 23:01:14 -0000
@@ -2854,7 +2854,7 @@
 		uiBlockEndAlign(block);
 	}
 	else {
-		char *str1= "Diffuse Shader%t|Lambert %x0|Oren-Nayar %x1|Toon %x2";
+		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";
 		
 		/* diff shader buttons */
@@ -2868,6 +2868,8 @@
 			uiDefButF(block, NUMSLI, B_MATPRV, "Size:",	90, 160,150,19, &(ma->param[0]), 0.0, 3.14, 0, 0, "Sets size of diffuse toon area");
 			uiDefButF(block, NUMSLI, B_MATPRV, "Smooth:",90,140,150,19, &(ma->param[1]), 0.0, 1.0, 0, 0, "Sets smoothness of diffuse toon area");
 		}
+		else if(ma->diff_shader==MA_DIFF_MINNAERT)
+                        uiDefButF(block, NUMSLI, B_MATPRV, "Dark:",90,160, 150,19, &(ma->darkness), 0, 2.0, 0, 0, "Sets Minnaert darkness");
 		uiBlockEndAlign(block);
 		
 		/* spec shader buttons */
Index: source/blender/src/previewrender.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/previewrender.c,v
retrieving revision 1.46
diff -u -r1.46 previewrender.c
--- source/blender/src/previewrender.c	7 Jan 2005 21:48:25 -0000	1.46
+++ source/blender/src/previewrender.c	8 Jan 2005 23:01:27 -0000
@@ -896,6 +896,7 @@
 			/* diffuse shaders */
 			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(shi->vn, lv, shi->view, mat->darkness);
 			// else Lambert
 			
 			inp= (shi->refl*is + shi->emit);


More information about the tuhopuu-devel mailing list