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
This commit is contained in:
OmarSquircleArt
2019-09-04 23:17:13 +02:00
parent f098f6df76
commit baaa89a0bc
24 changed files with 466 additions and 239 deletions

View File

@@ -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");
}