[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41533] branches/cycles: Cycles: add location/rotate/scale and XYZ mapping options for all texture nodes,

Brecht Van Lommel brechtvanlommel at pandora.be
Fri Nov 4 21:58:02 CET 2011


Revision: 41533
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41533
Author:   blendix
Date:     2011-11-04 20:58:00 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
Cycles: add location/rotate/scale and XYZ mapping options for all texture nodes,
to reduce the amount of nodes needed to set up a simple texture.

These are currently editable in the texture properties tab, still need to make
them available in the node editor. Projection and color modification options will
be added later, they're not implemented yet but allocated already to avoid
version patches later.

Also an issue with the XYZ mapping is that when you set one to None, texture and
material draw mode doesn't draw the image texture well, OpenGL doesn't seem to
like the degenerate texture matrix?

Modified Paths:
--------------
    branches/cycles/intern/cycles/blender/addon/ui.py
    branches/cycles/intern/cycles/blender/blender_shader.cpp
    branches/cycles/intern/cycles/render/nodes.cpp
    branches/cycles/intern/cycles/render/nodes.h
    branches/cycles/source/blender/blenkernel/BKE_texture.h
    branches/cycles/source/blender/blenkernel/intern/texture.c
    branches/cycles/source/blender/blenloader/intern/readfile.c
    branches/cycles/source/blender/editors/include/ED_uvedit.h
    branches/cycles/source/blender/editors/interface/interface_node.c
    branches/cycles/source/blender/editors/sculpt_paint/paint_image.c
    branches/cycles/source/blender/editors/space_image/space_image.c
    branches/cycles/source/blender/editors/space_node/drawnode.c
    branches/cycles/source/blender/editors/space_node/node_draw.c
    branches/cycles/source/blender/editors/space_view3d/drawmesh.c
    branches/cycles/source/blender/editors/uvedit/uvedit_ops.c
    branches/cycles/source/blender/makesdna/DNA_node_types.h
    branches/cycles/source/blender/makesdna/DNA_texture_types.h
    branches/cycles/source/blender/makesrna/intern/rna_nodetree.c
    branches/cycles/source/blender/makesrna/intern/rna_nodetree_types.h
    branches/cycles/source/blender/makesrna/intern/rna_space.c
    branches/cycles/source/blender/makesrna/intern/rna_texture.c
    branches/cycles/source/blender/nodes/composite/nodes/node_composite_mapValue.c
    branches/cycles/source/blender/nodes/shader/node_shader_util.c
    branches/cycles/source/blender/nodes/shader/node_shader_util.h
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_mapping.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_blend.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_clouds.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_distnoise.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_image.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_marble.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_sky.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_stucci.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
    branches/cycles/source/blender/nodes/shader/nodes/node_shader_tex_wood.c

Modified: branches/cycles/intern/cycles/blender/addon/ui.py
===================================================================
--- branches/cycles/intern/cycles/blender/addon/ui.py	2011-11-04 20:21:40 UTC (rev 41532)
+++ branches/cycles/intern/cycles/blender/addon/ui.py	2011-11-04 20:58:00 UTC (rev 41533)
@@ -311,7 +311,7 @@
     @classmethod
     def poll(cls, context):
         ob = context.object
-        return ob and ob.type in ('MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META') # todo: 'LAMP'
+        return CyclesButtonsPanel.poll(context) and ob and ob.type in ('MESH', 'CURVE', 'CURVE', 'SURFACE', 'FONT', 'META') # todo: 'LAMP'
 
     def draw(self, context):
         layout = self.layout
@@ -604,24 +604,65 @@
 
     def draw(self, context):
         layout = self.layout
-        layout.label("Texture coordinate mapping goes here.");
-        layout.label("Translate, rotate, scale, projection, XYZ.")
 
-class CyclesTexture_PT_color(CyclesButtonsPanel, Panel):
+        tex = context.texture
+        node = context.texture_node
+
+        mapping = node.texture_mapping
+
+        row = layout.row()
+
+        row.column().prop(mapping, "location")
+        row.column().prop(mapping, "rotation")
+        row.column().prop(mapping, "scale")
+
+        layout.label(text="Projection:")
+
+        row = layout.row()
+        row.prop(mapping, "mapping_x", text="")
+        row.prop(mapping, "mapping_y", text="")
+        row.prop(mapping, "mapping_z", text="")
+
+class CyclesTexture_PT_colors(CyclesButtonsPanel, Panel):
     bl_label = "Color"
     bl_context = "texture"
+    bl_options = {'DEFAULT_CLOSED'}
 
     @classmethod
     def poll(cls, context):
         tex = context.texture
         node = context.texture_node
-        return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
+        return False
+        #return (node or (tex and tex.use_nodes)) and CyclesButtonsPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
-        layout.label("Color modification options go here.");
-        layout.label("Ramp, brightness, contrast, saturation.")
 
