Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-09-26 00:28:49 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-09-26 00:28:49 +0400
commitc3d3d8be3675e284cbe269b4173c3cc15ce762ae (patch)
treedeff4134588923edb71ba8f7823562773957f6b7 /intern
parente9859bb0e59cd54a5d682a0fc484e2366d5e54fe (diff)
Fix cycles issue with mapping node rotation and scale order. When using both
scale and rotation in mapping node, there would be shearing, and the only way to avoid that was to add 2 mapping nodes. This is because to transform the texture, the inverse transform needs to be done on the texture coordinate Now the mapping node has Texture/Point/Vector/Normal types to transform the vector for a particular purpose. Point is the existing behavior, Texture is the new default that behaves more like you might expect.
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/addon/ui.py2
-rw-r--r--intern/cycles/blender/blender_shader.cpp2
-rw-r--r--intern/cycles/render/nodes.cpp51
-rw-r--r--intern/cycles/render/nodes.h3
4 files changed, 56 insertions, 2 deletions
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py
index 5fa497776fe..34585260cdb 100644
--- a/intern/cycles/blender/addon/ui.py
+++ b/intern/cycles/blender/addon/ui.py
@@ -1085,6 +1085,8 @@ class CyclesTexture_PT_mapping(CyclesButtonsPanel, Panel):
mapping = node.texture_mapping
+ layout.prop(mapping, "type", expand=True)
+
row = layout.row()
row.column().prop(mapping, "translation")
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 2007171642f..d915d51dfd8 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -147,6 +147,7 @@ static void get_tex_mapping(TextureMapping *mapping, BL::TexMapping b_mapping)
mapping->translation = get_float3(b_mapping.translation());
mapping->rotation = get_float3(b_mapping.rotation());
mapping->scale = get_float3(b_mapping.scale());
+ mapping->type = (TextureMapping::Type)b_mapping.type();
mapping->x_mapping = (TextureMapping::Mapping)b_mapping.mapping_x();
mapping->y_mapping = (TextureMapping::Mapping)b_mapping.mapping_y();
@@ -161,6 +162,7 @@ static void get_tex_mapping(TextureMapping *mapping, BL::ShaderNodeMapping b_map
mapping->translation = get_float3(b_mapping.translation());
mapping->rotation = get_float3(b_mapping.rotation());
mapping->scale = get_float3(b_mapping.scale());
+ mapping->type = (TextureMapping::Type)b_mapping.type();
mapping->use_minmax = b_mapping.use_min() || b_mapping.use_max();
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 658deb87cff..35b8a151587 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -42,6 +42,8 @@ TextureMapping::TextureMapping()
y_mapping = Y;
z_mapping = Z;
+ type = TEXTURE;
+
projection = FLAT;
}
@@ -55,12 +57,52 @@ Transform TextureMapping::compute_transform()
mmat[1][y_mapping-1] = 1.0f;
if(z_mapping != NONE)
mmat[2][z_mapping-1] = 1.0f;
+
+ float3 scale_clamped = scale;
- Transform smat = transform_scale(scale);
+ if(type == TEXTURE || type == NORMAL) {
+ /* keep matrix invertible */
+ if(fabsf(scale.x) < 1e-5f)
+ scale_clamped.x = signf(scale.x)*1e-5f;
+ if(fabsf(scale.y) < 1e-5f)
+ scale_clamped.y = signf(scale.y)*1e-5f;
+ if(fabsf(scale.z) < 1e-5f)
+ scale_clamped.z = signf(scale.z)*1e-5f;
+ }
+
+ Transform smat = transform_scale(scale_clamped);
Transform rmat = transform_euler(rotation);
Transform tmat = transform_translate(translation);
- return tmat*rmat*smat*mmat;
+ Transform mat;
+
+ switch(type) {
+ case TEXTURE:
+ /* inverse transform on texture coordinate gives
+ * forward transform on texture */
+ mat = tmat*rmat*smat;
+ mat = transform_inverse(mat);
+ break;
+ case POINT:
+ /* full transform */
+ mat = tmat*rmat*smat;
+ break;
+ case VECTOR:
+ /* no translation for vectors */
+ mat = rmat*smat;
+ break;
+ case NORMAL:
+ /* no translation for normals, and inverse transpose */
+ mat = rmat*smat;
+ mat = transform_inverse(mat);
+ mat = transform_transpose(mat);
+ break;
+ }
+
+ /* projection last */
+ mat = mat*mmat;
+
+ return mat;
}
bool TextureMapping::skip()
@@ -98,6 +140,11 @@ void TextureMapping::compile(SVMCompiler& compiler, int offset_in, int offset_ou
compiler.add_node(float3_to_float4(min));
compiler.add_node(float3_to_float4(max));
}
+
+ if(type == NORMAL) {
+ compiler.add_node(NODE_VECTOR_MATH, NODE_VECTOR_MATH_NORMALIZE, offset_out, offset_out);
+ compiler.add_node(NODE_VECTOR_MATH, SVM_STACK_INVALID, offset_out);
+ }
}
void TextureMapping::compile(OSLCompiler &compiler)
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index d58c6633a41..430c37158f4 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -43,6 +43,9 @@ public:
float3 min, max;
bool use_minmax;
+ enum Type { POINT = 0, TEXTURE = 1, VECTOR = 2, NORMAL = 3 };
+ Type type;
+
enum Mapping { NONE = 0, X = 1, Y = 2, Z = 3 };
Mapping x_mapping, y_mapping, z_mapping;