[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34548] trunk/blender: new bumpmapping options for the renderer
M.G. Kishalmi
lmg at kishalmi.net
Sat Jan 29 12:56:13 CET 2011
Revision: 34548
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34548
Author: lmg
Date: 2011-01-29 11:56:11 +0000 (Sat, 29 Jan 2011)
Log Message:
-----------
new bumpmapping options for the renderer
oldbump -> original
newbump -> compatible
*new* -> default (3tap)
*new* -> best quality (5tap)
the latter two have an option to apply bumpmapping in
viewspace - much like displacement mapping
objectspace - default (scales with the object)
texturespace - much like normal mapping (scales)
Modified Paths:
--------------
trunk/blender/release/scripts/ui/properties_texture.py
trunk/blender/source/blender/blenkernel/intern/material.c
trunk/blender/source/blender/blenkernel/intern/texture.c
trunk/blender/source/blender/blenloader/intern/readfile.c
trunk/blender/source/blender/makesdna/DNA_texture_types.h
trunk/blender/source/blender/makesrna/intern/rna_material.c
trunk/blender/source/blender/render/intern/include/texture.h
trunk/blender/source/blender/render/intern/source/texture.c
Modified: trunk/blender/release/scripts/ui/properties_texture.py
===================================================================
--- trunk/blender/release/scripts/ui/properties_texture.py 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/release/scripts/ui/properties_texture.py 2011-01-29 11:56:11 UTC (rev 34548)
@@ -994,11 +994,6 @@
# color is used on grayscale textures even when use_rgb_to_intensity is disabled.
col.prop(tex, "color", text="")
- if isinstance(idblock, bpy.types.Material):
- sub = layout.row()
- sub.prop(tex, "bump_method", text="Bump Method")
- sub.active = tex.use_map_normal
-
col = split.column()
col.prop(tex, "invert", text="Negative")
col.prop(tex, "use_stencil")
@@ -1006,7 +1001,22 @@
if isinstance(idblock, bpy.types.Material) or isinstance(idblock, bpy.types.World):
col.prop(tex, "default_value", text="DVar", slider=True)
+ if isinstance(idblock, bpy.types.Material):
+ row = layout.row()
+ row.label(text="Bump Mapping:")
+ row = layout.row()
+ # only show bump settings if activated but not for normalmap images
+ row.active = tex.use_map_normal and not( tex.texture.type == 'IMAGE' and tex.texture.use_normal_map )
+
+ col = row.column()
+ col.prop(tex, "bump_method", text="Method")
+
+ col = row.column()
+ col.prop(tex, "bump_objectspace", text="Space")
+ col.active = tex.bump_method in ('BUMP_DEFAULT', 'BUMP_BEST_QUALITY')
+
+
class TEXTURE_PT_custom_props(TextureButtonsPanel, PropertyPanel, bpy.types.Panel):
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
_context_path = "texture"
Modified: trunk/blender/source/blender/blenkernel/intern/material.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/material.c 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/blenkernel/intern/material.c 2011-01-29 11:56:11 UTC (rev 34548)
@@ -820,7 +820,7 @@
/* always get derivatives for these textures */
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;
+ else if(mtex->texflag & (MTEX_COMPAT_BUMP|MTEX_3TAP_BUMP|MTEX_5TAP_BUMP)) ma->texco |= TEXCO_OSA;
if(ma->texco & (TEXCO_ORCO|TEXCO_REFL|TEXCO_NORM|TEXCO_STRAND|TEXCO_STRESS)) needuv= 1;
else if(ma->texco & (TEXCO_GLOB|TEXCO_UV|TEXCO_OBJECT|TEXCO_SPEED)) needuv= 1;
Modified: trunk/blender/source/blender/blenkernel/intern/texture.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/texture.c 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/blenkernel/intern/texture.c 2011-01-29 11:56:11 UTC (rev 34548)
@@ -630,7 +630,8 @@
mtex->size[1]= 1.0;
mtex->size[2]= 1.0;
mtex->tex= 0;
- mtex->texflag= MTEX_NEW_BUMP;
+ mtex->texflag= MTEX_3TAP_BUMP;
+ mtex->texflag= MTEX_BUMP_OBJECTSPACE;
mtex->colormodel= 0;
mtex->r= 1.0;
mtex->g= 0.0;
Modified: trunk/blender/source/blender/blenloader/intern/readfile.c
===================================================================
--- trunk/blender/source/blender/blenloader/intern/readfile.c 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/blenloader/intern/readfile.c 2011-01-29 11:56:11 UTC (rev 34548)
@@ -9991,12 +9991,15 @@
for(a=0; a<MAX_MTEX; a++) {
if(ma->mtex[a]) {
tex= ma->mtex[a]->tex;
- if(!tex)
- ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
- else {
+ if(!tex) {
+ ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
+ ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
+ } else {
tex= (Tex*)newlibadr(fd, ma->id.lib, tex);
- if(tex && tex->type == 0) /* invalid type */
- ma->mtex[a]->texflag |= MTEX_NEW_BUMP;
+ if(tex && tex->type == 0) { /* invalid type */
+ ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
+ ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
+ }
}
}
}
Modified: trunk/blender/source/blender/makesdna/DNA_texture_types.h
===================================================================
--- trunk/blender/source/blender/makesdna/DNA_texture_types.h 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/makesdna/DNA_texture_types.h 2011-01-29 11:56:11 UTC (rev 34548)
@@ -454,7 +454,11 @@
#define MTEX_VIEWSPACE 16
#define MTEX_DUPLI_MAPTO 32
#define MTEX_OB_DUPLI_ORIG 64
-#define MTEX_NEW_BUMP 128
+#define MTEX_COMPAT_BUMP 128
+#define MTEX_3TAP_BUMP 256
+#define MTEX_5TAP_BUMP 512
+#define MTEX_BUMP_OBJECTSPACE 1024
+#define MTEX_BUMP_TEXTURESPACE 2048
/* blendtype */
#define MTEX_BLEND 0
Modified: trunk/blender/source/blender/makesrna/intern/rna_material.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_material.c 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/makesrna/intern/rna_material.c 2011-01-29 11:56:11 UTC (rev 34548)
@@ -378,9 +378,17 @@
static EnumPropertyItem prop_bump_method_items[] = {
{0, "BUMP_ORIGINAL", 0, "Original", ""},
- {MTEX_NEW_BUMP, "BUMP_IMPROVED", 0, "Improved", ""},
+ {MTEX_COMPAT_BUMP, "BUMP_COMPATIBLE", 0, "Compatible", ""},
+ {MTEX_3TAP_BUMP, "BUMP_DEFAULT", 0, "Default", ""},
+ {MTEX_5TAP_BUMP, "BUMP_BEST_QUALITY", 0, "Best Quality", ""},
{0, NULL, 0, NULL, NULL}};
+ static EnumPropertyItem prop_bump_space_items[] = {
+ {0, "BUMP_VIEWSPACE", 0, "ViewSpace", ""},
+ {MTEX_BUMP_OBJECTSPACE, "BUMP_OBJECTSPACE", 0, "ObjectSpace", ""},
+ {MTEX_BUMP_TEXTURESPACE, "BUMP_TEXTURESPACE", 0, "TextureSpace", ""},
+ {0, NULL, 0, NULL, NULL}};
+
srna= RNA_def_struct(brna, "MaterialTextureSlot", "TextureSlot");
RNA_def_struct_sdna(srna, "MTex");
RNA_def_struct_ui_text(srna, "Material Texture Slot", "Texture slot for textures in a Material datablock");
@@ -687,6 +695,12 @@
RNA_def_property_enum_items(prop, prop_bump_method_items);
RNA_def_property_ui_text(prop, "Bump Method", "Method to use for bump mapping");
RNA_def_property_update(prop, 0, "rna_Material_update");
+
+ prop= RNA_def_property(srna, "bump_objectspace", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_bitflag_sdna(prop, NULL, "texflag");
+ RNA_def_property_enum_items(prop, prop_bump_space_items);
+ RNA_def_property_ui_text(prop, "Bump Space", "Space to apply bump mapping in");
+ RNA_def_property_update(prop, 0, "rna_Material_update");
}
static void rna_def_material_colors(StructRNA *srna)
Modified: trunk/blender/source/blender/render/intern/include/texture.h
===================================================================
--- trunk/blender/source/blender/render/intern/include/texture.h 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/render/intern/include/texture.h 2011-01-29 11:56:11 UTC (rev 34548)
@@ -48,6 +48,7 @@
hsv_to_rgb(_hsv[0], _hsv[1], _hsv[2], &texres->tr, &texres->tg, &texres->tb); \
} \
+#define RGBTOBW(r,g,b) ( r*0.35 + g*0.45 + b*0.2 ) /* keep this in sync with gpu_shader_material.glsl:rgbtobw */
struct HaloRen;
struct ShadeInput;
Modified: trunk/blender/source/blender/render/intern/source/texture.c
===================================================================
--- trunk/blender/source/blender/render/intern/source/texture.c 2011-01-29 09:47:48 UTC (rev 34547)
+++ trunk/blender/source/blender/render/intern/source/texture.c 2011-01-29 11:56:11 UTC (rev 34548)
@@ -1607,6 +1607,7 @@
do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt);
// translate and scale
+ /*
texvec[0] = mtex->size[0]*(texvec[0] - 0.5f) + mtex->ofs[0] + 0.5f;
texvec[1] = mtex->size[1]*(texvec[1] - 0.5f) + mtex->ofs[1] + 0.5f;
if (shi->osatex) {
@@ -1615,6 +1616,7 @@
dyt[0] = mtex->size[0]*dyt[0];
dyt[1] = mtex->size[1]*dyt[1];
}
+ */
/* problem: repeat-mirror is not a 'repeat' but 'extend' in imagetexture.c */
// TXF: bug was here, only modify texvec when repeat mode set, old code affected other modes too.
@@ -1667,6 +1669,410 @@
}
}
+/* Bump code from 2.5 development cycle, has a number of bugs, but here for compatibility */
+
+typedef struct CompatibleBump {
+ float nu[3], nv[3], nn[3];
+ float dudnu, dudnv, dvdnu, dvdnv;
+ int nunvdone;
+} CompatibleBump;
+
+static void compatible_bump_init(CompatibleBump *compat_bump)
+{
+ memset(compat_bump, 0, sizeof(*compat_bump));
+
+ compat_bump->dudnu = 1.0f;
+ compat_bump->dvdnv = 1.0f;
+}
+
+static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *shi, MTex *mtex, int i)
+{
+ // uvmapping only, calculation of normal tangent u/v partial derivatives
+ // (should not be here, dudnu, dudnv, dvdnu & dvdnv should probably be part of ShadeInputUV struct,
+ // nu/nv in ShadeInput and this calculation should then move to shadeinput.c, shade_input_set_shade_texco() func.)
+ // NOTE: test for shi->obr->ob here, since vlr/obr/obi can be 'fake' when called from fastshade(), another reason to move it..
+ // NOTE: shi->v1 is NULL when called from displace_render_vert, assigning verts in this case is not trivial because the shi quad face side is not know.
+ if ((mtex->texflag & MTEX_COMPAT_BUMP) && shi->obr && shi->obr->ob && shi->v1) {
+ if(mtex->mapto & (MAP_NORM|MAP_WARP) && !((mtex->tex->type==TEX_IMAGE) && (mtex->tex->imaflag & TEX_NORMALMAP))) {
+ MTFace* tf = RE_vlakren_get_tface(shi->obr, shi->vlr, i, NULL, 0);
+ int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
+
+ vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
+
+ // compute ortho basis around normal
+ if(!compat_bump->nunvdone) {
+ // render normal is negated
+ compat_bump->nn[0] = -shi->vn[0];
+ compat_bump->nn[1] = -shi->vn[1];
+ compat_bump->nn[2] = -shi->vn[2];
+ ortho_basis_v3v3_v3(compat_bump->nu, compat_bump->nv, compat_bump->nn);
+ compat_bump->nunvdone= 1;
+ }
+
+ if (tf) {
+ float *uv1 = tf->uv[j1], *uv2 = tf->uv[j2], *uv3 = tf->uv[j3];
+ const float an[3] = {fabsf(compat_bump->nn[0]), fabsf(compat_bump->nn[1]), fabsf(compat_bump->nn[2])};
+ const int a1 = (an[0] > an[1] && an[0] > an[2]) ? 1 : 0;
+ const int a2 = (an[2] > an[0] && an[2] > an[1]) ? 1 : 2;
+ const float dp1_a1 = shi->v1->co[a1] - shi->v3->co[a1];
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list