+        tex = context.texture
+        node = context.texture_node
+
+        mapping = node.color_mapping
+
+        split = layout.split()
+
+        col = split.column()
+        col.label(text="Blend:")
+        col.prop(mapping, "blend_type", text="")
+        col.prop(mapping, "blend_factor", text="Factor")
+        col.prop(mapping, "blend_color", text="")
+
+        col = split.column()
+        col.label(text="Adjust:")
+        col.prop(mapping, "brightness")
+        col.prop(mapping, "contrast")
+        col.prop(mapping, "saturation")
+
+        layout.separator()
+
+        layout.prop(mapping, "use_color_ramp", text="Ramp")
+        if mapping.use_color_ramp:
+            layout.template_color_ramp(mapping, "color_ramp", expand=True)
+
 def draw_device(self, context):
     scene = context.scene
     layout = self.layout

Modified: branches/cycles/intern/cycles/blender/blender_shader.cpp
===================================================================
--- branches/cycles/intern/cycles/blender/blender_shader.cpp	2011-11-04 20:21:40 UTC (rev 41532)
+++ branches/cycles/intern/cycles/blender/blender_shader.cpp	2011-11-04 20:58:00 UTC (rev 41533)
@@ -97,6 +97,17 @@
 	return sock.default_value();
 }
 
+static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping b_mapping)
+{
+	mapping->translation = get_float3(b_mapping.location());
+	mapping->rotation = get_float3(b_mapping.rotation())*(M_PI/180.0f); /* in degrees! */
+	mapping->scale = get_float3(b_mapping.scale());
+
+	mapping->x_mapping = (TextureMapping::Mapping)b_mapping.mapping_x();
+	mapping->y_mapping = (TextureMapping::Mapping)b_mapping.mapping_y();
+	mapping->z_mapping = (TextureMapping::Mapping)b_mapping.mapping_z();
+}
+
 static ShaderNode *add_node(BL::BlendData b_data, ShaderGraph *graph, BL::Node *b_group_node, BL::ShaderNode b_node)
 {
 	ShaderNode *node = NULL;
@@ -163,10 +174,7 @@
 			BL::ShaderNodeMapping b_mapping_node(b_node);
 			MappingNode *mapping = new MappingNode();
 
-			TextureMapping *tex_mapping = &mapping->tex_mapping;
-			tex_mapping->translation = get_float3(b_mapping_node.location());
-			tex_mapping->rotation = get_float3(b_mapping_node.rotation());
-			tex_mapping->scale = get_float3(b_mapping_node.scale());
+			get_tex_mapping(&mapping->tex_mapping, b_mapping_node.mapping());
 
 			node = mapping;
 			break;
@@ -293,6 +301,7 @@
 			if(b_image)
 				image->filename = blender_absolute_path(b_data, b_image, b_image.filepath());
 			image->color_space = ImageTextureNode::color_space_enum[(int)b_image_node.color_space()];
+			get_tex_mapping(&image->tex_mapping, b_image_node.texture_mapping());
 			node = image;
 			break;
 		}
@@ -303,11 +312,15 @@
 			if(b_image)
 				env->filename = blender_absolute_path(b_data, b_image, b_image.filepath());
 			env->color_space = EnvironmentTextureNode::color_space_enum[(int)b_env_node.color_space()];
+			get_tex_mapping(&env->tex_mapping, b_env_node.texture_mapping());
 			node = env;
 			break;
 		}
 		case BL::ShaderNode::type_TEX_NOISE: {
-			node = new NoiseTextureNode();
+			BL::ShaderNodeTexNoise b_noise_node(b_node);
+			NoiseTextureNode *noise = new NoiseTextureNode();
+			get_tex_mapping(&noise->tex_mapping, b_noise_node.texture_mapping());
+			node = noise;
 			break;
 		}
 		case BL::ShaderNode::type_TEX_BLEND: {
@@ -315,6 +328,7 @@
 			BlendTextureNode *blend = new BlendTextureNode();
 			blend->progression = BlendTextureNode::progression_enum[(int)b_blend_node.progression()];
 			blend->axis = BlendTextureNode::axis_enum[(int)b_blend_node.axis()];
+			get_tex_mapping(&blend->tex_mapping, b_blend_node.texture_mapping());
 			node = blend;
 			break;
 		}
@@ -323,6 +337,7 @@
 			VoronoiTextureNode *voronoi = new VoronoiTextureNode();
 			voronoi->distance_metric = VoronoiTextureNode::distance_metric_enum[(int)b_voronoi_node.distance_metric()];
 			voronoi->coloring = VoronoiTextureNode::coloring_enum[(int)b_voronoi_node.coloring()];
+			get_tex_mapping(&voronoi->tex_mapping, b_voronoi_node.texture_mapping());
 			node = voronoi;
 			break;
 		}
@@ -330,6 +345,7 @@
 			BL::ShaderNodeTexMagic b_magic_node(b_node);
 			MagicTextureNode *magic = new MagicTextureNode();
 			magic->depth = b_magic_node.turbulence_depth();
+			get_tex_mapping(&magic->tex_mapping, b_magic_node.texture_mapping());
 			node = magic;
 			break;
 		}
