[Bf-committers] normalmap patch

Alfredo de Greef bf-committers@blender.org
Thu, 15 Jan 2004 12:53:23 -0800 (PST)


--0-1288649249-1074200003=:85714
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

There have been some requests for normalmap support
for some time now. I don't really know if it is all
that useful or not, but for those who want to try this
in Blender, here is a small patch. This only allows
you to use normalmaps for bumpmapping, it doesn't
create normalmaps. It adds a 'NorMap' button to the
image texture panel, when enabled and used with
bumpmapping, it will use the encoded normals from the
image directly instead of calculating it from the
image intensities.
I hope the patch contains less 'noise' this time...

Alfredo

__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus
--0-1288649249-1074200003=:85714
Content-Type: text/plain; name="patch.txt"
Content-Description: patch.txt
Content-Disposition: inline; filename="patch.txt"

? Makefile.in
? aclocal.m4
? autom4te.cache
? config.h.in
? configure
? intern/Makefile.in
? intern/SoundSystem/Makefile.in
? intern/bmfont/Makefile.in
? intern/bsp/Makefile.in
? intern/container/Makefile.in
? intern/decimation/Makefile.in
? intern/ghost/Makefile.in
? intern/guardedalloc/Makefile.in
? intern/iksolver/Makefile.in
? intern/memutil/Makefile.in
? intern/moto/Makefile.in
? intern/string/Makefile.in
? source/Makefile.in
? source/blender/Makefile.in
? source/blender/avi/Makefile.in
? source/blender/blenkernel/Makefile.in
? source/blender/blenlib/Makefile.in
? source/blender/blenloader/Makefile.in
? source/blender/blenpluginapi/Makefile.in
? source/blender/deflate/Makefile.in
? source/blender/imbuf/Makefile.in
? source/blender/img/Makefile.in
? source/blender/inflate/Makefile.in
? source/blender/makesdna/Makefile.in
? source/blender/makesdna/intern/Makefile.in
? source/blender/python/Makefile.in
? source/blender/python/api2_2x/Makefile.in
? source/blender/quicktime/Makefile.in
? source/blender/radiosity/Makefile.in
? source/blender/readblenfile/Makefile.in
? source/blender/readstreamglue/Makefile.in
? source/blender/render/Makefile.in
? source/blender/renderconverter/Makefile.in
? source/blender/src/Makefile.in
? source/blender/writeblenfile/Makefile.in
? source/blender/writestreamglue/Makefile.in
? source/blender/yafray/Makefile.in
? source/creator/Makefile.in
? source/gameengine/Makefile.in
? source/gameengine/BlenderRoutines/Makefile.in
? source/gameengine/Converter/Makefile.in
? source/gameengine/Expressions/Makefile.in
? source/gameengine/GameLogic/Makefile.in
? source/gameengine/GamePlayer/Makefile.in
? source/gameengine/Ketsji/Makefile.in
? source/gameengine/Network/Makefile.in
? source/gameengine/Physics/Makefile.in
? source/gameengine/Rasterizer/Makefile.in
? source/gameengine/SceneGraph/Makefile.in
? source/icons/Makefile.in
? source/kernel/Makefile.in
Index: source/blender/blenkernel/intern/image.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/blenkernel/intern/image.c,v
retrieving revision 1.4
diff -u -r1.4 image.c
--- source/blender/blenkernel/intern/image.c	26 Apr 2003 11:56:44 -0000	1.4
+++ source/blender/blenkernel/intern/image.c	15 Jan 2004 20:21:18 -0000
@@ -670,25 +670,33 @@
 		Tb = ((float)rect[2])/255.0f;
 		
 		if(tex->nor) {
-			/* bump: take three samples */
-			val1= Tr+Tg+Tb;
-
-			if(x<ibuf->x-1) {
-				rect+=4;
-				val2= ((float)(rect[0]+rect[1]+rect[2]))/255.0f;
-				rect-=4;
+			if (tex->imaflag & TEX_NORMALMAP) {
+				/* normalmap: rgb as normalvectors */
+				tex->nor[0] = (0.5-Tr)*2.0;
+				tex->nor[1] = (0.5-Tg)*2.0;
+				tex->nor[2] = (0.5-Tb)*2.0;
 			}
-			else val2= val1;
+			else {
+				/* bump: take three samples */
+				val1= Tr+Tg+Tb;
 
-			if(y<ibuf->y-1) {
-				rect+= 4*ibuf->x;
-				val3= ((float)(rect[0]+rect[1]+rect[2]))/255.0f;
-			}
-			else val3= val1;
+				if(x<ibuf->x-1) {
+					rect+=4;
+					val2= ((float)(rect[0]+rect[1]+rect[2]))/255.0f;
+					rect-=4;
+				}
+				else val2= val1;
+
+				if(y<ibuf->y-1) {
+					rect+= 4*ibuf->x;
+					val3= ((float)(rect[0]+rect[1]+rect[2]))/255.0f;
+				}
+				else val3= val1;
 
-			/* do not mix up x and y here! */
-			tex->nor[0]= (val1-val2);
-			tex->nor[1]= (val1-val3);
+				/* do not mix up x and y here! */
+				tex->nor[0]= (val1-val2);
+				tex->nor[1]= (val1-val3);
+			}
 		}
 
 		BRICONRGB;
@@ -1362,45 +1370,77 @@
 			}
 			
 			if(tex->nor) {
-				/* a bit extra filter */
-				minx*= 1.35f;
-				miny*= 1.35f;
-				
-				boxsample(ibuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &Tr, &Tg, &Tb, &Ta);
-				val1= Tr+Tg+Tb;
-				boxsample(ibuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
-				val2= fac1+fac2+fac3;
-				boxsample(ibuf, fx-2.0f*minx, fy-miny, fx+minx, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
-				val3= fac1+fac2+fac3;
-	
-				if(previbuf!=ibuf) {  /* interpolate */
-					
-					boxsample(previbuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
-					
-					/* calc rgb */
-					dx= 2.0f*(pixsize-maxd)/pixsize;
-					if(dx>=1.0f) {
-						Ta= fac4; Tb= fac3;
-						Tg= fac2; Tr= fac1;
+				if (tex->imaflag & TEX_NORMALMAP) {
+					/* normalmap: rgb as normalvectors */
+					maxx= fx+minx;
+					minx= fx-minx;
+					maxy= fy+miny;
+					miny= fy-miny;
+
+					boxsample(ibuf, minx, miny, maxx, maxy, &Tr, &Tg, &Tb, &Ta);
+
+					if(previbuf!=ibuf) {  /* interpolate */
+						boxsample(previbuf, minx, miny, maxx, maxy, &fac1, &fac2, &fac3, &fac4);
+
+						fx= 2.0f*(pixsize-maxd)/pixsize;
+
+						if(fx>=1.0) {
+							Ta= fac4; Tb= fac3;
+							Tg= fac2; Tr= fac1;
+						} else {
+							fy= 1.0f-fx;
+							Tb= fy*Tb+ fx*fac3;
+							Tg= fy*Tg+ fx*fac2;
+							Tr= fy*Tr+ fx*fac1;
+							if(Talpha) Ta= fy*Ta+ fx*fac4;
+						}
 					}
-					else {
-						dy= 1.0f-dx;
-						Tb= dy*Tb+ dx*fac3;
-						Tg= dy*Tg+ dx*fac2;
-						Tr= dy*Tr+ dx*fac1;
-						if(Talpha) Ta= dy*Ta+ dx*fac4;
-					}
-					
-					val1= dy*val1+ dx*(fac1+fac2+fac3);
-					boxsample(previbuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
-					val2= dy*val2+ dx*(fac1+fac2+fac3);
-					boxsample(previbuf, fx-2.0f*minx, fy-miny, fx+minx, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
-					val3= dy*val3+ dx*(fac1+fac2+fac3);
+
+					tex->nor[0] = (0.5-Tr)*2.0;
+					tex->nor[1] = (0.5-Tg)*2.0;
+					tex->nor[2] = (0.5-Tb)*2.0;
 				}
+				else {
+					/* a bit extra filter */
+					minx*= 1.35f;
+					miny*= 1.35f;
+
+					boxsample(ibuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &Tr, &Tg, &Tb, &Ta);
+					val1= Tr+Tg+Tb;
+					boxsample(ibuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
+					val2= fac1+fac2+fac3;
+					boxsample(ibuf, fx-2.0f*minx, fy-miny, fx+minx, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
+					val3= fac1+fac2+fac3;
+
+					if(previbuf!=ibuf) {  /* interpolate */
+
+						boxsample(previbuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
+
+						/* calc rgb */
+						dx= 2.0f*(pixsize-maxd)/pixsize;
+						if(dx>=1.0f) {
+							Ta= fac4; Tb= fac3;
+							Tg= fac2; Tr= fac1;
+						}
+						else {
+							dy= 1.0f-dx;
+							Tb= dy*Tb+ dx*fac3;
+							Tg= dy*Tg+ dx*fac2;
+							Tr= dy*Tr+ dx*fac1;
+							if(Talpha) Ta= dy*Ta+ dx*fac4;
+						}
+
+						val1= dy*val1+ dx*(fac1+fac2+fac3);
+						boxsample(previbuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
+						val2= dy*val2+ dx*(fac1+fac2+fac3);
+						boxsample(previbuf, fx-2.0f*minx, fy-miny, fx+minx, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
+						val3= dy*val3+ dx*(fac1+fac2+fac3);
+					}
 
-				/* don't switch x or y! */
-				tex->nor[0]= (val1-val2);
-				tex->nor[1]= (val1-val3);
+					/* don't switch x or y! */
+					tex->nor[0]= (val1-val2);
+					tex->nor[1]= (val1-val3);
+				}
 
 			}
 			else {
@@ -1438,23 +1478,35 @@
 
 			if(tex->nor) {
 				
-				/* a bit extra filter */
-				minx*= 1.35f;
-				miny*= 1.35f;
-				
-				boxsample(ibuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &Tr, &Tg, &Tb, &Ta);
-				val1= Tr+Tg+Tb;
-
-				boxsample(ibuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
-				val2= fac1+fac2+fac3;
-				
-				boxsample(ibuf, fx-2.0f*minx, fy-miny, fx+miny, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
-				val3= fac1+fac2+fac3;
-
-				/* don't switch x or y! */
-				tex->nor[0]= (val1-val2);
-				tex->nor[1]= (val1-val3);
-				
+				if (tex->imaflag & TEX_NORMALMAP) {
+					/* normalmap: rgb as normalvectors */
+					maxx= fx+minx;
+					minx= fx-minx;
+					maxy= fy+miny;
+					miny= fy-miny;
+					boxsample(ibuf, minx, miny, maxx, maxy, &fac1, &fac2, &fac3, &fac4);
+					tex->nor[0] = (0.5-fac1)*2.0;
+					tex->nor[1] = (0.5-fac2)*2.0;
+					tex->nor[2] = (0.5-fac3)*2.0;
+				}
+				else {
+					/* a bit extra filter */
+					minx*= 1.35f;
+					miny*= 1.35f;
+
+					boxsample(ibuf, fx-2.0f*minx, fy-2.0f*miny, fx+minx, fy+miny, &Tr, &Tg, &Tb, &Ta);
+					val1= Tr+Tg+Tb;
+
+					boxsample(ibuf, fx-minx, fy-2.0f*miny, fx+2.0f*minx, fy+miny, &fac1, &fac2, &fac3, &fac4);
+					val2= fac1+fac2+fac3;
+
+					boxsample(ibuf, fx-2.0f*minx, fy-miny, fx+miny, fy+2.0f*miny, &fac1, &fac2, &fac3, &fac4);
+					val3= fac1+fac2+fac3;
+
+					/* don't switch x or y! */
+					tex->nor[0]= (val1-val2);
+					tex->nor[1]= (val1-val3);
+				}
 			}
 			else {
 				boxsample(ibuf, fx-minx, fy-miny, fx+minx, fy+miny, &Tr, &Tg, &Tb, &Ta);
Index: source/blender/makesdna/DNA_texture_types.h
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/makesdna/DNA_texture_types.h,v
retrieving revision 1.9
diff -u -r1.9 DNA_texture_types.h
--- source/blender/makesdna/DNA_texture_types.h	15 Jan 2004 04:06:23 -0000	1.9
+++ source/blender/makesdna/DNA_texture_types.h	15 Jan 2004 20:21:19 -0000
@@ -174,6 +174,8 @@
 #define TEX_ANTIALI		256
 #define TEX_ANTISCALE	512
 #define TEX_STD_FIELD	1024
+/* image as normalmap */
+#define TEX_NORMALMAP	2048
 
 #define TEX_LASOPPATCH	8192
 #define TEX_MORKPATCH	16384
Index: source/blender/src/buttons_shading.c
===================================================================
RCS file: /cvsroot/bf-blender/blender/source/blender/src/buttons_shading.c,v
retrieving revision 1.59
diff -u -r1.59 buttons_shading.c
--- source/blender/src/buttons_shading.c	15 Jan 2004 04:06:24 -0000	1.59
+++ source/blender/src/buttons_shading.c	15 Jan 2004 20:21:23 -0000
@@ -926,10 +926,12 @@
 
 	/* types */
 	uiBlockBeginAlign(block);
-	uiDefButS(block, TOG|BIT|0, 0, "InterPol",			10, 180, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Interpolates pixels of the Image to fit texture mapping");
-	uiDefButS(block, TOG|BIT|1, B_TEXPRV, "UseAlpha",	85, 180, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Click to use Image's alpha channel");
-	uiDefButS(block, TOG|BIT|5, B_TEXPRV, "CalcAlpha",	160, 180, 75, 18, &tex->imaflag, 0, 0, 0, 0, "Click to calculate an alpha channel based on Image RGB values");
-	uiDefButS(block, TOG|BIT|2, B_TEXPRV, "NegAlpha",	235, 180, 75, 18, &tex->flag, 0, 0, 0, 0, "Click to invert the alpha values");
+	uiDefButS(block, TOG|BIT|0, 0, "InterPol",			10, 180, 60, 18, &tex->imaflag, 0, 0, 0, 0, "Interpolates pixels of the Image to fit texture mapping");
+	uiDefButS(block, TOG|BIT|1, B_TEXPRV, "UseAlpha",	70, 180, 60, 18, &tex->imaflag, 0, 0, 0, 0, "Click to use Image's alpha channel");
+	uiDefButS(block, TOG|BIT|5, B_TEXPRV, "CalcAlpha",	130, 180, 60, 18, &tex->imaflag, 0, 0, 0, 0, "Click to calculate an alpha channel based on Image RGB values");
+	uiDefButS(block, TOG|BIT|2, B_TEXPRV, "NegAlpha",	190, 180, 60, 18, &tex->flag, 0, 0, 0, 0, "Click to invert the alpha values");
+	/* normalmap addition */
+	uiDefButS(block, TOG|BIT|11, 0, "NorMap",			250, 180, 60, 18, &tex->imaflag, 0, 0, 0, 0, "Click to use image as normalmap");
 	
 	uiDefButS(block, TOG|BIT|2, B_IMAPTEST, "MipMap",	10, 160, 60, 18, &tex->imaflag, 0, 0, 0, 0, "Generates a series of pictures to use for mipmapping");
 	uiDefButS(block, TOG|BIT|3, B_IMAPTEST, "Fields",	70, 160, 50, 18, &tex->imaflag, 0, 0, 0, 0, "Click to enable use of fields in Image");

--0-1288649249-1074200003=:85714--