Code refactor: make ShaderNode match Node a bit more, reusing types and enums.
Differential Revision: https://developer.blender.org/D2016
This commit is contained in:
@@ -214,7 +214,7 @@ static bool xml_equal_string(pugi::xml_node node, const char *name, const char *
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool xml_read_enum(ustring *str, ShaderEnum& enm, pugi::xml_node node, const char *name)
|
static bool xml_read_enum(ustring *str, NodeEnum& enm, pugi::xml_node node, const char *name)
|
||||||
{
|
{
|
||||||
pugi::xml_attribute attr = node.attribute(name);
|
pugi::xml_attribute attr = node.attribute(name);
|
||||||
|
|
||||||
@@ -232,7 +232,7 @@ static bool xml_read_enum(ustring *str, ShaderEnum& enm, pugi::xml_node node, co
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool xml_read_enum_value(int *value, ShaderEnum& enm, pugi::xml_node node, const char *name)
|
static bool xml_read_enum_value(int *value, NodeEnum& enm, pugi::xml_node node, const char *name)
|
||||||
{
|
{
|
||||||
pugi::xml_attribute attr = node.attribute(name);
|
pugi::xml_attribute attr = node.attribute(name);
|
||||||
|
|
||||||
@@ -250,33 +250,33 @@ static bool xml_read_enum_value(int *value, ShaderEnum& enm, pugi::xml_node node
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShaderSocketType xml_read_socket_type(pugi::xml_node node, const char *name)
|
static SocketType::Type xml_read_socket_type(pugi::xml_node node, const char *name)
|
||||||
{
|
{
|
||||||
pugi::xml_attribute attr = node.attribute(name);
|
pugi::xml_attribute attr = node.attribute(name);
|
||||||
|
|
||||||
if(attr) {
|
if(attr) {
|
||||||
string value = attr.value();
|
string value = attr.value();
|
||||||
if(string_iequals(value, "float"))
|
if(string_iequals(value, "float"))
|
||||||
return SHADER_SOCKET_FLOAT;
|
return SocketType::FLOAT;
|
||||||
else if(string_iequals(value, "int"))
|
else if(string_iequals(value, "int"))
|
||||||
return SHADER_SOCKET_INT;
|
return SocketType::INT;
|
||||||
else if(string_iequals(value, "color"))
|
else if(string_iequals(value, "color"))
|
||||||
return SHADER_SOCKET_COLOR;
|
return SocketType::COLOR;
|
||||||
else if(string_iequals(value, "vector"))
|
else if(string_iequals(value, "vector"))
|
||||||
return SHADER_SOCKET_VECTOR;
|
return SocketType::VECTOR;
|
||||||
else if(string_iequals(value, "point"))
|
else if(string_iequals(value, "point"))
|
||||||
return SHADER_SOCKET_POINT;
|
return SocketType::POINT;
|
||||||
else if(string_iequals(value, "normal"))
|
else if(string_iequals(value, "normal"))
|
||||||
return SHADER_SOCKET_NORMAL;
|
return SocketType::NORMAL;
|
||||||
else if(string_iequals(value, "closure color"))
|
else if(string_iequals(value, "closure color"))
|
||||||
return SHADER_SOCKET_CLOSURE;
|
return SocketType::CLOSURE;
|
||||||
else if(string_iequals(value, "string"))
|
else if(string_iequals(value, "string"))
|
||||||
return SHADER_SOCKET_STRING;
|
return SocketType::STRING;
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Unknown shader socket type \"%s\" for attribute \"%s\".\n", value.c_str(), name);
|
fprintf(stderr, "Unknown shader socket type \"%s\" for attribute \"%s\".\n", value.c_str(), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SHADER_SOCKET_UNDEFINED;
|
return SocketType::UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Camera */
|
/* Camera */
|
||||||
@@ -371,8 +371,8 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
|
|||||||
if(!xml_read_string(&name, param, "name"))
|
if(!xml_read_string(&name, param, "name"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ShaderSocketType type = xml_read_socket_type(param, "type");
|
SocketType::Type type = xml_read_socket_type(param, "type");
|
||||||
if(type == SHADER_SOCKET_UNDEFINED)
|
if(type == SocketType::UNDEFINED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
osl->add_input(ustring(name).c_str(), type);
|
osl->add_input(ustring(name).c_str(), type);
|
||||||
@@ -382,8 +382,8 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
|
|||||||
if(!xml_read_string(&name, param, "name"))
|
if(!xml_read_string(&name, param, "name"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
ShaderSocketType type = xml_read_socket_type(param, "type");
|
SocketType::Type type = xml_read_socket_type(param, "type");
|
||||||
if(type == SHADER_SOCKET_UNDEFINED)
|
if(type == SocketType::UNDEFINED)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
osl->add_output(ustring(name).c_str(), type);
|
osl->add_output(ustring(name).c_str(), type);
|
||||||
@@ -699,7 +699,7 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
|
|||||||
ShaderNode *fromnode = nodemap[from_tokens[0]];
|
ShaderNode *fromnode = nodemap[from_tokens[0]];
|
||||||
|
|
||||||
foreach(ShaderOutput *out, fromnode->outputs)
|
foreach(ShaderOutput *out, fromnode->outputs)
|
||||||
if(string_iequals(xml_socket_name(out->name), from_tokens[1]))
|
if(string_iequals(xml_socket_name(out->name().c_str()), from_tokens[1]))
|
||||||
output = out;
|
output = out;
|
||||||
|
|
||||||
if(!output)
|
if(!output)
|
||||||
@@ -712,7 +712,7 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
|
|||||||
ShaderNode *tonode = nodemap[to_tokens[0]];
|
ShaderNode *tonode = nodemap[to_tokens[0]];
|
||||||
|
|
||||||
foreach(ShaderInput *in, tonode->inputs)
|
foreach(ShaderInput *in, tonode->inputs)
|
||||||
if(string_iequals(xml_socket_name(in->name), to_tokens[1]))
|
if(string_iequals(xml_socket_name(in->name().c_str()), to_tokens[1]))
|
||||||
input = in;
|
input = in;
|
||||||
|
|
||||||
if(!input)
|
if(!input)
|
||||||
@@ -744,20 +744,20 @@ static void xml_read_shader_graph(XMLReadState& state, Shader *shader, pugi::xml
|
|||||||
/* read input values */
|
/* read input values */
|
||||||
for(pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) {
|
for(pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) {
|
||||||
foreach(ShaderInput *in, snode->inputs) {
|
foreach(ShaderInput *in, snode->inputs) {
|
||||||
if(string_iequals(in->name, attr.name())) {
|
if(string_iequals(in->name().c_str(), attr.name())) {
|
||||||
switch(in->type) {
|
switch(in->type()) {
|
||||||
case SHADER_SOCKET_FLOAT:
|
case SocketType::FLOAT:
|
||||||
case SHADER_SOCKET_INT:
|
case SocketType::INT:
|
||||||
xml_read_float(&in->value.x, node, attr.name());
|
xml_read_float(&in->value_float(), node, attr.name());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_COLOR:
|
case SocketType::COLOR:
|
||||||
case SHADER_SOCKET_VECTOR:
|
case SocketType::VECTOR:
|
||||||
case SHADER_SOCKET_POINT:
|
case SocketType::POINT:
|
||||||
case SHADER_SOCKET_NORMAL:
|
case SocketType::NORMAL:
|
||||||
xml_read_float3(&in->value, node, attr.name());
|
xml_read_float3(&in->value(), node, attr.name());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_STRING:
|
case SocketType::STRING:
|
||||||
xml_read_ustring( &in->value_string, node, attr.name() );
|
xml_read_ustring( &in->value_string(), node, attr.name() );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@@ -127,42 +127,42 @@ static float3 get_node_output_vector(BL::Node& b_node, const string& name)
|
|||||||
return make_float3(value[0], value[1], value[2]);
|
return make_float3(value[0], value[1], value[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ShaderSocketType convert_socket_type(BL::NodeSocket& b_socket)
|
static SocketType::Type convert_socket_type(BL::NodeSocket& b_socket)
|
||||||
{
|
{
|
||||||
switch(b_socket.type()) {
|
switch(b_socket.type()) {
|
||||||
case BL::NodeSocket::type_VALUE:
|
case BL::NodeSocket::type_VALUE:
|
||||||
return SHADER_SOCKET_FLOAT;
|
return SocketType::FLOAT;
|
||||||
case BL::NodeSocket::type_INT:
|
case BL::NodeSocket::type_INT:
|
||||||
return SHADER_SOCKET_INT;
|
return SocketType::INT;
|
||||||
case BL::NodeSocket::type_VECTOR:
|
case BL::NodeSocket::type_VECTOR:
|
||||||
return SHADER_SOCKET_VECTOR;
|
return SocketType::VECTOR;
|
||||||
case BL::NodeSocket::type_RGBA:
|
case BL::NodeSocket::type_RGBA:
|
||||||
return SHADER_SOCKET_COLOR;
|
return SocketType::COLOR;
|
||||||
case BL::NodeSocket::type_STRING:
|
case BL::NodeSocket::type_STRING:
|
||||||
return SHADER_SOCKET_STRING;
|
return SocketType::STRING;
|
||||||
case BL::NodeSocket::type_SHADER:
|
case BL::NodeSocket::type_SHADER:
|
||||||
return SHADER_SOCKET_CLOSURE;
|
return SocketType::CLOSURE;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return SHADER_SOCKET_UNDEFINED;
|
return SocketType::UNDEFINED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_OSL
|
#ifdef WITH_OSL
|
||||||
static ShaderSocketType convert_osl_socket_type(OSL::OSLQuery& query,
|
static SocketType::Type convert_osl_socket_type(OSL::OSLQuery& query,
|
||||||
BL::NodeSocket& b_socket)
|
BL::NodeSocket& b_socket)
|
||||||
{
|
{
|
||||||
ShaderSocketType socket_type = convert_socket_type(b_socket);
|
SocketType::Type socket_type = convert_socket_type(b_socket);
|
||||||
if(socket_type == SHADER_SOCKET_VECTOR) {
|
if(socket_type == SocketType::VECTOR) {
|
||||||
/* TODO(sergey): Do we need compatible_name() here? */
|
/* TODO(sergey): Do we need compatible_name() here? */
|
||||||
const OSL::OSLQuery::Parameter *param = query.getparam(b_socket.name());
|
const OSL::OSLQuery::Parameter *param = query.getparam(b_socket.name());
|
||||||
assert(param != NULL);
|
assert(param != NULL);
|
||||||
if(param != NULL) {
|
if(param != NULL) {
|
||||||
if(param->type.vecsemantics == TypeDesc::POINT) {
|
if(param->type.vecsemantics == TypeDesc::POINT) {
|
||||||
socket_type = SHADER_SOCKET_POINT;
|
socket_type = SocketType::POINT;
|
||||||
}
|
}
|
||||||
else if(param->type.vecsemantics == TypeDesc::NORMAL) {
|
else if(param->type.vecsemantics == TypeDesc::NORMAL) {
|
||||||
socket_type = SHADER_SOCKET_NORMAL;
|
socket_type = SocketType::NORMAL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -177,32 +177,30 @@ static void set_default_value(ShaderInput *input,
|
|||||||
BL::ID& b_id)
|
BL::ID& b_id)
|
||||||
{
|
{
|
||||||
/* copy values for non linked inputs */
|
/* copy values for non linked inputs */
|
||||||
switch(input->type) {
|
switch(input->type()) {
|
||||||
case SHADER_SOCKET_FLOAT: {
|
case SocketType::FLOAT: {
|
||||||
input->set(get_float(b_sock.ptr, "default_value"));
|
input->value_float() = get_float(b_sock.ptr, "default_value");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHADER_SOCKET_INT: {
|
case SocketType::INT: {
|
||||||
input->set((float)get_int(b_sock.ptr, "default_value"));
|
input->value_float() = (float)get_int(b_sock.ptr, "default_value");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHADER_SOCKET_COLOR: {
|
case SocketType::COLOR: {
|
||||||
input->set(float4_to_float3(get_float4(b_sock.ptr, "default_value")));
|
input->value() = float4_to_float3(get_float4(b_sock.ptr, "default_value"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHADER_SOCKET_NORMAL:
|
case SocketType::NORMAL:
|
||||||
case SHADER_SOCKET_POINT:
|
case SocketType::POINT:
|
||||||
case SHADER_SOCKET_VECTOR: {
|
case SocketType::VECTOR: {
|
||||||
input->set(get_float3(b_sock.ptr, "default_value"));
|
input->value() = get_float3(b_sock.ptr, "default_value");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SHADER_SOCKET_STRING: {
|
case SocketType::STRING: {
|
||||||
input->set((ustring)blender_absolute_path(b_data, b_id, get_string(b_sock.ptr, "default_value")));
|
input->value_string() = (ustring)blender_absolute_path(b_data, b_id, get_string(b_sock.ptr, "default_value"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
case SHADER_SOCKET_CLOSURE:
|
|
||||||
case SHADER_SOCKET_UNDEFINED:
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -341,7 +339,7 @@ static ShaderNode *add_node(Scene *scene,
|
|||||||
node = new HSVNode();
|
node = new HSVNode();
|
||||||
}
|
}
|
||||||
else if(b_node.is_a(&RNA_ShaderNodeRGBToBW)) {
|
else if(b_node.is_a(&RNA_ShaderNodeRGBToBW)) {
|
||||||
node = new ConvertNode(SHADER_SOCKET_COLOR, SHADER_SOCKET_FLOAT);
|
node = new ConvertNode(SocketType::COLOR, SocketType::FLOAT);
|
||||||
}
|
}
|
||||||
else if(b_node.is_a(&RNA_ShaderNodeMath)) {
|
else if(b_node.is_a(&RNA_ShaderNodeMath)) {
|
||||||
BL::ShaderNodeMath b_math_node(b_node);
|
BL::ShaderNodeMath b_math_node(b_node);
|
||||||
@@ -1020,7 +1018,7 @@ static void add_nodes(Scene *scene,
|
|||||||
BL::Node::internal_links_iterator b_link;
|
BL::Node::internal_links_iterator b_link;
|
||||||
for(b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
|
for(b_node->internal_links.begin(b_link); b_link != b_node->internal_links.end(); ++b_link) {
|
||||||
BL::NodeSocket to_socket(b_link->to_socket());
|
BL::NodeSocket to_socket(b_link->to_socket());
|
||||||
ShaderSocketType to_socket_type = convert_socket_type(to_socket);
|
SocketType::Type to_socket_type = convert_socket_type(to_socket);
|
||||||
ConvertNode *proxy = new ConvertNode(to_socket_type, to_socket_type, true);
|
ConvertNode *proxy = new ConvertNode(to_socket_type, to_socket_type, true);
|
||||||
|
|
||||||
input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
|
input_map[b_link->from_socket().ptr.data] = proxy->inputs[0];
|
||||||
@@ -1043,7 +1041,7 @@ static void add_nodes(Scene *scene,
|
|||||||
* so that links have something to connect to and assert won't fail.
|
* so that links have something to connect to and assert won't fail.
|
||||||
*/
|
*/
|
||||||
for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
|
for(b_node->inputs.begin(b_input); b_input != b_node->inputs.end(); ++b_input) {
|
||||||
ShaderSocketType input_type = convert_socket_type(*b_input);
|
SocketType::Type input_type = convert_socket_type(*b_input);
|
||||||
ConvertNode *proxy = new ConvertNode(input_type, input_type, true);
|
ConvertNode *proxy = new ConvertNode(input_type, input_type, true);
|
||||||
graph->add(proxy);
|
graph->add(proxy);
|
||||||
|
|
||||||
@@ -1055,7 +1053,7 @@ static void add_nodes(Scene *scene,
|
|||||||
set_default_value(proxy->inputs[0], *b_input, b_data, b_ntree);
|
set_default_value(proxy->inputs[0], *b_input, b_data, b_ntree);
|
||||||
}
|
}
|
||||||
for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
|
for(b_node->outputs.begin(b_output); b_output != b_node->outputs.end(); ++b_output) {
|
||||||
ShaderSocketType output_type = convert_socket_type(*b_output);
|
SocketType::Type output_type = convert_socket_type(*b_output);
|
||||||
ConvertNode *proxy = new ConvertNode(output_type, output_type, true);
|
ConvertNode *proxy = new ConvertNode(output_type, output_type, true);
|
||||||
graph->add(proxy);
|
graph->add(proxy);
|
||||||
|
|
||||||
@@ -1227,7 +1225,7 @@ void BlenderSync::sync_materials(bool update_all)
|
|||||||
ShaderNode *closure, *out;
|
ShaderNode *closure, *out;
|
||||||
|
|
||||||
closure = graph->add(new DiffuseBsdfNode());
|
closure = graph->add(new DiffuseBsdfNode());
|
||||||
closure->input("Color")->value = get_float3(b_mat->diffuse_color());
|
closure->input("Color")->value() = get_float3(b_mat->diffuse_color());
|
||||||
out = graph->output();
|
out = graph->output();
|
||||||
|
|
||||||
graph->connect(closure->output("BSDF"), out->input("Surface"));
|
graph->connect(closure->output("BSDF"), out->input("Surface"));
|
||||||
@@ -1276,7 +1274,7 @@ void BlenderSync::sync_world(bool update_all)
|
|||||||
ShaderNode *closure, *out;
|
ShaderNode *closure, *out;
|
||||||
|
|
||||||
closure = graph->add(new BackgroundNode());
|
closure = graph->add(new BackgroundNode());
|
||||||
closure->input("Color")->value = get_float3(b_world.horizon_color());
|
closure->input("Color")->value() = get_float3(b_world.horizon_color());
|
||||||
out = graph->output();
|
out = graph->output();
|
||||||
|
|
||||||
graph->connect(closure->output("Background"), out->input("Surface"));
|
graph->connect(closure->output("Background"), out->input("Surface"));
|
||||||
@@ -1369,8 +1367,8 @@ void BlenderSync::sync_lamps(bool update_all)
|
|||||||
}
|
}
|
||||||
|
|
||||||
closure = graph->add(new EmissionNode());
|
closure = graph->add(new EmissionNode());
|
||||||
closure->input("Color")->value = get_float3(b_lamp->color());
|
closure->input("Color")->value() = get_float3(b_lamp->color());
|
||||||
closure->input("Strength")->value.x = strength;
|
closure->input("Strength")->value_float() = strength;
|
||||||
out = graph->output();
|
out = graph->output();
|
||||||
|
|
||||||
graph->connect(closure->output("Emission"), out->input("Surface"));
|
graph->connect(closure->output("Emission"), out->input("Surface"));
|
||||||
|
@@ -66,7 +66,7 @@ bool check_node_inputs_equals(const ShaderNode *node_a,
|
|||||||
*input_b = node_b->inputs[i];
|
*input_b = node_b->inputs[i];
|
||||||
if(input_a->link == NULL && input_b->link == NULL) {
|
if(input_a->link == NULL && input_b->link == NULL) {
|
||||||
/* Unconnected inputs are expected to have the same value. */
|
/* Unconnected inputs are expected to have the same value. */
|
||||||
if(input_a->value != input_b->value) {
|
if(input_a->value() != input_b->value()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,23 +90,22 @@ bool check_node_inputs_equals(const ShaderNode *node_a,
|
|||||||
|
|
||||||
/* Input and Output */
|
/* Input and Output */
|
||||||
|
|
||||||
ShaderInput::ShaderInput(ShaderNode *parent_, const char *name_, ShaderSocketType type_)
|
ShaderInput::ShaderInput(ShaderNode *parent_, const char *name, SocketType::Type type)
|
||||||
{
|
{
|
||||||
parent = parent_;
|
parent = parent_;
|
||||||
name = name_;
|
name_ = name;
|
||||||
type = type_;
|
type_ = type;
|
||||||
link = NULL;
|
link = NULL;
|
||||||
value = make_float3(0.0f, 0.0f, 0.0f);
|
value_ = make_float3(0.0f, 0.0f, 0.0f);
|
||||||
stack_offset = SVM_STACK_INVALID;
|
stack_offset = SVM_STACK_INVALID;
|
||||||
default_value = NONE;
|
flags_ = 0;
|
||||||
usage = USE_ALL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderOutput::ShaderOutput(ShaderNode *parent_, const char *name_, ShaderSocketType type_)
|
ShaderOutput::ShaderOutput(ShaderNode *parent_, const char *name, SocketType::Type type)
|
||||||
{
|
{
|
||||||
parent = parent_;
|
parent = parent_;
|
||||||
name = name_;
|
name_ = name;
|
||||||
type = type_;
|
type_ = type;
|
||||||
stack_offset = SVM_STACK_INVALID;
|
stack_offset = SVM_STACK_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,7 +131,7 @@ ShaderNode::~ShaderNode()
|
|||||||
ShaderInput *ShaderNode::input(const char *name)
|
ShaderInput *ShaderNode::input(const char *name)
|
||||||
{
|
{
|
||||||
foreach(ShaderInput *socket, inputs) {
|
foreach(ShaderInput *socket, inputs) {
|
||||||
if(strcmp(socket->name, name) == 0)
|
if(socket->name() == name)
|
||||||
return socket;
|
return socket;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,39 +141,50 @@ ShaderInput *ShaderNode::input(const char *name)
|
|||||||
ShaderOutput *ShaderNode::output(const char *name)
|
ShaderOutput *ShaderNode::output(const char *name)
|
||||||
{
|
{
|
||||||
foreach(ShaderOutput *socket, outputs)
|
foreach(ShaderOutput *socket, outputs)
|
||||||
if(strcmp(socket->name, name) == 0)
|
if(socket->name() == name)
|
||||||
return socket;
|
return socket;
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderInput *ShaderNode::add_input(const char *name, ShaderSocketType type, float value, int usage)
|
ShaderInput *ShaderNode::input(ustring name)
|
||||||
|
{
|
||||||
|
foreach(ShaderInput *socket, inputs) {
|
||||||
|
if(socket->name() == name)
|
||||||
|
return socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderOutput *ShaderNode::output(ustring name)
|
||||||
|
{
|
||||||
|
foreach(ShaderOutput *socket, outputs)
|
||||||
|
if(socket->name() == name)
|
||||||
|
return socket;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ShaderInput *ShaderNode::add_input(const char *name, SocketType::Type type, float value, int flags)
|
||||||
{
|
{
|
||||||
ShaderInput *input = new ShaderInput(this, name, type);
|
ShaderInput *input = new ShaderInput(this, name, type);
|
||||||
input->value.x = value;
|
input->value_.x = value;
|
||||||
input->usage = usage;
|
input->flags_ = flags;
|
||||||
inputs.push_back(input);
|
inputs.push_back(input);
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderInput *ShaderNode::add_input(const char *name, ShaderSocketType type, float3 value, int usage)
|
ShaderInput *ShaderNode::add_input(const char *name, SocketType::Type type, float3 value, int flags)
|
||||||
{
|
{
|
||||||
ShaderInput *input = new ShaderInput(this, name, type);
|
ShaderInput *input = new ShaderInput(this, name, type);
|
||||||
input->value = value;
|
input->value_ = value;
|
||||||
input->usage = usage;
|
input->flags_ = flags;
|
||||||
inputs.push_back(input);
|
inputs.push_back(input);
|
||||||
return input;
|
return input;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderInput *ShaderNode::add_input(const char *name, ShaderSocketType type, ShaderInput::DefaultValue value, int usage)
|
ShaderOutput *ShaderNode::add_output(const char *name, SocketType::Type type)
|
||||||
{
|
|
||||||
ShaderInput *input = add_input(name, type);
|
|
||||||
input->default_value = value;
|
|
||||||
input->usage = usage;
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
ShaderOutput *ShaderNode::add_output(const char *name, ShaderSocketType type)
|
|
||||||
{
|
{
|
||||||
ShaderOutput *output = new ShaderOutput(this, name, type);
|
ShaderOutput *output = new ShaderOutput(this, name, type);
|
||||||
outputs.push_back(output);
|
outputs.push_back(output);
|
||||||
@@ -185,13 +195,13 @@ void ShaderNode::attributes(Shader *shader, AttributeRequestSet *attributes)
|
|||||||
{
|
{
|
||||||
foreach(ShaderInput *input, inputs) {
|
foreach(ShaderInput *input, inputs) {
|
||||||
if(!input->link) {
|
if(!input->link) {
|
||||||
if(input->default_value == ShaderInput::TEXTURE_GENERATED) {
|
if(input->flags() & SocketType::LINK_TEXTURE_GENERATED) {
|
||||||
if(shader->has_surface)
|
if(shader->has_surface)
|
||||||
attributes->add(ATTR_STD_GENERATED);
|
attributes->add(ATTR_STD_GENERATED);
|
||||||
if(shader->has_volume)
|
if(shader->has_volume)
|
||||||
attributes->add(ATTR_STD_GENERATED_TRANSFORM);
|
attributes->add(ATTR_STD_GENERATED_TRANSFORM);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::TEXTURE_UV) {
|
else if(input->flags() & SocketType::LINK_TEXTURE_UV) {
|
||||||
if(shader->has_surface)
|
if(shader->has_surface)
|
||||||
attributes->add(ATTR_STD_UV);
|
attributes->add(ATTR_STD_UV);
|
||||||
}
|
}
|
||||||
@@ -256,18 +266,18 @@ void ShaderGraph::connect(ShaderOutput *from, ShaderInput *to)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(from->type != to->type) {
|
if(from->type() != to->type()) {
|
||||||
/* for closures we can't do automatic conversion */
|
/* for closures we can't do automatic conversion */
|
||||||
if(from->type == SHADER_SOCKET_CLOSURE || to->type == SHADER_SOCKET_CLOSURE) {
|
if(from->type() == SocketType::CLOSURE || to->type() == SocketType::CLOSURE) {
|
||||||
fprintf(stderr, "Cycles shader graph connect: can only connect closure to closure "
|
fprintf(stderr, "Cycles shader graph connect: can only connect closure to closure "
|
||||||
"(%s.%s to %s.%s).\n",
|
"(%s.%s to %s.%s).\n",
|
||||||
from->parent->name.c_str(), from->name,
|
from->parent->name.c_str(), from->name().c_str(),
|
||||||
to->parent->name.c_str(), to->name);
|
to->parent->name.c_str(), to->name().c_str());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add automatic conversion node in case of type mismatch */
|
/* add automatic conversion node in case of type mismatch */
|
||||||
ShaderNode *convert = add(new ConvertNode(from->type, to->type, true));
|
ShaderNode *convert = add(new ConvertNode(from->type(), to->type(), true));
|
||||||
|
|
||||||
connect(from, convert->inputs[0]);
|
connect(from, convert->inputs[0]);
|
||||||
connect(convert->outputs[0], to);
|
connect(convert->outputs[0], to);
|
||||||
@@ -401,8 +411,8 @@ void ShaderGraph::copy_nodes(ShaderNodeSet& nodes, ShaderNodeMap& nnodemap)
|
|||||||
/* find new input and output */
|
/* find new input and output */
|
||||||
ShaderNode *nfrom = nnodemap[input->link->parent];
|
ShaderNode *nfrom = nnodemap[input->link->parent];
|
||||||
ShaderNode *nto = nnodemap[input->parent];
|
ShaderNode *nto = nnodemap[input->parent];
|
||||||
ShaderOutput *noutput = nfrom->output(input->link->name);
|
ShaderOutput *noutput = nfrom->output(input->link->name());
|
||||||
ShaderInput *ninput = nto->input(input->name);
|
ShaderInput *ninput = nto->input(input->name());
|
||||||
|
|
||||||
/* connect */
|
/* connect */
|
||||||
connect(noutput, ninput);
|
connect(noutput, ninput);
|
||||||
@@ -447,10 +457,10 @@ void ShaderGraph::remove_proxy_nodes()
|
|||||||
vector<ShaderInput*> links = tonode->outputs[0]->links;
|
vector<ShaderInput*> links = tonode->outputs[0]->links;
|
||||||
|
|
||||||
foreach(ShaderInput *autoin, links) {
|
foreach(ShaderInput *autoin, links) {
|
||||||
if(autoin->default_value == ShaderInput::NONE)
|
if(autoin->flags() & SocketType::DEFAULT_LINK_MASK)
|
||||||
all_links_removed = false;
|
|
||||||
else
|
|
||||||
disconnect(autoin);
|
disconnect(autoin);
|
||||||
|
else
|
||||||
|
all_links_removed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(all_links_removed)
|
if(all_links_removed)
|
||||||
@@ -460,8 +470,8 @@ void ShaderGraph::remove_proxy_nodes()
|
|||||||
disconnect(to);
|
disconnect(to);
|
||||||
|
|
||||||
/* transfer the default input value to the target socket */
|
/* transfer the default input value to the target socket */
|
||||||
to->set(input->value);
|
to->value() = input->value();
|
||||||
to->set(input->value_string);
|
to->value_string() = input->value_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,7 +543,7 @@ void ShaderGraph::constant_fold()
|
|||||||
vector<ShaderInput*> links(output->links);
|
vector<ShaderInput*> links(output->links);
|
||||||
foreach(ShaderInput *input, links) {
|
foreach(ShaderInput *input, links) {
|
||||||
/* Assign value and disconnect the optimizedinput. */
|
/* Assign value and disconnect the optimizedinput. */
|
||||||
input->value = optimized_value;
|
input->value() = optimized_value;
|
||||||
disconnect(input);
|
disconnect(input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -706,38 +716,38 @@ void ShaderGraph::default_inputs(bool do_osl)
|
|||||||
|
|
||||||
foreach(ShaderNode *node, nodes) {
|
foreach(ShaderNode *node, nodes) {
|
||||||
foreach(ShaderInput *input, node->inputs) {
|
foreach(ShaderInput *input, node->inputs) {
|
||||||
if(!input->link && ((input->usage & ShaderInput::USE_SVM) || do_osl)) {
|
if(!input->link && (!(input->flags() & SocketType::OSL_INTERNAL) || do_osl)) {
|
||||||
if(input->default_value == ShaderInput::TEXTURE_GENERATED) {
|
if(input->flags() & SocketType::LINK_TEXTURE_GENERATED) {
|
||||||
if(!texco)
|
if(!texco)
|
||||||
texco = new TextureCoordinateNode();
|
texco = new TextureCoordinateNode();
|
||||||
|
|
||||||
connect(texco->output("Generated"), input);
|
connect(texco->output("Generated"), input);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::TEXTURE_UV) {
|
else if(input->flags() & SocketType::LINK_TEXTURE_UV) {
|
||||||
if(!texco)
|
if(!texco)
|
||||||
texco = new TextureCoordinateNode();
|
texco = new TextureCoordinateNode();
|
||||||
|
|
||||||
connect(texco->output("UV"), input);
|
connect(texco->output("UV"), input);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::INCOMING) {
|
else if(input->flags() & SocketType::LINK_INCOMING) {
|
||||||
if(!geom)
|
if(!geom)
|
||||||
geom = new GeometryNode();
|
geom = new GeometryNode();
|
||||||
|
|
||||||
connect(geom->output("Incoming"), input);
|
connect(geom->output("Incoming"), input);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::NORMAL) {
|
else if(input->flags() & SocketType::LINK_NORMAL) {
|
||||||
if(!geom)
|
if(!geom)
|
||||||
geom = new GeometryNode();
|
geom = new GeometryNode();
|
||||||
|
|
||||||
connect(geom->output("Normal"), input);
|
connect(geom->output("Normal"), input);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::POSITION) {
|
else if(input->flags() & SocketType::LINK_POSITION) {
|
||||||
if(!geom)
|
if(!geom)
|
||||||
geom = new GeometryNode();
|
geom = new GeometryNode();
|
||||||
|
|
||||||
connect(geom->output("Position"), input);
|
connect(geom->output("Position"), input);
|
||||||
}
|
}
|
||||||
else if(input->default_value == ShaderInput::TANGENT) {
|
else if(input->flags() & SocketType::LINK_TANGENT) {
|
||||||
if(!geom)
|
if(!geom)
|
||||||
geom = new GeometryNode();
|
geom = new GeometryNode();
|
||||||
|
|
||||||
@@ -785,8 +795,8 @@ void ShaderGraph::refine_bump_nodes()
|
|||||||
pair.second->bump = SHADER_BUMP_DY;
|
pair.second->bump = SHADER_BUMP_DY;
|
||||||
|
|
||||||
ShaderOutput *out = bump_input->link;
|
ShaderOutput *out = bump_input->link;
|
||||||
ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name);
|
ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name());
|
||||||
ShaderOutput *out_dy = nodes_dy[out->parent]->output(out->name);
|
ShaderOutput *out_dy = nodes_dy[out->parent]->output(out->name());
|
||||||
|
|
||||||
connect(out_dx, node->input("SampleX"));
|
connect(out_dx, node->input("SampleX"));
|
||||||
connect(out_dy, node->input("SampleY"));
|
connect(out_dy, node->input("SampleY"));
|
||||||
@@ -860,9 +870,9 @@ void ShaderGraph::bump_from_displacement()
|
|||||||
ShaderNode *bump = add(new BumpNode());
|
ShaderNode *bump = add(new BumpNode());
|
||||||
|
|
||||||
ShaderOutput *out = displacement_in->link;
|
ShaderOutput *out = displacement_in->link;
|
||||||
ShaderOutput *out_center = nodes_center[out->parent]->output(out->name);
|
ShaderOutput *out_center = nodes_center[out->parent]->output(out->name());
|
||||||
ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name);
|
ShaderOutput *out_dx = nodes_dx[out->parent]->output(out->name());
|
||||||
ShaderOutput *out_dy = nodes_dy[out->parent]->output(out->name);
|
ShaderOutput *out_dy = nodes_dy[out->parent]->output(out->name());
|
||||||
|
|
||||||
connect(out_center, bump->input("SampleCenter"));
|
connect(out_center, bump->input("SampleCenter"));
|
||||||
connect(out_dx, bump->input("SampleX"));
|
connect(out_dx, bump->input("SampleX"));
|
||||||
@@ -882,7 +892,7 @@ void ShaderGraph::bump_from_displacement()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach(ShaderInput *input, node->inputs) {
|
foreach(ShaderInput *input, node->inputs) {
|
||||||
if(!input->link && input->default_value == ShaderInput::NORMAL)
|
if(!input->link && (input->flags() & SocketType::LINK_NORMAL))
|
||||||
connect(set_normal->output("Normal"), input);
|
connect(set_normal->output("Normal"), input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -925,7 +935,7 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
|
|||||||
if(fin->link)
|
if(fin->link)
|
||||||
connect(fin->link, fac_in);
|
connect(fin->link, fac_in);
|
||||||
else
|
else
|
||||||
fac_in->value = fin->value;
|
fac_in->value_float() = fin->value_float();
|
||||||
|
|
||||||
if(weight_out)
|
if(weight_out)
|
||||||
connect(weight_out, weight_in);
|
connect(weight_out, weight_in);
|
||||||
@@ -952,7 +962,7 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* already has a weight connected to it? add weights */
|
/* already has a weight connected to it? add weights */
|
||||||
if(weight_in->link || weight_in->value.x != 0.0f) {
|
if(weight_in->link || weight_in->value_float() != 0.0f) {
|
||||||
ShaderNode *math_node = add(new MathNode());
|
ShaderNode *math_node = add(new MathNode());
|
||||||
ShaderInput *value1_in = math_node->input("Value1");
|
ShaderInput *value1_in = math_node->input("Value1");
|
||||||
ShaderInput *value2_in = math_node->input("Value2");
|
ShaderInput *value2_in = math_node->input("Value2");
|
||||||
@@ -960,12 +970,12 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
|
|||||||
if(weight_in->link)
|
if(weight_in->link)
|
||||||
connect(weight_in->link, value1_in);
|
connect(weight_in->link, value1_in);
|
||||||
else
|
else
|
||||||
value1_in->value = weight_in->value;
|
value1_in->value() = weight_in->value();
|
||||||
|
|
||||||
if(weight_out)
|
if(weight_out)
|
||||||
connect(weight_out, value2_in);
|
connect(weight_out, value2_in);
|
||||||
else
|
else
|
||||||
value2_in->value.x = 1.0f;
|
value2_in->value_float() = 1.0f;
|
||||||
|
|
||||||
weight_out = math_node->output("Value");
|
weight_out = math_node->output("Value");
|
||||||
if(weight_in->link)
|
if(weight_in->link)
|
||||||
@@ -976,7 +986,7 @@ void ShaderGraph::transform_multi_closure(ShaderNode *node, ShaderOutput *weight
|
|||||||
if(weight_out)
|
if(weight_out)
|
||||||
connect(weight_out, weight_in);
|
connect(weight_out, weight_in);
|
||||||
else
|
else
|
||||||
weight_in->value.x += 1.0f;
|
weight_in->value_float() += 1.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1024,7 +1034,7 @@ void ShaderGraph::dump_graph(const char *filename)
|
|||||||
if(socket != node->inputs[0]) {
|
if(socket != node->inputs[0]) {
|
||||||
fprintf(fd, "|");
|
fprintf(fd, "|");
|
||||||
}
|
}
|
||||||
fprintf(fd, "<IN_%p>%s", socket, socket->name);
|
fprintf(fd, "<IN_%p>%s", socket, socket->name().c_str());
|
||||||
}
|
}
|
||||||
fprintf(fd, "}|");
|
fprintf(fd, "}|");
|
||||||
}
|
}
|
||||||
@@ -1044,7 +1054,7 @@ void ShaderGraph::dump_graph(const char *filename)
|
|||||||
if(socket != node->outputs[0]) {
|
if(socket != node->outputs[0]) {
|
||||||
fprintf(fd, "|");
|
fprintf(fd, "|");
|
||||||
}
|
}
|
||||||
fprintf(fd, "<OUT_%p>%s", socket, socket->name);
|
fprintf(fd, "<OUT_%p>%s", socket, socket->name().c_str());
|
||||||
}
|
}
|
||||||
fprintf(fd, "}");
|
fprintf(fd, "}");
|
||||||
}
|
}
|
||||||
@@ -1058,7 +1068,7 @@ void ShaderGraph::dump_graph(const char *filename)
|
|||||||
"// CONNECTION: OUT_%p->IN_%p (%s:%s)\n",
|
"// CONNECTION: OUT_%p->IN_%p (%s:%s)\n",
|
||||||
output,
|
output,
|
||||||
input,
|
input,
|
||||||
output->name, input->name);
|
output->name().c_str(), input->name().c_str());
|
||||||
fprintf(fd,
|
fprintf(fd,
|
||||||
"\"%p\":\"OUT_%p\":e -> \"%p\":\"IN_%p\":w [label=\"\"]\n",
|
"\"%p\":\"OUT_%p\":e -> \"%p\":\"IN_%p\":w [label=\"\"]\n",
|
||||||
output->parent,
|
output->parent,
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
#ifndef __GRAPH_H__
|
#ifndef __GRAPH_H__
|
||||||
#define __GRAPH_H__
|
#define __GRAPH_H__
|
||||||
|
|
||||||
|
#include "node.h"
|
||||||
|
|
||||||
#include "kernel_types.h"
|
#include "kernel_types.h"
|
||||||
|
|
||||||
#include "util_list.h"
|
#include "util_list.h"
|
||||||
@@ -39,23 +41,6 @@ class SVMCompiler;
|
|||||||
class OSLCompiler;
|
class OSLCompiler;
|
||||||
class OutputNode;
|
class OutputNode;
|
||||||
|
|
||||||
/* Socket Type
|
|
||||||
*
|
|
||||||
* Data type for inputs and outputs */
|
|
||||||
|
|
||||||
enum ShaderSocketType {
|
|
||||||
SHADER_SOCKET_UNDEFINED,
|
|
||||||
|
|
||||||
SHADER_SOCKET_FLOAT,
|
|
||||||
SHADER_SOCKET_INT,
|
|
||||||
SHADER_SOCKET_COLOR,
|
|
||||||
SHADER_SOCKET_VECTOR,
|
|
||||||
SHADER_SOCKET_POINT,
|
|
||||||
SHADER_SOCKET_NORMAL,
|
|
||||||
SHADER_SOCKET_CLOSURE,
|
|
||||||
SHADER_SOCKET_STRING
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Bump
|
/* Bump
|
||||||
*
|
*
|
||||||
* For bump mapping, a node may be evaluated multiple times, using different
|
* For bump mapping, a node may be evaluated multiple times, using different
|
||||||
@@ -86,30 +71,6 @@ enum ShaderNodeSpecialType {
|
|||||||
SHADER_SPECIAL_TYPE_BUMP,
|
SHADER_SPECIAL_TYPE_BUMP,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Enum
|
|
||||||
*
|
|
||||||
* Utility class for enum values. */
|
|
||||||
|
|
||||||
class ShaderEnum {
|
|
||||||
public:
|
|
||||||
bool empty() const { return left.empty(); }
|
|
||||||
void insert(const char *x, int y) {
|
|
||||||
left[ustring(x)] = y;
|
|
||||||
right[y] = ustring(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool exists(ustring x) { return left.find(x) != left.end(); }
|
|
||||||
bool exists(int y) { return right.find(y) != right.end(); }
|
|
||||||
|
|
||||||
int operator[](const char *x) { return left[ustring(x)]; }
|
|
||||||
int operator[](ustring x) { return left[x]; }
|
|
||||||
ustring operator[](int y) { return right[y]; }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
map<ustring, int> left;
|
|
||||||
map<int, ustring> right;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Input
|
/* Input
|
||||||
*
|
*
|
||||||
* Input socket for a shader node. May be linked to an output or not. If not
|
* Input socket for a shader node. May be linked to an output or not. If not
|
||||||
@@ -118,39 +79,27 @@ protected:
|
|||||||
|
|
||||||
class ShaderInput {
|
class ShaderInput {
|
||||||
public:
|
public:
|
||||||
enum DefaultValue {
|
ShaderInput(ShaderNode *parent, const char *name, SocketType::Type type);
|
||||||
TEXTURE_GENERATED,
|
|
||||||
TEXTURE_UV,
|
|
||||||
INCOMING,
|
|
||||||
NORMAL,
|
|
||||||
POSITION,
|
|
||||||
TANGENT,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
enum Usage {
|
ustring name() { return name_; }
|
||||||
USE_SVM = 1,
|
int flags() { return flags_; }
|
||||||
USE_OSL = 2,
|
SocketType::Type type() { return type_; }
|
||||||
USE_ALL = USE_SVM|USE_OSL
|
|
||||||
};
|
|
||||||
|
|
||||||
ShaderInput(ShaderNode *parent, const char *name, ShaderSocketType type);
|
float3& value() { return value_; }
|
||||||
void set(const float3& v) { value = v; }
|
float& value_float() { return value_.x; }
|
||||||
void set(float f) { value = make_float3(f, 0, 0); }
|
ustring& value_string() { return value_string_; }
|
||||||
void set(const ustring v) { value_string = v; }
|
|
||||||
|
|
||||||
const char *name;
|
ustring name_;
|
||||||
ShaderSocketType type;
|
SocketType::Type type_;
|
||||||
|
|
||||||
ShaderNode *parent;
|
ShaderNode *parent;
|
||||||
ShaderOutput *link;
|
ShaderOutput *link;
|
||||||
|
|
||||||
DefaultValue default_value;
|
float3 value_;
|
||||||
float3 value;
|
ustring value_string_;
|
||||||
ustring value_string;
|
|
||||||
|
|
||||||
int stack_offset; /* for SVM compiler */
|
int stack_offset; /* for SVM compiler */
|
||||||
int usage;
|
int flags_;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Output
|
/* Output
|
||||||
@@ -159,12 +108,15 @@ public:
|
|||||||
|
|
||||||
class ShaderOutput {
|
class ShaderOutput {
|
||||||
public:
|
public:
|
||||||
ShaderOutput(ShaderNode *parent, const char *name, ShaderSocketType type);
|
ShaderOutput(ShaderNode *parent, const char *name, SocketType::Type type);
|
||||||
|
|
||||||
|
ustring name() { return name_; }
|
||||||
|
SocketType::Type type() { return type_; }
|
||||||
|
|
||||||
|
ustring name_;
|
||||||
|
SocketType::Type type_;
|
||||||
|
|
||||||
const char *name;
|
|
||||||
ShaderNode *parent;
|
ShaderNode *parent;
|
||||||
ShaderSocketType type;
|
|
||||||
|
|
||||||
vector<ShaderInput*> links;
|
vector<ShaderInput*> links;
|
||||||
|
|
||||||
int stack_offset; /* for SVM compiler */
|
int stack_offset; /* for SVM compiler */
|
||||||
@@ -182,11 +134,12 @@ public:
|
|||||||
|
|
||||||
ShaderInput *input(const char *name);
|
ShaderInput *input(const char *name);
|
||||||
ShaderOutput *output(const char *name);
|
ShaderOutput *output(const char *name);
|
||||||
|
ShaderInput *input(ustring name);
|
||||||
|
ShaderOutput *output(ustring name);
|
||||||
|
|
||||||
ShaderInput *add_input(const char *name, ShaderSocketType type, float value=0.0f, int usage=ShaderInput::USE_ALL);
|
ShaderInput *add_input(const char *name, SocketType::Type type, float value=0.0f, int flags=0);
|
||||||
ShaderInput *add_input(const char *name, ShaderSocketType type, float3 value, int usage=ShaderInput::USE_ALL);
|
ShaderInput *add_input(const char *name, SocketType::Type type, float3 value, int flags=0);
|
||||||
ShaderInput *add_input(const char *name, ShaderSocketType type, ShaderInput::DefaultValue value, int usage=ShaderInput::USE_ALL);
|
ShaderOutput *add_output(const char *name, SocketType::Type type);
|
||||||
ShaderOutput *add_output(const char *name, ShaderSocketType type);
|
|
||||||
|
|
||||||
virtual ShaderNode *clone() const = 0;
|
virtual ShaderNode *clone() const = 0;
|
||||||
virtual void attributes(Shader *shader, AttributeRequestSet *attributes);
|
virtual void attributes(Shader *shader, AttributeRequestSet *attributes);
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -49,15 +49,15 @@ public:
|
|||||||
|
|
||||||
enum Type { POINT = 0, TEXTURE = 1, VECTOR = 2, NORMAL = 3 };
|
enum Type { POINT = 0, TEXTURE = 1, VECTOR = 2, NORMAL = 3 };
|
||||||
Type type;
|
Type type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
enum Mapping { NONE = 0, X = 1, Y = 2, Z = 3 };
|
enum Mapping { NONE = 0, X = 1, Y = 2, Z = 3 };
|
||||||
Mapping x_mapping, y_mapping, z_mapping;
|
Mapping x_mapping, y_mapping, z_mapping;
|
||||||
static ShaderEnum mapping_enum;
|
static NodeEnum mapping_enum;
|
||||||
|
|
||||||
enum Projection { FLAT, CUBE, TUBE, SPHERE };
|
enum Projection { FLAT, CUBE, TUBE, SPHERE };
|
||||||
Projection projection;
|
Projection projection;
|
||||||
static ShaderEnum projection_enum;
|
static NodeEnum projection_enum;
|
||||||
|
|
||||||
bool equals(const TextureMapping& other) {
|
bool equals(const TextureMapping& other) {
|
||||||
return translation == other.translation &&
|
return translation == other.translation &&
|
||||||
@@ -116,8 +116,8 @@ public:
|
|||||||
float projection_blend;
|
float projection_blend;
|
||||||
bool animated;
|
bool animated;
|
||||||
|
|
||||||
static ShaderEnum color_space_enum;
|
static NodeEnum color_space_enum;
|
||||||
static ShaderEnum projection_enum;
|
static NodeEnum projection_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const ImageTextureNode *image_node = (const ImageTextureNode*)other;
|
const ImageTextureNode *image_node = (const ImageTextureNode*)other;
|
||||||
@@ -153,8 +153,8 @@ public:
|
|||||||
InterpolationType interpolation;
|
InterpolationType interpolation;
|
||||||
bool animated;
|
bool animated;
|
||||||
|
|
||||||
static ShaderEnum color_space_enum;
|
static NodeEnum color_space_enum;
|
||||||
static ShaderEnum projection_enum;
|
static NodeEnum projection_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const EnvironmentTextureNode *env_node = (const EnvironmentTextureNode*)other;
|
const EnvironmentTextureNode *env_node = (const EnvironmentTextureNode*)other;
|
||||||
@@ -180,7 +180,7 @@ public:
|
|||||||
float ground_albedo;
|
float ground_albedo;
|
||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const SkyTextureNode *sky_node = (const SkyTextureNode*)other;
|
const SkyTextureNode *sky_node = (const SkyTextureNode*)other;
|
||||||
@@ -207,7 +207,7 @@ public:
|
|||||||
virtual int get_group() { return NODE_GROUP_LEVEL_2; }
|
virtual int get_group() { return NODE_GROUP_LEVEL_2; }
|
||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const GradientTextureNode *gradient_node = (const GradientTextureNode*)other;
|
const GradientTextureNode *gradient_node = (const GradientTextureNode*)other;
|
||||||
@@ -229,7 +229,7 @@ public:
|
|||||||
|
|
||||||
ustring coloring;
|
ustring coloring;
|
||||||
|
|
||||||
static ShaderEnum coloring_enum;
|
static NodeEnum coloring_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const VoronoiTextureNode *voronoi_node = (const VoronoiTextureNode*)other;
|
const VoronoiTextureNode *voronoi_node = (const VoronoiTextureNode*)other;
|
||||||
@@ -246,7 +246,7 @@ public:
|
|||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
|
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const MusgraveTextureNode *musgrave_node = (const MusgraveTextureNode*)other;
|
const MusgraveTextureNode *musgrave_node = (const MusgraveTextureNode*)other;
|
||||||
@@ -263,8 +263,8 @@ public:
|
|||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
ustring profile;
|
ustring profile;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
static ShaderEnum profile_enum;
|
static NodeEnum profile_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const WaveTextureNode *wave_node = (const WaveTextureNode*)other;
|
const WaveTextureNode *wave_node = (const WaveTextureNode*)other;
|
||||||
@@ -335,7 +335,7 @@ public:
|
|||||||
|
|
||||||
Transform tfm;
|
Transform tfm;
|
||||||
|
|
||||||
static ShaderEnum space_enum;
|
static NodeEnum space_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const PointDensityTextureNode *point_dendity_node = (const PointDensityTextureNode*)other;
|
const PointDensityTextureNode *point_dendity_node = (const PointDensityTextureNode*)other;
|
||||||
@@ -364,12 +364,12 @@ public:
|
|||||||
|
|
||||||
class ConvertNode : public ShaderNode {
|
class ConvertNode : public ShaderNode {
|
||||||
public:
|
public:
|
||||||
ConvertNode(ShaderSocketType from, ShaderSocketType to, bool autoconvert = false);
|
ConvertNode(SocketType::Type from, SocketType::Type to, bool autoconvert = false);
|
||||||
SHADER_NODE_BASE_CLASS(ConvertNode)
|
SHADER_NODE_BASE_CLASS(ConvertNode)
|
||||||
|
|
||||||
bool constant_fold(ShaderGraph *graph, ShaderOutput *socket, float3 *optimized_value);
|
bool constant_fold(ShaderGraph *graph, ShaderOutput *socket, float3 *optimized_value);
|
||||||
|
|
||||||
ShaderSocketType from, to;
|
SocketType::Type from, to;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other)
|
virtual bool equals(const ShaderNode *other)
|
||||||
{
|
{
|
||||||
@@ -404,7 +404,7 @@ public:
|
|||||||
SHADER_NODE_CLASS(AnisotropicBsdfNode)
|
SHADER_NODE_CLASS(AnisotropicBsdfNode)
|
||||||
|
|
||||||
ustring distribution;
|
ustring distribution;
|
||||||
static ShaderEnum distribution_enum;
|
static NodeEnum distribution_enum;
|
||||||
|
|
||||||
void attributes(Shader *shader, AttributeRequestSet *attributes);
|
void attributes(Shader *shader, AttributeRequestSet *attributes);
|
||||||
};
|
};
|
||||||
@@ -439,7 +439,7 @@ public:
|
|||||||
bool has_integrator_dependency();
|
bool has_integrator_dependency();
|
||||||
|
|
||||||
ustring distribution, distribution_orig;
|
ustring distribution, distribution_orig;
|
||||||
static ShaderEnum distribution_enum;
|
static NodeEnum distribution_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GlassBsdfNode : public BsdfNode {
|
class GlassBsdfNode : public BsdfNode {
|
||||||
@@ -450,7 +450,7 @@ public:
|
|||||||
bool has_integrator_dependency();
|
bool has_integrator_dependency();
|
||||||
|
|
||||||
ustring distribution, distribution_orig;
|
ustring distribution, distribution_orig;
|
||||||
static ShaderEnum distribution_enum;
|
static NodeEnum distribution_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class RefractionBsdfNode : public BsdfNode {
|
class RefractionBsdfNode : public BsdfNode {
|
||||||
@@ -461,7 +461,7 @@ public:
|
|||||||
bool has_integrator_dependency();
|
bool has_integrator_dependency();
|
||||||
|
|
||||||
ustring distribution, distribution_orig;
|
ustring distribution, distribution_orig;
|
||||||
static ShaderEnum distribution_enum;
|
static NodeEnum distribution_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ToonBsdfNode : public BsdfNode {
|
class ToonBsdfNode : public BsdfNode {
|
||||||
@@ -469,7 +469,7 @@ public:
|
|||||||
SHADER_NODE_CLASS(ToonBsdfNode)
|
SHADER_NODE_CLASS(ToonBsdfNode)
|
||||||
|
|
||||||
ustring component;
|
ustring component;
|
||||||
static ShaderEnum component_enum;
|
static NodeEnum component_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SubsurfaceScatteringNode : public BsdfNode {
|
class SubsurfaceScatteringNode : public BsdfNode {
|
||||||
@@ -478,7 +478,7 @@ public:
|
|||||||
bool has_surface_bssrdf() { return true; }
|
bool has_surface_bssrdf() { return true; }
|
||||||
bool has_bssrdf_bump();
|
bool has_bssrdf_bump();
|
||||||
|
|
||||||
static ShaderEnum falloff_enum;
|
static NodeEnum falloff_enum;
|
||||||
};
|
};
|
||||||
|
|
||||||
class EmissionNode : public ShaderNode {
|
class EmissionNode : public ShaderNode {
|
||||||
@@ -548,7 +548,7 @@ public:
|
|||||||
SHADER_NODE_CLASS(HairBsdfNode)
|
SHADER_NODE_CLASS(HairBsdfNode)
|
||||||
|
|
||||||
ustring component;
|
ustring component;
|
||||||
static ShaderEnum component_enum;
|
static NodeEnum component_enum;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -698,7 +698,7 @@ public:
|
|||||||
bool use_clamp;
|
bool use_clamp;
|
||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other)
|
virtual bool equals(const ShaderNode *other)
|
||||||
{
|
{
|
||||||
@@ -839,7 +839,7 @@ public:
|
|||||||
bool use_clamp;
|
bool use_clamp;
|
||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other)
|
virtual bool equals(const ShaderNode *other)
|
||||||
{
|
{
|
||||||
@@ -872,7 +872,7 @@ public:
|
|||||||
bool constant_fold(ShaderGraph *graph, ShaderOutput *socket, float3 *optimized_value);
|
bool constant_fold(ShaderGraph *graph, ShaderOutput *socket, float3 *optimized_value);
|
||||||
|
|
||||||
ustring type;
|
ustring type;
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other)
|
virtual bool equals(const ShaderNode *other)
|
||||||
{
|
{
|
||||||
@@ -892,8 +892,8 @@ public:
|
|||||||
ustring convert_from;
|
ustring convert_from;
|
||||||
ustring convert_to;
|
ustring convert_to;
|
||||||
|
|
||||||
static ShaderEnum type_enum;
|
static NodeEnum type_enum;
|
||||||
static ShaderEnum convert_space_enum;
|
static NodeEnum convert_space_enum;
|
||||||
|
|
||||||
virtual bool equals(const ShaderNode *other) {
|
virtual bool equals(const ShaderNode *other) {
|
||||||
const VectorTransformNode *vector_transform_node = (const VectorTransformNode*)other;
|
const VectorTransformNode *vector_transform_node = (const VectorTransformNode*)other;
|
||||||
@@ -980,7 +980,7 @@ public:
|
|||||||
virtual int get_group() { return NODE_GROUP_LEVEL_3; }
|
virtual int get_group() { return NODE_GROUP_LEVEL_3; }
|
||||||
|
|
||||||
ustring space;
|
ustring space;
|
||||||
static ShaderEnum space_enum;
|
static NodeEnum space_enum;
|
||||||
|
|
||||||
ustring attribute;
|
ustring attribute;
|
||||||
|
|
||||||
@@ -1001,10 +1001,10 @@ public:
|
|||||||
virtual int get_group() { return NODE_GROUP_LEVEL_3; }
|
virtual int get_group() { return NODE_GROUP_LEVEL_3; }
|
||||||
|
|
||||||
ustring direction_type;
|
ustring direction_type;
|
||||||
static ShaderEnum direction_type_enum;
|
static NodeEnum direction_type_enum;
|
||||||
|
|
||||||
ustring axis;
|
ustring axis;
|
||||||
static ShaderEnum axis_enum;
|
static NodeEnum axis_enum;
|
||||||
|
|
||||||
ustring attribute;
|
ustring attribute;
|
||||||
|
|
||||||
|
@@ -427,7 +427,7 @@ string OSLCompiler::id(ShaderNode *node)
|
|||||||
|
|
||||||
string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input)
|
string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input)
|
||||||
{
|
{
|
||||||
string sname(input->name);
|
string sname(input->name().string());
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* strip whitespace */
|
/* strip whitespace */
|
||||||
@@ -436,7 +436,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input)
|
|||||||
|
|
||||||
/* if output exists with the same name, add "In" suffix */
|
/* if output exists with the same name, add "In" suffix */
|
||||||
foreach(ShaderOutput *output, node->outputs) {
|
foreach(ShaderOutput *output, node->outputs) {
|
||||||
if(strcmp(input->name, output->name)==0) {
|
if(input->name() == output->name()) {
|
||||||
sname += "In";
|
sname += "In";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -447,7 +447,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderInput *input)
|
|||||||
|
|
||||||
string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output)
|
string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output)
|
||||||
{
|
{
|
||||||
string sname(output->name);
|
string sname(output->name().string());
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* strip whitespace */
|
/* strip whitespace */
|
||||||
@@ -456,7 +456,7 @@ string OSLCompiler::compatible_name(ShaderNode *node, ShaderOutput *output)
|
|||||||
|
|
||||||
/* if input exists with the same name, add "Out" suffix */
|
/* if input exists with the same name, add "Out" suffix */
|
||||||
foreach(ShaderInput *input, node->inputs) {
|
foreach(ShaderInput *input, node->inputs) {
|
||||||
if(strcmp(input->name, output->name)==0) {
|
if(input->name() == output->name()) {
|
||||||
sname += "Out";
|
sname += "Out";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -470,21 +470,21 @@ bool OSLCompiler::node_skip_input(ShaderNode *node, ShaderInput *input)
|
|||||||
/* exception for output node, only one input is actually used
|
/* exception for output node, only one input is actually used
|
||||||
* depending on the current shader type */
|
* depending on the current shader type */
|
||||||
|
|
||||||
if(!(input->usage & ShaderInput::USE_OSL))
|
if(input->flags() & SocketType::SVM_INTERNAL)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if(node->special_type == SHADER_SPECIAL_TYPE_OUTPUT) {
|
if(node->special_type == SHADER_SPECIAL_TYPE_OUTPUT) {
|
||||||
if(strcmp(input->name, "Surface") == 0 && current_type != SHADER_TYPE_SURFACE)
|
if(input->name() == "Surface" && current_type != SHADER_TYPE_SURFACE)
|
||||||
return true;
|
return true;
|
||||||
if(strcmp(input->name, "Volume") == 0 && current_type != SHADER_TYPE_VOLUME)
|
if(input->name() == "Volume" && current_type != SHADER_TYPE_VOLUME)
|
||||||
return true;
|
return true;
|
||||||
if(strcmp(input->name, "Displacement") == 0 && current_type != SHADER_TYPE_DISPLACEMENT)
|
if(input->name() == "Displacement" && current_type != SHADER_TYPE_DISPLACEMENT)
|
||||||
return true;
|
return true;
|
||||||
if(strcmp(input->name, "Normal") == 0)
|
if(input->name() == "Normal")
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(node->special_type == SHADER_SPECIAL_TYPE_BUMP) {
|
else if(node->special_type == SHADER_SPECIAL_TYPE_BUMP) {
|
||||||
if(strcmp(input->name, "Height") == 0)
|
if(input->name() == "Height")
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else if(current_type == SHADER_TYPE_DISPLACEMENT && input->link && input->link->parent->special_type == SHADER_SPECIAL_TYPE_BUMP)
|
else if(current_type == SHADER_TYPE_DISPLACEMENT && input->link && input->link->parent->special_type == SHADER_SPECIAL_TYPE_BUMP)
|
||||||
@@ -512,34 +512,35 @@ void OSLCompiler::add(ShaderNode *node, const char *name, bool isfilepath)
|
|||||||
if(node_skip_input(node, input))
|
if(node_skip_input(node, input))
|
||||||
continue;
|
continue;
|
||||||
/* already has default value assigned */
|
/* already has default value assigned */
|
||||||
else if(input->default_value != ShaderInput::NONE)
|
else if(input->flags() & SocketType::DEFAULT_LINK_MASK)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string param_name = compatible_name(node, input);
|
string param_name = compatible_name(node, input);
|
||||||
switch(input->type) {
|
switch(input->type()) {
|
||||||
case SHADER_SOCKET_COLOR:
|
case SocketType::COLOR:
|
||||||
parameter_color(param_name.c_str(), input->value);
|
parameter_color(param_name.c_str(), input->value());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_POINT:
|
case SocketType::POINT:
|
||||||
parameter_point(param_name.c_str(), input->value);
|
parameter_point(param_name.c_str(), input->value());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_VECTOR:
|
case SocketType::VECTOR:
|
||||||
parameter_vector(param_name.c_str(), input->value);
|
parameter_vector(param_name.c_str(), input->value());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_NORMAL:
|
case SocketType::NORMAL:
|
||||||
parameter_normal(param_name.c_str(), input->value);
|
parameter_normal(param_name.c_str(), input->value());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_FLOAT:
|
case SocketType::FLOAT:
|
||||||
parameter(param_name.c_str(), input->value.x);
|
parameter(param_name.c_str(), input->value_float());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_INT:
|
case SocketType::INT:
|
||||||
parameter(param_name.c_str(), (int)input->value.x);
|
parameter(param_name.c_str(), (int)input->value_float());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_STRING:
|
case SocketType::STRING:
|
||||||
parameter(param_name.c_str(), input->value_string);
|
parameter(param_name.c_str(), input->value_string());
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_CLOSURE:
|
case SocketType::CLOSURE:
|
||||||
case SHADER_SOCKET_UNDEFINED:
|
case SocketType::UNDEFINED:
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -456,7 +456,7 @@ void ShaderManager::add_default(Scene *scene)
|
|||||||
ShaderGraph *graph = new ShaderGraph();
|
ShaderGraph *graph = new ShaderGraph();
|
||||||
|
|
||||||
closure = graph->add(new DiffuseBsdfNode());
|
closure = graph->add(new DiffuseBsdfNode());
|
||||||
closure->input("Color")->value = make_float3(0.8f, 0.8f, 0.8f);
|
closure->input("Color")->value() = make_float3(0.8f, 0.8f, 0.8f);
|
||||||
out = graph->output();
|
out = graph->output();
|
||||||
|
|
||||||
graph->connect(closure->output("BSDF"), out->input("Surface"));
|
graph->connect(closure->output("BSDF"), out->input("Surface"));
|
||||||
@@ -473,8 +473,8 @@ void ShaderManager::add_default(Scene *scene)
|
|||||||
ShaderGraph *graph = new ShaderGraph();
|
ShaderGraph *graph = new ShaderGraph();
|
||||||
|
|
||||||
closure = graph->add(new EmissionNode());
|
closure = graph->add(new EmissionNode());
|
||||||
closure->input("Color")->value = make_float3(0.8f, 0.8f, 0.8f);
|
closure->input("Color")->value() = make_float3(0.8f, 0.8f, 0.8f);
|
||||||
closure->input("Strength")->value.x = 0.0f;
|
closure->input("Strength")->value_float() = 0.0f;
|
||||||
out = graph->output();
|
out = graph->output();
|
||||||
|
|
||||||
graph->connect(closure->output("Emission"), out->input("Surface"));
|
graph->connect(closure->output("Emission"), out->input("Surface"));
|
||||||
|
@@ -120,22 +120,22 @@ SVMCompiler::SVMCompiler(ShaderManager *shader_manager_, ImageManager *image_man
|
|||||||
compile_failed = false;
|
compile_failed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SVMCompiler::stack_size(ShaderSocketType type)
|
int SVMCompiler::stack_size(SocketType::Type type)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
|
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case SHADER_SOCKET_FLOAT:
|
case SocketType::FLOAT:
|
||||||
case SHADER_SOCKET_INT:
|
case SocketType::INT:
|
||||||
size = 1;
|
size = 1;
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_COLOR:
|
case SocketType::COLOR:
|
||||||
case SHADER_SOCKET_VECTOR:
|
case SocketType::VECTOR:
|
||||||
case SHADER_SOCKET_NORMAL:
|
case SocketType::NORMAL:
|
||||||
case SHADER_SOCKET_POINT:
|
case SocketType::POINT:
|
||||||
size = 3;
|
size = 3;
|
||||||
break;
|
break;
|
||||||
case SHADER_SOCKET_CLOSURE:
|
case SocketType::CLOSURE:
|
||||||
size = 0;
|
size = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -146,7 +146,7 @@ int SVMCompiler::stack_size(ShaderSocketType type)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SVMCompiler::stack_find_offset(ShaderSocketType type)
|
int SVMCompiler::stack_find_offset(SocketType::Type type)
|
||||||
{
|
{
|
||||||
int size = stack_size(type);
|
int size = stack_size(type);
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
@@ -175,7 +175,7 @@ int SVMCompiler::stack_find_offset(ShaderSocketType type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SVMCompiler::stack_clear_offset(ShaderSocketType type, int offset)
|
void SVMCompiler::stack_clear_offset(SocketType::Type type, int offset)
|
||||||
{
|
{
|
||||||
int size = stack_size(type);
|
int size = stack_size(type);
|
||||||
|
|
||||||
@@ -193,22 +193,22 @@ int SVMCompiler::stack_assign(ShaderInput *input)
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* not linked to output -> add nodes to load default value */
|
/* not linked to output -> add nodes to load default value */
|
||||||
input->stack_offset = stack_find_offset(input->type);
|
input->stack_offset = stack_find_offset(input->type());
|
||||||
|
|
||||||
if(input->type == SHADER_SOCKET_FLOAT) {
|
if(input->type() == SocketType::FLOAT) {
|
||||||
add_node(NODE_VALUE_F, __float_as_int(input->value.x), input->stack_offset);
|
add_node(NODE_VALUE_F, __float_as_int(input->value_float()), input->stack_offset);
|
||||||
}
|
}
|
||||||
else if(input->type == SHADER_SOCKET_INT) {
|
else if(input->type() == SocketType::INT) {
|
||||||
add_node(NODE_VALUE_F, (int)input->value.x, input->stack_offset);
|
add_node(NODE_VALUE_F, (int)input->value_float(), input->stack_offset);
|
||||||
}
|
}
|
||||||
else if(input->type == SHADER_SOCKET_VECTOR ||
|
else if(input->type() == SocketType::VECTOR ||
|
||||||
input->type == SHADER_SOCKET_NORMAL ||
|
input->type() == SocketType::NORMAL ||
|
||||||
input->type == SHADER_SOCKET_POINT ||
|
input->type() == SocketType::POINT ||
|
||||||
input->type == SHADER_SOCKET_COLOR)
|
input->type() == SocketType::COLOR)
|
||||||
{
|
{
|
||||||
|
|
||||||
add_node(NODE_VALUE_V, input->stack_offset);
|
add_node(NODE_VALUE_V, input->stack_offset);
|
||||||
add_node(NODE_VALUE_V, input->value);
|
add_node(NODE_VALUE_V, input->value());
|
||||||
}
|
}
|
||||||
else /* should not get called for closure */
|
else /* should not get called for closure */
|
||||||
assert(0);
|
assert(0);
|
||||||
@@ -222,7 +222,7 @@ int SVMCompiler::stack_assign(ShaderOutput *output)
|
|||||||
{
|
{
|
||||||
/* if no stack offset assigned yet, find one */
|
/* if no stack offset assigned yet, find one */
|
||||||
if(output->stack_offset == SVM_STACK_INVALID)
|
if(output->stack_offset == SVM_STACK_INVALID)
|
||||||
output->stack_offset = stack_find_offset(output->type);
|
output->stack_offset = stack_find_offset(output->type());
|
||||||
|
|
||||||
return output->stack_offset;
|
return output->stack_offset;
|
||||||
}
|
}
|
||||||
@@ -247,11 +247,11 @@ void SVMCompiler::stack_link(ShaderInput *input, ShaderOutput *output)
|
|||||||
{
|
{
|
||||||
if(output->stack_offset == SVM_STACK_INVALID) {
|
if(output->stack_offset == SVM_STACK_INVALID) {
|
||||||
assert(input->link);
|
assert(input->link);
|
||||||
assert(stack_size(output->type) == stack_size(input->link->type));
|
assert(stack_size(output->type()) == stack_size(input->link->type()));
|
||||||
|
|
||||||
output->stack_offset = input->link->stack_offset;
|
output->stack_offset = input->link->stack_offset;
|
||||||
|
|
||||||
int size = stack_size(output->type);
|
int size = stack_size(output->type());
|
||||||
|
|
||||||
for(int i = 0; i < size; i++)
|
for(int i = 0; i < size; i++)
|
||||||
active_stack.users[output->stack_offset + i]++;
|
active_stack.users[output->stack_offset + i]++;
|
||||||
@@ -279,7 +279,7 @@ void SVMCompiler::stack_clear_users(ShaderNode *node, ShaderNodeSet& done)
|
|||||||
all_done = false;
|
all_done = false;
|
||||||
|
|
||||||
if(all_done) {
|
if(all_done) {
|
||||||
stack_clear_offset(output->type, output->stack_offset);
|
stack_clear_offset(output->type(), output->stack_offset);
|
||||||
output->stack_offset = SVM_STACK_INVALID;
|
output->stack_offset = SVM_STACK_INVALID;
|
||||||
|
|
||||||
foreach(ShaderInput *in, output->links)
|
foreach(ShaderInput *in, output->links)
|
||||||
@@ -293,7 +293,7 @@ void SVMCompiler::stack_clear_temporary(ShaderNode *node)
|
|||||||
{
|
{
|
||||||
foreach(ShaderInput *input, node->inputs) {
|
foreach(ShaderInput *input, node->inputs) {
|
||||||
if(!input->link && input->stack_offset != SVM_STACK_INVALID) {
|
if(!input->link && input->stack_offset != SVM_STACK_INVALID) {
|
||||||
stack_clear_offset(input->type, input->stack_offset);
|
stack_clear_offset(input->type(), input->stack_offset);
|
||||||
input->stack_offset = SVM_STACK_INVALID;
|
input->stack_offset = SVM_STACK_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -446,7 +446,7 @@ void SVMCompiler::generate_closure_node(ShaderNode *node,
|
|||||||
const char *weight_name = (current_type == SHADER_TYPE_VOLUME)? "VolumeMixWeight": "SurfaceMixWeight";
|
const char *weight_name = (current_type == SHADER_TYPE_VOLUME)? "VolumeMixWeight": "SurfaceMixWeight";
|
||||||
ShaderInput *weight_in = node->input(weight_name);
|
ShaderInput *weight_in = node->input(weight_name);
|
||||||
|
|
||||||
if(weight_in && (weight_in->link || weight_in->value.x != 1.0f))
|
if(weight_in && (weight_in->link || weight_in->value_float() != 1.0f))
|
||||||
mix_weight_offset = stack_assign(weight_in);
|
mix_weight_offset = stack_assign(weight_in);
|
||||||
else
|
else
|
||||||
mix_weight_offset = SVM_STACK_INVALID;
|
mix_weight_offset = SVM_STACK_INVALID;
|
||||||
@@ -479,7 +479,7 @@ void SVMCompiler::generated_shared_closure_nodes(ShaderNode *root_node,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
foreach(ShaderInput *in, node->inputs) {
|
foreach(ShaderInput *in, node->inputs) {
|
||||||
if(in->type == SHADER_SOCKET_CLOSURE && in->link)
|
if(in->type() == SocketType::CLOSURE && in->link)
|
||||||
generated_shared_closure_nodes(root_node,
|
generated_shared_closure_nodes(root_node,
|
||||||
in->link->parent,
|
in->link->parent,
|
||||||
state,
|
state,
|
||||||
|
@@ -99,8 +99,8 @@ public:
|
|||||||
int stack_assign(ShaderInput *input);
|
int stack_assign(ShaderInput *input);
|
||||||
int stack_assign_if_linked(ShaderInput *input);
|
int stack_assign_if_linked(ShaderInput *input);
|
||||||
int stack_assign_if_linked(ShaderOutput *output);
|
int stack_assign_if_linked(ShaderOutput *output);
|
||||||
int stack_find_offset(ShaderSocketType type);
|
int stack_find_offset(SocketType::Type type);
|
||||||
void stack_clear_offset(ShaderSocketType type, int offset);
|
void stack_clear_offset(SocketType::Type type, int offset);
|
||||||
void stack_link(ShaderInput *input, ShaderOutput *output);
|
void stack_link(ShaderInput *input, ShaderOutput *output);
|
||||||
|
|
||||||
void add_node(ShaderNodeType type, int a = 0, int b = 0, int c = 0);
|
void add_node(ShaderNodeType type, int a = 0, int b = 0, int c = 0);
|
||||||
@@ -172,7 +172,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void stack_clear_temporary(ShaderNode *node);
|
void stack_clear_temporary(ShaderNode *node);
|
||||||
int stack_size(ShaderSocketType type);
|
int stack_size(SocketType::Type type);
|
||||||
void stack_clear_users(ShaderNode *node, ShaderNodeSet& done);
|
void stack_clear_users(ShaderNode *node, ShaderNodeSet& done);
|
||||||
|
|
||||||
bool node_skip_input(ShaderNode *node, ShaderInput *input);
|
bool node_skip_input(ShaderNode *node, ShaderInput *input);
|
||||||
|
Reference in New Issue
Block a user