@@ -341,6 +357,7 @@
 			marble->type = MarbleTextureNode::type_enum[(int)b_marble_node.marble_type()];
 			marble->wave = MarbleTextureNode::wave_enum[(int)b_marble_node.wave_type()];
 			marble->hard = b_marble_node.noise_type() == BL::ShaderNodeTexMarble::noise_type_HARD;
+			get_tex_mapping(&marble->tex_mapping, b_marble_node.texture_mapping());
 			node = marble;
 			break;
 		}
@@ -350,6 +367,7 @@
 			clouds->depth = b_clouds_node.turbulence_depth();
 			clouds->basis = CloudsTextureNode::basis_enum[(int)b_clouds_node.noise_basis()];
 			clouds->hard = b_clouds_node.noise_type() == BL::ShaderNodeTexClouds::noise_type_HARD;
+			get_tex_mapping(&clouds->tex_mapping, b_clouds_node.texture_mapping());
 			node = clouds;
 			break;
 		}
@@ -360,6 +378,7 @@
 			wood->basis = WoodTextureNode::basis_enum[(int)b_wood_node.noise_basis()];
 			wood->hard = b_wood_node.noise_type() == BL::ShaderNodeTexWood::noise_type_HARD;
 			wood->wave = WoodTextureNode::wave_enum[(int)b_wood_node.wave_type()];
+			get_tex_mapping(&wood->tex_mapping, b_wood_node.texture_mapping());
 			node = wood;
 			break;
 		}
@@ -368,6 +387,7 @@
 			MusgraveTextureNode *musgrave = new MusgraveTextureNode();
 			musgrave->type = MusgraveTextureNode::type_enum[(int)b_musgrave_node.musgrave_type()];
 			musgrave->basis = MusgraveTextureNode::basis_enum[(int)b_musgrave_node.noise_basis()];
+			get_tex_mapping(&musgrave->tex_mapping, b_musgrave_node.texture_mapping());
 			node = musgrave;
 			break;
 		}
@@ -377,6 +397,7 @@
 			stucci->type = StucciTextureNode::type_enum[(int)b_stucci_node.stucci_type()];
 			stucci->basis = StucciTextureNode::basis_enum[(int)b_stucci_node.noise_basis()];
 			stucci->hard = b_stucci_node.noise_type() == BL::ShaderNodeTexStucci::noise_type_HARD;
+			get_tex_mapping(&stucci->tex_mapping, b_stucci_node.texture_mapping());
 			node = stucci;
 			break;
 		}
@@ -385,6 +406,7 @@
 			DistortedNoiseTextureNode *distnoise = new DistortedNoiseTextureNode();
 			distnoise->basis = DistortedNoiseTextureNode::basis_enum[(int)b_distnoise_node.noise_basis()];
 			distnoise->distortion_basis = DistortedNoiseTextureNode::basis_enum[(int)b_distnoise_node.noise_distortion()];
+			get_tex_mapping(&distnoise->tex_mapping, b_distnoise_node.texture_mapping());
 			node = distnoise;
 			break;
 		}
@@ -397,6 +419,7 @@
 			SkyTextureNode *sky = new SkyTextureNode();
 			sky->sun_direction = get_float3(b_sky_node.sun_direction());
 			sky->turbidity = b_sky_node.turbidity();
+			get_tex_mapping(&sky->tex_mapping, b_sky_node.texture_mapping());
 			node = sky;
 			break;
 		}

Modified: branches/cycles/intern/cycles/render/nodes.cpp
===================================================================
--- branches/cycles/intern/cycles/render/nodes.cpp	2011-11-04 20:21:40 UTC (rev 41532)
+++ branches/cycles/intern/cycles/render/nodes.cpp	2011-11-04 20:58:00 UTC (rev 41533)
@@ -45,11 +45,11 @@
 	Transform mmat = transform_scale(make_float3(0.0f, 0.0f, 0.0f));
 
 	if(x_mapping != NONE)
-		mmat[0][x_mapping] = 1.0f;
+		mmat[0][x_mapping-1] = 1.0f;
 	if(y_mapping != NONE)
-		mmat[1][y_mapping] = 1.0f;
+		mmat[1][y_mapping-1] = 1.0f;
 	if(z_mapping != NONE)
-		mmat[2][z_mapping] = 1.0f;
+		mmat[2][z_mapping-1] = 1.0f;
 
 	Transform smat = transform_scale(scale);
 	Transform rmat = transform_euler(rotation);

Modified: branches/cycles/intern/cycles/render/nodes.h
===================================================================
--- branches/cycles/intern/cycles/render/nodes.h	2011-11-04 20:21:40 UTC (rev 41532)
+++ branches/cycles/intern/cycles/render/nodes.h	2011-11-04 20:58:00 UTC (rev 41533)
@@ -41,7 +41,7 @@
 	float3 rotation;
 	float3 scale;
 
-	enum Mapping { X=0, Y=1, Z=2, NONE };
+	enum Mapping { NONE=0, X=1, Y=2, Z=3 };
 	Mapping x_mapping, y_mapping, z_mapping;
 
 	enum Projection { FLAT, CUBE, TUBE, SPHERE };

Modified: branches/cycles/source/blender/blenkernel/BKE_texture.h
===================================================================

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list