Shading: Rewrite Mapping node with dynamic inputs.
This patch rewrites the Mapping node to support dynamic inputs. The Max and Min options have been removed. They can be added as Min and Max Vector Math nodes manually. Texture nodes still use the old matrix-based mapping. A new SVM node `NODE_TEXTURE_MAPPING` has been added to preserve this functionality. Similarly, in GLSL, a `mapping_mat4` function has been added. Reviewers: brecht, JacquesLucketemp-npr-smooth-contour
parent
f098f6df76
commit
baaa89a0bc
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2011-2014 Blender Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
ccl_device float3
|
||||
svm_mapping(NodeMappingType type, float3 vector, float3 location, float3 rotation, float3 scale)
|
||||
{
|
||||
Transform rotationTransform = euler_to_transform(rotation);
|
||||
switch (type) {
|
||||
case NODE_MAPPING_TYPE_POINT:
|
||||
return transform_direction(&rotationTransform, (vector * scale)) + location;
|
||||
case NODE_MAPPING_TYPE_TEXTURE:
|
||||
return safe_divide_float3_float3(
|
||||
transform_direction_transposed(&rotationTransform, (vector - location)), scale);
|
||||
case NODE_MAPPING_TYPE_VECTOR:
|
||||
return transform_direction(&rotationTransform, (vector * scale));
|
||||
case NODE_MAPPING_TYPE_NORMAL:
|
||||
return safe_normalize(
|
||||
transform_direction(&rotationTransform, safe_divide_float3_float3(vector, scale)));
|
||||
default:
|
||||
return make_float3(0.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
@ -1,7 +1,27 @@
|
||||
void mapping(
|
||||
void mapping_mat4(
|
||||
vec3 vec, vec4 m0, vec4 m1, vec4 m2, vec4 m3, vec3 minvec, vec3 maxvec, out vec3 outvec)
|
||||
{
|
||||
mat4 mat = mat4(m0, m1, m2, m3);
|
||||
outvec = (mat * vec4(vec, 1.0)).xyz;
|
||||
outvec = clamp(outvec, minvec, maxvec);
|
||||
}
|
||||
|
||||
void mapping_point(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
|
||||
{
|
||||
result = (euler_to_mat3(rotation) * (vector * scale)) + location;
|
||||
}
|
||||
|
||||
void mapping_texture(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
|
||||
{
|
||||
result = safe_divide(transpose(euler_to_mat3(rotation)) * (vector - location), scale);
|
||||
}
|
||||
|
||||
void mapping_vector(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
|
||||
{
|
||||
result = euler_to_mat3(rotation) * (vector * scale);
|
||||
}
|
||||
|
||||
void mapping_normal(vec3 vector, vec3 location, vec3 rotation, vec3 scale, out vec3 result)
|
||||
{
|
||||
result = normalize(euler_to_mat3(rotation) * safe_divide(vector, scale));
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue