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
diff options
context:
space:
mode:
authorOmarSquircleArt <omar.squircleart@gmail.com>2019-09-05 00:17:13 +0300
committerOmarSquircleArt <omar.squircleart@gmail.com>2019-09-05 00:17:13 +0300
commitbaaa89a0bc54a659f9ddbc34cce21d6920c0f6a6 (patch)
treef5337407abc1e1e832612cc7643d508ed021eb37 /intern/cycles/render/nodes.cpp
parentf098f6df767aa62ffe0a7db6635ead058770d92f (diff)
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, JacquesLucke
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r--intern/cycles/render/nodes.cpp48
1 files changed, 39 insertions, 9 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 24aa9589220..31dc986a4d1 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -25,6 +25,7 @@
#include "kernel/svm/svm_color_util.h"
#include "kernel/svm/svm_ramp_util.h"
#include "kernel/svm/svm_math_util.h"
+#include "kernel/svm/svm_mapping_util.h"
#include "render/osl.h"
#include "render/constant_fold.h"
@@ -149,7 +150,7 @@ bool TextureMapping::skip()
void TextureMapping::compile(SVMCompiler &compiler, int offset_in, int offset_out)
{
- compiler.add_node(NODE_MAPPING, offset_in, offset_out);
+ compiler.add_node(NODE_TEXTURE_MAPPING, offset_in, offset_out);
Transform tfm = compute_transform();
compiler.add_node(tfm.x);
@@ -1727,9 +1728,18 @@ NODE_DEFINE(MappingNode)
{
NodeType *type = NodeType::add("mapping", create, NodeType::SHADER);
- TEXTURE_MAPPING_DEFINE(MappingNode);
+ static NodeEnum type_enum;
+ type_enum.insert("point", NODE_MAPPING_TYPE_POINT);
+ type_enum.insert("texture", NODE_MAPPING_TYPE_TEXTURE);
+ type_enum.insert("vector", NODE_MAPPING_TYPE_VECTOR);
+ type_enum.insert("normal", NODE_MAPPING_TYPE_NORMAL);
+ SOCKET_ENUM(type, "Type", type_enum, NODE_MAPPING_TYPE_POINT);
SOCKET_IN_POINT(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f));
+ SOCKET_IN_POINT(location, "Location", make_float3(0.0f, 0.0f, 0.0f));
+ SOCKET_IN_POINT(rotation, "Rotation", make_float3(0.0f, 0.0f, 0.0f));
+ SOCKET_IN_POINT(scale, "Scale", make_float3(1.0f, 1.0f, 1.0f));
+
SOCKET_OUT_POINT(vector, "Vector");
return type;
@@ -1739,22 +1749,42 @@ MappingNode::MappingNode() : ShaderNode(node_type)
{
}
+void MappingNode::constant_fold(const ConstantFolder &folder)
+{
+ if (folder.all_inputs_constant()) {
+ float3 result = svm_mapping((NodeMappingType)type, vector, location, rotation, scale);
+ folder.make_constant(result);
+ }
+ else {
+ folder.fold_mapping((NodeMappingType)type);
+ }
+}
+
void MappingNode::compile(SVMCompiler &compiler)
{
ShaderInput *vector_in = input("Vector");
+ ShaderInput *location_in = input("Location");
+ ShaderInput *rotation_in = input("Rotation");
+ ShaderInput *scale_in = input("Scale");
ShaderOutput *vector_out = output("Vector");
- tex_mapping.compile(
- compiler, compiler.stack_assign(vector_in), compiler.stack_assign(vector_out));
+ int vector_stack_offset = compiler.stack_assign(vector_in);
+ int location_stack_offset = compiler.stack_assign(location_in);
+ int rotation_stack_offset = compiler.stack_assign(rotation_in);
+ int scale_stack_offset = compiler.stack_assign(scale_in);
+ int result_stack_offset = compiler.stack_assign(vector_out);
+
+ compiler.add_node(
+ NODE_MAPPING,
+ type,
+ compiler.encode_uchar4(
+ vector_stack_offset, location_stack_offset, rotation_stack_offset, scale_stack_offset),
+ result_stack_offset);
}
void MappingNode::compile(OSLCompiler &compiler)
{
- compiler.parameter("Matrix", tex_mapping.compute_transform());
- compiler.parameter_point("mapping_min", tex_mapping.min);
- compiler.parameter_point("mapping_max", tex_mapping.max);
- compiler.parameter("use_minmax", tex_mapping.use_minmax);
-
+ compiler.parameter(this, "type");
compiler.add(this, "node_mapping");
}