[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [21771] branches/blender2.5/blender: 2.5: Bump Mapping

Brecht Van Lommel brecht at blender.org
Tue Jul 21 15:46:49 CEST 2009


Revision: 21771
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=21771
Author:   blendix
Date:     2009-07-21 15:46:49 +0200 (Tue, 21 Jul 2009)

Log Message:
-----------
2.5: Bump Mapping

Patch by Alfredo de Greef. Considerably improves the quality of bump
mapping, and texture filtering for displacement and warp too. Mainly
this is achieved by getting the texture derivatives just right in
various cases, many thanks to Alfredo for figuring this one out, works
great.


This is enabled by default now, but disabled still for existing
textures to preserve backwards compatibility. Can be enabled with
the "New Bump" option in the material texture slot in the outliner.

Also, I made the range for the normal factor a bit smaller since this
gives stronger effects, but note that you can still type in larger
values than the slider allows.

Modified Paths:
--------------
    branches/blender2.5/blender/release/ui/buttons_data_mesh.py
    branches/blender2.5/blender/source/blender/blenkernel/intern/material.c
    branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c
    branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
    branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
    branches/blender2.5/blender/source/blender/makesdna/DNA_texture_types.h
    branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c
    branches/blender2.5/blender/source/blender/render/intern/source/convertblender.c
    branches/blender2.5/blender/source/blender/render/intern/source/shadeinput.c
    branches/blender2.5/blender/source/blender/render/intern/source/texture.c

Modified: branches/blender2.5/blender/release/ui/buttons_data_mesh.py
===================================================================
--- branches/blender2.5/blender/release/ui/buttons_data_mesh.py	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/release/ui/buttons_data_mesh.py	2009-07-21 13:46:49 UTC (rev 21771)
@@ -49,6 +49,14 @@
 		sub.itemR(mesh, "vertex_normal_flip")
 		sub.itemR(mesh, "double_sided")
 
+		row = layout.row(align=True)
+		if context.edit_object:
+			row.itemO("MESH_OT_faces_shade_smooth")
+			row.itemO("MESH_OT_faces_shade_flat")
+		else:
+			row.itemO("OBJECT_OT_shade_smooth")
+			row.itemO("OBJECT_OT_shade_flat")
+
 class DATA_PT_vertex_groups(DataButtonsPanel):
 	__idname__ = "DATA_PT_vertex_groups"
 	__label__ = "Vertex Groups"

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/material.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/material.c	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/material.c	2009-07-21 13:46:49 UTC (rev 21771)
@@ -671,6 +671,7 @@
 			ma->mapto |= mtex->mapto;
 			if(r_mode & R_OSA) {
 				if ELEM3(mtex->tex->type, TEX_IMAGE, TEX_PLUGIN, TEX_ENVMAP) ma->texco |= TEXCO_OSA;
+				else if(mtex->texflag & MTEX_NEW_BUMP) ma->texco |= TEXCO_OSA; // NEWBUMP: need texture derivatives for procedurals as well
 			}
 			
 			if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;

Modified: branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/blenkernel/intern/texture.c	2009-07-21 13:46:49 UTC (rev 21771)
@@ -534,7 +534,7 @@
 	mtex->size[1]= 1.0;
 	mtex->size[2]= 1.0;
 	mtex->tex= 0;
-	mtex->texflag= 0;
+	mtex->texflag= MTEX_NEW_BUMP;
 	mtex->colormodel= 0;
 	mtex->r= 1.0;
 	mtex->g= 0.0;
@@ -543,7 +543,7 @@
 	mtex->def_var= 1.0;
 	mtex->blendtype= MTEX_BLEND;
 	mtex->colfac= 1.0;
-	mtex->norfac= 0.5;
+	mtex->norfac= 1.0;
 	mtex->varfac= 1.0;
 	mtex->dispfac=0.2;
 	mtex->normapspace= MTEX_NSPACE_TANGENT;

Modified: branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/blenlib/intern/arithb.c	2009-07-21 13:46:49 UTC (rev 21771)
@@ -2197,25 +2197,23 @@
 
 void VecOrthoBasisf(float *v, float *v1, float *v2)
 {
-	float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]);
+	const float f = (float)sqrt(v[0]*v[0] + v[1]*v[1]);
 
 	if (f < 1e-35f) {
 		// degenerate case
-		v1[0] = 0.0f; v1[1] = 1.0f; v1[2] = 0.0f;
-		if (v[2] > 0.0f) {
-			v2[0] = 1.0f; v2[1] = v2[2] = 0.0f;
-		}
-		else {
-			v2[0] = -1.0f; v2[1] = v2[2] = 0.0f;
-		}
+		v1[0] = (v[2] < 0.0f) ? -1.0f : 1.0f;
+		v1[1] = v1[2] = v2[0] = v2[2] = 0.0f;
+		v2[1] = 1.0f;
 	}
 	else  {
-		f = 1.0f/f;
-		v1[0] = v[1]*f;
-		v1[1] = -v[0]*f;
-		v1[2] = 0.0f;
+		const float d= 1.0f/f;
 
-		Crossf(v2, v, v1);
+		v1[0] =  v[1]*d;
+		v1[1] = -v[0]*d;
+		v1[2] = 0.0f;
+		v2[0] = -v[2]*v1[1];
+		v2[1] = v[2]*v1[0];
+		v2[2] = v[0]*v1[1] - v[1]*v1[0];
 	}
 }
 

Modified: branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/blenloader/intern/readfile.c	2009-07-21 13:46:49 UTC (rev 21771)
@@ -9276,7 +9276,7 @@
 		Tex *tex;
 		Scene *sce;
 		ToolSettings *ts;
-		int i;
+		int i, a;
 
 		for(ob = main->object.first; ob; ob = ob->id.next) {
 
@@ -9351,15 +9351,26 @@
 		}
 
 		/* texture filter */
-		for(tex = main->tex.first; tex; tex = tex->id.next)
+		for(tex = main->tex.first; tex; tex = tex->id.next) {
 			if(tex->afmax == 0)
 				tex->afmax= 8;
+		}
 
 		for(ma = main->mat.first; ma; ma = ma->id.next) {
 			if(ma->mode & MA_HALO) {
 				ma->material_type= MA_TYPE_HALO;
 				ma->mode &= ~MA_HALO;
 			}
+
+			/* set new bump for unused slots */
+			for(a=0; a<MAX_MTEX; a++) {
+				if(ma->mtex[a]) {
+					if(!ma->mtex[a]->tex)
+						ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
+					else if(((Tex*)newlibadr(fd, ma->id.lib, ma->mtex[a]->tex))->type == 0)
+						ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
+				}
+			}
 		}
 
 		for(sce = main->scene.first; sce; sce = sce->id.next) {

Modified: branches/blender2.5/blender/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- branches/blender2.5/blender/source/blender/makesdna/DNA_texture_types.h	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/makesdna/DNA_texture_types.h	2009-07-21 13:46:49 UTC (rev 21771)
@@ -373,6 +373,7 @@
 #define MTEX_VIEWSPACE		16
 #define MTEX_DUPLI_MAPTO	32
 #define MTEX_OB_DUPLI_ORIG	64
+#define MTEX_NEW_BUMP		128
 
 /* blendtype */
 #define MTEX_BLEND		0

Modified: branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c
===================================================================
--- branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c	2009-07-21 13:21:14 UTC (rev 21770)
+++ branches/blender2.5/blender/source/blender/makesrna/intern/rna_material.c	2009-07-21 13:46:49 UTC (rev 21771)
@@ -231,99 +231,122 @@
 	RNA_def_property_enum_sdna(prop, NULL, "texco");
 	RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
 	RNA_def_property_ui_text(prop, "Texture Coordinates", "");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 
 	prop= RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
 	RNA_def_property_pointer_sdna(prop, NULL, "object");
 	RNA_def_property_struct_type(prop, "Object");
 	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates.");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 
 	prop= RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "uvname");
 	RNA_def_property_ui_text(prop, "UV Layer", "UV layer to use for mapping with UV texture coordinates.");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 
 	prop= RNA_def_property(srna, "from_dupli", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_DUPLI_MAPTO);
 	RNA_def_property_ui_text(prop, "From Dupli", "Dupli's instanced from verts, faces or particles, inherit texture coordinate from their parent.");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 
 	prop= RNA_def_property(srna, "from_original", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_OB_DUPLI_ORIG);
 	RNA_def_property_ui_text(prop, "From Original", "Dupli's derive their object coordinates from the original objects transformation.");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 
 	prop= RNA_def_property(srna, "map_colordiff", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COL);
 	RNA_def_property_ui_text(prop, "Diffuse Color", "Causes the texture to affect basic color of the material");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_normal", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_NORM);
 	RNA_def_property_ui_text(prop, "Normal", "Causes the texture to affect the rendered normal");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_colorspec", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLSPEC);
 	RNA_def_property_ui_text(prop, "Specular Color", "Causes the texture to affect the specularity color");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_mirror", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLMIR);
 	RNA_def_property_ui_text(prop, "Mirror", "Causes the texture to affect the mirror color");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_diffuse", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REF);
 	RNA_def_property_ui_text(prop, "Diffuse", "Causes the texture to affect the value of the materials diffuse reflectivity");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_specular", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SPEC);
 	RNA_def_property_ui_text(prop, "Specular", "Causes the texture to affect the value of specular reflectivity");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_ambient", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_AMB);
 	RNA_def_property_ui_text(prop, "Ambient", "Causes the texture to affect the value of ambient");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_hardness", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_HAR);
 	RNA_def_property_ui_text(prop, "Hardness", "Causes the texture to affect the hardness value");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_raymir", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_RAYMIRR);
 	RNA_def_property_ui_text(prop, "Ray-Mirror", "Causes the texture to affect the ray-mirror value");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_alpha", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_ALPHA);
 	RNA_def_property_ui_text(prop, "Alpha", "Causes the texture to affect the alpha value");
+	RNA_def_property_update(prop, NC_TEXTURE, NULL);
 	
 	prop= RNA_def_property(srna, "map_emit", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMIT);
 	RNA_def_property_ui_text(prop, "Emit", "Causes the texture to affect the emit value");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list