diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-03 18:10:01 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-02-03 18:10:01 +0300 |
commit | 1bc0cd00713a573bed76ab35b6ae0cc0e9edc307 (patch) | |
tree | a24e6f88aee2a999b187dd416bef941af6450677 /intern/cycles | |
parent | 065a84c8d0d68edece9a407dbe97828fe22d3a6f (diff) | |
parent | db989e1f118071aae6dcd9f29d10182bd5ebed0b (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'intern/cycles')
-rw-r--r-- | intern/cycles/blender/addon/ui.py | 15 | ||||
-rw-r--r-- | intern/cycles/blender/addon/version_update.py | 8 | ||||
-rw-r--r-- | intern/cycles/blender/blender_mesh.cpp | 7 | ||||
-rw-r--r-- | intern/cycles/blender/blender_shader.cpp | 14 | ||||
-rw-r--r-- | intern/cycles/kernel/CMakeLists.txt | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/CMakeLists.txt | 1 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_displacement.osl | 15 | ||||
-rw-r--r-- | intern/cycles/kernel/shaders/node_vector_displacement.osl | 60 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm.h | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_closure.h | 2 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_displace.h | 65 | ||||
-rw-r--r-- | intern/cycles/kernel/svm/svm_types.h | 1 | ||||
-rw-r--r-- | intern/cycles/render/nodes.cpp | 107 | ||||
-rw-r--r-- | intern/cycles/render/nodes.h | 17 | ||||
-rw-r--r-- | intern/cycles/render/shader.cpp | 2 |
15 files changed, 293 insertions, 26 deletions
diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 77e5cc8cf86..13bb0094982 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -1267,13 +1267,9 @@ class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel): col.prop(cmat, "sample_as_light", text="Multiple Importance") col.prop(cmat, "use_transparent_shadow") - if context.scene.cycles.feature_set == 'EXPERIMENTAL': - col.separator() - col.label(text="Geometry:") - col.prop(cmat, "displacement_method", text="") - else: - col.separator() - col.prop(mat, "pass_index") + col.separator() + col.label(text="Geometry:") + col.prop(cmat, "displacement_method", text="") col = split.column() col.label(text="Volume:") @@ -1283,9 +1279,8 @@ class CYCLES_MATERIAL_PT_settings(CyclesButtonsPanel, Panel): col.prop(cmat, "volume_interpolation", text="") col.prop(cmat, "homogeneous_volume", text="Homogeneous") - if context.scene.cycles.feature_set == 'EXPERIMENTAL': - col.separator() - col.prop(mat, "pass_index") + col.separator() + col.prop(mat, "pass_index") class CYCLES_MATERIAL_PT_viewport(CyclesButtonsPanel, Panel): diff --git a/intern/cycles/blender/addon/version_update.py b/intern/cycles/blender/addon/version_update.py index ec334c71555..12f1cec4ac9 100644 --- a/intern/cycles/blender/addon/version_update.py +++ b/intern/cycles/blender/addon/version_update.py @@ -119,6 +119,7 @@ def displacement_node_insert(material, nodetree, traversed): node.location[0] = 0.5 * (from_node.location[0] + to_node.location[0]); node.location[1] = 0.5 * (from_node.location[1] + to_node.location[1]); node.inputs['Scale'].default_value = 0.1 + node.inputs['Midlevel'].default_value = 0.0 nodetree.links.new(from_socket, node.inputs['Height']) nodetree.links.new(node.outputs['Displacement'], to_socket) @@ -129,6 +130,11 @@ def displacement_nodes_insert(): if check_is_new_shading_material(material): displacement_node_insert(material, material.node_tree, traversed) +def displacement_node_space(node): + if node.bl_idname == 'ShaderNodeDisplacement': + if node.space != 'WORLD': + node.space = 'OBJECT' + def mapping_node_order_flip(node): """ @@ -366,3 +372,5 @@ def do_versions(self): cmat = mat.cycles if not cmat.is_property_set("displacement_method"): cmat.displacement_method = 'BUMP' + + foreach_cycles_node(displacement_node_space) diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index adffb4ea004..df1b1a4ca10 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -97,8 +97,11 @@ struct MikkUserData { if(layer_name == NULL) { Attribute *attr_orco = attributes.find(ATTR_STD_GENERATED); - orco = attr_orco->data_float3(); - mesh_texture_space(*(BL::Mesh*)&b_mesh, orco_loc, orco_size); + + if(attr_orco) { + orco = attr_orco->data_float3(); + mesh_texture_space(*(BL::Mesh*)&b_mesh, orco_loc, orco_size); + } } else { Attribute *attr_uv = attributes.find(ustring(layer_name)); diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 8b8242ab7da..d4c34d52011 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -867,7 +867,17 @@ static ShaderNode *add_node(Scene *scene, node = bevel; } else if(b_node.is_a(&RNA_ShaderNodeDisplacement)) { - node = new DisplacementNode(); + BL::ShaderNodeDisplacement b_disp_node(b_node); + DisplacementNode *disp = new DisplacementNode(); + disp->space = (NodeNormalMapSpace)b_disp_node.space(); + node = disp; + } + else if(b_node.is_a(&RNA_ShaderNodeVectorDisplacement)) { + BL::ShaderNodeVectorDisplacement b_disp_node(b_node); + VectorDisplacementNode *disp = new VectorDisplacementNode(); + disp->space = (NodeNormalMapSpace)b_disp_node.space(); + disp->attribute = ""; + node = disp; } if(node) { @@ -1235,7 +1245,7 @@ void BlenderSync::sync_materials(bool update_all) shader->heterogeneous_volume = !get_boolean(cmat, "homogeneous_volume"); shader->volume_sampling_method = get_volume_sampling(cmat); shader->volume_interpolation_method = get_volume_interpolation(cmat); - shader->displacement_method = (experimental) ? get_displacement_method(cmat) : DISPLACE_BUMP; + shader->displacement_method = get_displacement_method(cmat); shader->set_graph(graph); diff --git a/intern/cycles/kernel/CMakeLists.txt b/intern/cycles/kernel/CMakeLists.txt index 5f10bdf2041..8f7bc7996a4 100644 --- a/intern/cycles/kernel/CMakeLists.txt +++ b/intern/cycles/kernel/CMakeLists.txt @@ -408,7 +408,7 @@ if(WITH_CYCLES_CUDA_BINARIES) endmacro() foreach(arch ${CYCLES_CUDA_BINARIES_ARCH}) - if(CUDA_VERSION MATCHES "90" AND ${arch} MATCHES "sm_2.") + if(CUDA_VERSION GREATER "89" AND ${arch} MATCHES "sm_2.") message(STATUS "CUDA binaries for ${arch} disabled, not supported by CUDA 9.") else() # Compile regular kernel diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt index fb983a44579..5e8e98773d9 100644 --- a/intern/cycles/kernel/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/shaders/CMakeLists.txt @@ -24,6 +24,7 @@ set(SRC_OSL node_convert_from_vector.osl node_diffuse_bsdf.osl node_displacement.osl + node_vector_displacement.osl node_emission.osl node_environment_texture.osl node_fresnel.osl diff --git a/intern/cycles/kernel/shaders/node_displacement.osl b/intern/cycles/kernel/shaders/node_displacement.osl index fb81533c778..89f35841527 100644 --- a/intern/cycles/kernel/shaders/node_displacement.osl +++ b/intern/cycles/kernel/shaders/node_displacement.osl @@ -17,13 +17,22 @@ #include "stdosl.h" shader node_displacement( + string space = "object", float Height = 0.0, + float Midlevel = 0.5, float Scale = 1.0, normal Normal = N, output vector Displacement = vector(0.0, 0.0, 0.0)) { - Displacement = normalize(transform("object", Normal)); - Displacement *= Height * Scale; - Displacement = transform("object", "world", Displacement); + Displacement = Normal; + if(space == "object") { + Displacement = transform("object", Displacement); + } + + Displacement = normalize(Displacement) * (Height - Midlevel) * Scale; + + if(space == "object") { + Displacement = transform("object", "world", Displacement); + } } diff --git a/intern/cycles/kernel/shaders/node_vector_displacement.osl b/intern/cycles/kernel/shaders/node_vector_displacement.osl new file mode 100644 index 00000000000..b19bc228e37 --- /dev/null +++ b/intern/cycles/kernel/shaders/node_vector_displacement.osl @@ -0,0 +1,60 @@ +/* + * Copyright 2011-2013 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. + */ + +#include "stdosl.h" + +shader node_vector_displacement( + color Vector = color(0.0, 0.0, 0.0), + float Midlevel = 0.0, + float Scale = 1.0, + string space = "tangent", + string attr_name = "geom:tangent", + string attr_sign_name = "geom:tangent_sign", + output vector Displacement = vector(0.0, 0.0, 0.0)) +{ + vector offset = (Vector - vector(Midlevel)) * Scale; + + if(space == "tangent") { + /* Tangent space. */ + vector N_object = normalize(transform("world", "object", N)); + + vector T_object; + if(getattribute(attr_name, T_object)) { + T_object = normalize(T_object); + } + else { + T_object = normalize(dPdu); + } + + vector B_object = normalize(cross(N_object, T_object)); + float tangent_sign; + if(getattribute(attr_sign_name, tangent_sign)) { + B_object *= tangent_sign; + } + + Displacement = T_object*offset[0] + N_object*offset[1] + B_object*offset[2]; + } + else { + /* Object or world space. */ + Displacement = offset; + } + + if(space != "world") { + /* Tangent or object space. */ + Displacement = transform("object", "world", Displacement); + } +} + diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index cbc603d4645..a8f99d23b7d 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -270,6 +270,9 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a case NODE_DISPLACEMENT: svm_node_displacement(kg, sd, stack, node); break; + case NODE_VECTOR_DISPLACEMENT: + svm_node_vector_displacement(kg, sd, stack, node, &offset); + break; # endif /* NODES_FEATURE(NODE_FEATURE_BUMP) */ # ifdef __TEXTURES__ case NODE_TEX_IMAGE: diff --git a/intern/cycles/kernel/svm/svm_closure.h b/intern/cycles/kernel/svm/svm_closure.h index 7fc96f7e47f..578434792e4 100644 --- a/intern/cycles/kernel/svm/svm_closure.h +++ b/intern/cycles/kernel/svm/svm_closure.h @@ -333,6 +333,8 @@ ccl_device void svm_node_closure_bsdf(KernelGlobals *kg, ShaderData *sd, float * } bsdf->N = N; + bsdf->T = make_float3(0.0f, 0.0f, 0.0f); + bsdf->extra = NULL; if(distribution == CLOSURE_BSDF_MICROFACET_GGX_GLASS_ID) transmission_roughness = 1.0f - (1.0f - refl_roughness) * (1.0f - transmission_roughness); diff --git a/intern/cycles/kernel/svm/svm_displace.h b/intern/cycles/kernel/svm/svm_displace.h index 3066a364684..b9fd5bbf84d 100644 --- a/intern/cycles/kernel/svm/svm_displace.h +++ b/intern/cycles/kernel/svm/svm_displace.h @@ -89,17 +89,72 @@ ccl_device void svm_node_set_displacement(KernelGlobals *kg, ShaderData *sd, flo ccl_device void svm_node_displacement(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node) { - uint height_offset, scale_offset, normal_offset, displacement_offset; - decode_node_uchar4(node.y, &height_offset, &scale_offset, &normal_offset, &displacement_offset); + uint height_offset, midlevel_offset, scale_offset, normal_offset; + decode_node_uchar4(node.y, &height_offset, &midlevel_offset, &scale_offset, &normal_offset); float height = stack_load_float(stack, height_offset); + float midlevel = stack_load_float(stack, midlevel_offset); float scale = stack_load_float(stack, scale_offset); float3 normal = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N; + uint space = node.w; float3 dP = normal; - object_inverse_normal_transform(kg, sd, &dP); - dP *= height * scale; - object_dir_transform(kg, sd, &dP); + + if(space == NODE_NORMAL_MAP_OBJECT) { + /* Object space. */ + object_inverse_normal_transform(kg, sd, &dP); + dP *= (height - midlevel) * scale; + object_dir_transform(kg, sd, &dP); + } + else { + /* World space. */ + dP *= (height - midlevel) * scale; + } + + stack_store_float3(stack, node.z, dP); +} + +ccl_device void svm_node_vector_displacement(KernelGlobals *kg, ShaderData *sd, float *stack, uint4 node, int *offset) +{ + uint4 data_node = read_node(kg, offset); + uint space = data_node.x; + + uint vector_offset, midlevel_offset,scale_offset, displacement_offset; + decode_node_uchar4(node.y, &vector_offset, &midlevel_offset, &scale_offset, &displacement_offset); + + float3 vector = stack_load_float3(stack, vector_offset); + float midlevel = stack_load_float(stack, midlevel_offset); + float scale = stack_load_float(stack, scale_offset); + float3 dP = (vector - make_float3(midlevel, midlevel, midlevel)) * scale; + + if(space == NODE_NORMAL_MAP_TANGENT) { + /* Tangent space. */ + float3 normal = sd->N; + object_inverse_normal_transform(kg, sd, &normal); + + const AttributeDescriptor attr = find_attribute(kg, sd, node.z); + float3 tangent; + if(attr.offset != ATTR_STD_NOT_FOUND) { + tangent = primitive_attribute_float3(kg, sd, attr, NULL, NULL); + } + else { + tangent = normalize(sd->dPdu); + } + + float3 bitangent = normalize(cross(normal, tangent));; + const AttributeDescriptor attr_sign = find_attribute(kg, sd, node.w); + if(attr_sign.offset != ATTR_STD_NOT_FOUND) { + float sign = primitive_attribute_float(kg, sd, attr_sign, NULL, NULL); + bitangent *= sign; + } + + dP = tangent*dP.x + normal*dP.y + bitangent*dP.z; + } + + if(space != NODE_NORMAL_MAP_WORLD) { + /* Tangent or object space. */ + object_dir_transform(kg, sd, &dP); + } stack_store_float3(stack, displacement_offset, dP); } diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index 00c7752da8c..6ff04a65462 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -134,6 +134,7 @@ typedef enum ShaderNodeType { NODE_LEAVE_BUMP_EVAL, NODE_BEVEL, NODE_DISPLACEMENT, + NODE_VECTOR_DISPLACEMENT, } ShaderNodeType; typedef enum NodeAttributeType { diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 14c0dbab9f3..acfe07bf112 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -5650,7 +5650,14 @@ NODE_DEFINE(DisplacementNode) { NodeType* type = NodeType::add("displacement", create, NodeType::SHADER); + static NodeEnum space_enum; + space_enum.insert("object", NODE_NORMAL_MAP_OBJECT); + space_enum.insert("world", NODE_NORMAL_MAP_WORLD); + + SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT); + SOCKET_IN_FLOAT(height, "Height", 0.0f); + SOCKET_IN_FLOAT(midlevel, "Midlevel", 0.5f); SOCKET_IN_FLOAT(scale, "Scale", 1.0f); SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); @@ -5667,20 +5674,116 @@ DisplacementNode::DisplacementNode() void DisplacementNode::compile(SVMCompiler& compiler) { ShaderInput *height_in = input("Height"); + ShaderInput *midlevel_in = input("Midlevel"); ShaderInput *scale_in = input("Scale"); ShaderInput *normal_in = input("Normal"); ShaderOutput *displacement_out = output("Displacement"); compiler.add_node(NODE_DISPLACEMENT, compiler.encode_uchar4(compiler.stack_assign(height_in), + compiler.stack_assign(midlevel_in), compiler.stack_assign(scale_in), - compiler.stack_assign_if_linked(normal_in), - compiler.stack_assign(displacement_out))); + compiler.stack_assign_if_linked(normal_in)), + compiler.stack_assign(displacement_out), + space); } void DisplacementNode::compile(OSLCompiler& compiler) { + compiler.parameter(this, "space"); compiler.add(this, "node_displacement"); } +/* Vector Displacement */ + +NODE_DEFINE(VectorDisplacementNode) +{ + NodeType* type = NodeType::add("vector_displacement", create, NodeType::SHADER); + + static NodeEnum space_enum; + space_enum.insert("tangent", NODE_NORMAL_MAP_TANGENT); + space_enum.insert("object", NODE_NORMAL_MAP_OBJECT); + space_enum.insert("world", NODE_NORMAL_MAP_WORLD); + + SOCKET_ENUM(space, "Space", space_enum, NODE_NORMAL_MAP_TANGENT); + SOCKET_STRING(attribute, "Attribute", ustring("")); + + SOCKET_IN_COLOR(vector, "Vector", make_float3(0.0f, 0.0f, 0.0f)); + SOCKET_IN_FLOAT(midlevel, "Midlevel", 0.0f); + SOCKET_IN_FLOAT(scale, "Scale", 1.0f); + + SOCKET_OUT_VECTOR(displacement, "Displacement"); + + return type; +} + +VectorDisplacementNode::VectorDisplacementNode() +: ShaderNode(node_type) +{ +} + +void VectorDisplacementNode::attributes(Shader *shader, AttributeRequestSet *attributes) +{ + if(shader->has_surface && space == NODE_NORMAL_MAP_TANGENT) { + if(attribute == ustring("")) { + attributes->add(ATTR_STD_UV_TANGENT); + attributes->add(ATTR_STD_UV_TANGENT_SIGN); + } + else { + attributes->add(ustring((string(attribute.c_str()) + ".tangent").c_str())); + attributes->add(ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); + } + + attributes->add(ATTR_STD_VERTEX_NORMAL); + } + + ShaderNode::attributes(shader, attributes); +} + +void VectorDisplacementNode::compile(SVMCompiler& compiler) +{ + ShaderInput *vector_in = input("Vector"); + ShaderInput *midlevel_in = input("Midlevel"); + ShaderInput *scale_in = input("Scale"); + ShaderOutput *displacement_out = output("Displacement"); + int attr = 0, attr_sign = 0; + + if(space == NODE_NORMAL_MAP_TANGENT) { + if(attribute == ustring("")) { + attr = compiler.attribute(ATTR_STD_UV_TANGENT); + attr_sign = compiler.attribute(ATTR_STD_UV_TANGENT_SIGN); + } + else { + attr = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent").c_str())); + attr_sign = compiler.attribute(ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); + } + } + + compiler.add_node(NODE_VECTOR_DISPLACEMENT, + compiler.encode_uchar4(compiler.stack_assign(vector_in), + compiler.stack_assign(midlevel_in), + compiler.stack_assign(scale_in), + compiler.stack_assign(displacement_out)), + attr, attr_sign); + + compiler.add_node(space); +} + +void VectorDisplacementNode::compile(OSLCompiler& compiler) +{ + if(space == NODE_NORMAL_MAP_TANGENT) { + if(attribute == ustring("")) { + compiler.parameter("attr_name", ustring("geom:tangent")); + compiler.parameter("attr_sign_name", ustring("geom:tangent_sign")); + } + else { + compiler.parameter("attr_name", ustring((string(attribute.c_str()) + ".tangent").c_str())); + compiler.parameter("attr_sign_name", ustring((string(attribute.c_str()) + ".tangent_sign").c_str())); + } + } + + compiler.parameter(this, "space"); + compiler.add(this, "node_vector_displacement"); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 578451cbcfa..a00b48ca5bc 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -1034,11 +1034,28 @@ public: return NODE_FEATURE_BUMP; } + NodeNormalMapSpace space; float height; + float midlevel; float scale; float3 normal; }; +class VectorDisplacementNode : public ShaderNode { +public: + SHADER_NODE_CLASS(VectorDisplacementNode) + void attributes(Shader *shader, AttributeRequestSet *attributes); + virtual int get_feature() { + return NODE_FEATURE_BUMP; + } + + NodeNormalMapSpace space; + ustring attribute; + float3 vector; + float midlevel; + float scale; +}; + CCL_NAMESPACE_END #endif /* __NODES_H__ */ diff --git a/intern/cycles/render/shader.cpp b/intern/cycles/render/shader.cpp index 51b7f76b9d5..a1ebb26eba3 100644 --- a/intern/cycles/render/shader.cpp +++ b/intern/cycles/render/shader.cpp @@ -625,7 +625,7 @@ void ShaderManager::get_requested_features(Scene *scene, ShaderNode *output_node = shader->graph->output(); if(output_node->input("Displacement")->link != NULL) { requested_features->nodes_features |= NODE_FEATURE_BUMP; - if(shader->displacement_method == DISPLACE_BOTH && requested_features->experimental) { + if(shader->displacement_method == DISPLACE_BOTH) { requested_features->nodes_features |= NODE_FEATURE_BUMP_STATE; } } |