diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-23 15:11:02 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2018-01-23 15:19:32 +0300 |
commit | 41cc2ae62639bc6c8480beef86269c5b7fbd11fa (patch) | |
tree | 0ae885cebce8fe72caf2c1acdf172f2fd870bce5 | |
parent | 4ebcdff873cb71bb031155a9bddcc92dde8e6370 (diff) | |
parent | 4a3ddd8a7a5bc1851f832869310b5340a6b41d46 (diff) |
Merge branch 'master' into blender2.8
24 files changed, 279 insertions, 28 deletions
diff --git a/intern/cycles/blender/addon/version_update.py b/intern/cycles/blender/addon/version_update.py index efd794461d6..2075bdba8c5 100644 --- a/intern/cycles/blender/addon/version_update.py +++ b/intern/cycles/blender/addon/version_update.py @@ -89,6 +89,47 @@ def foreach_cycles_node(callback): traversed) +def displacement_node_insert(material, nodetree, traversed): + if nodetree in traversed: + return + traversed.add(nodetree) + + for node in nodetree.nodes: + if node.bl_idname == 'ShaderNodeGroup': + displacement_node_insert(material, node.node_tree, traversed) + + # Gather links to replace + displacement_links = [] + for link in nodetree.links: + if link.to_node.bl_idname == 'ShaderNodeOutputMaterial' and \ + link.from_node.bl_idname != 'ShaderNodeDisplacement' and \ + link.to_socket.identifier == 'Displacement': + displacement_links.append(link) + + # Replace links with displacement node + for link in displacement_links: + from_node = link.from_node + from_socket = link.from_socket + to_node = link.to_node + to_socket = link.to_socket + + nodetree.links.remove(link) + + node = nodetree.nodes.new(type='ShaderNodeDisplacement') + 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 + + nodetree.links.new(from_socket, node.inputs['Height']) + nodetree.links.new(node.outputs['Displacement'], to_socket) + +def displacement_nodes_insert(): + traversed = set() + for material in bpy.data.materials: + if check_is_new_shading_material(material): + displacement_node_insert(material, material.node_tree, traversed) + + def mapping_node_order_flip(node): """ Flip euler order of mapping shader node @@ -315,3 +356,6 @@ def do_versions(self): cscene.blur_glossy = 0.0 if not cscene.is_property_set("sample_clamp_indirect"): cscene.sample_clamp_indirect = 0.0 + + if bpy.data.version <= (2, 80, 3): + displacement_nodes_insert() diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp index 29ed4b4a772..8b8242ab7da 100644 --- a/intern/cycles/blender/blender_shader.cpp +++ b/intern/cycles/blender/blender_shader.cpp @@ -866,6 +866,9 @@ static ShaderNode *add_node(Scene *scene, bevel->samples = b_bevel_node.samples(); node = bevel; } + else if(b_node.is_a(&RNA_ShaderNodeDisplacement)) { + node = new DisplacementNode(); + } if(node) { node->name = b_node.name(); diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h index 796c898bc8d..0f2015ee27c 100644 --- a/intern/cycles/device/device_memory.h +++ b/intern/cycles/device/device_memory.h @@ -434,7 +434,10 @@ public: void alloc_to_device(size_t width, size_t height, size_t depth = 0) { device_vector<T>::alloc(width, height, depth); - device_memory::device_alloc(); + + if(!device_memory::device_pointer) { + device_memory::device_alloc(); + } } T *copy_from_device(int y, int w, int h) diff --git a/intern/cycles/kernel/shaders/CMakeLists.txt b/intern/cycles/kernel/shaders/CMakeLists.txt index 83cfdbcf8ba..fb983a44579 100644 --- a/intern/cycles/kernel/shaders/CMakeLists.txt +++ b/intern/cycles/kernel/shaders/CMakeLists.txt @@ -23,6 +23,7 @@ set(SRC_OSL node_convert_from_point.osl node_convert_from_vector.osl node_diffuse_bsdf.osl + node_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 new file mode 100644 index 00000000000..fb81533c778 --- /dev/null +++ b/intern/cycles/kernel/shaders/node_displacement.osl @@ -0,0 +1,29 @@ +/* + * 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_displacement( + float Height = 0.0, + 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); +} + diff --git a/intern/cycles/kernel/shaders/node_output_displacement.osl b/intern/cycles/kernel/shaders/node_output_displacement.osl index 294b8dd6bf2..5dbef0244fe 100644 --- a/intern/cycles/kernel/shaders/node_output_displacement.osl +++ b/intern/cycles/kernel/shaders/node_output_displacement.osl @@ -16,10 +16,8 @@ #include "stdosl.h" -displacement node_output_displacement(float Displacement = 0.0) +displacement node_output_displacement(vector Displacement = 0.0) { - vector dP = normalize(transform("object", N)); - dP *= Displacement * 0.1; /* todo: get rid of this factor */ - P += transform("object", "world", dP); + P += Displacement; } diff --git a/intern/cycles/kernel/split/kernel_next_iteration_setup.h b/intern/cycles/kernel/split/kernel_next_iteration_setup.h index 75a0af7567b..81024f0cf99 100644 --- a/intern/cycles/kernel/split/kernel_next_iteration_setup.h +++ b/intern/cycles/kernel/split/kernel_next_iteration_setup.h @@ -70,8 +70,7 @@ ccl_device void kernel_split_branched_indirect_light_end(KernelGlobals *kg, int } else { /* Update Path State */ - state->flag |= PATH_RAY_TRANSPARENT; - state->transparent_bounce++; + path_state_next(kg, state, LABEL_TRANSPARENT); ray->P = ray_offset(sd->P, -sd->Ng); ray->t -= sd->ray_length; /* clipping works through transparent */ diff --git a/intern/cycles/kernel/svm/svm.h b/intern/cycles/kernel/svm/svm.h index d3dac5706d0..cbc603d4645 100644 --- a/intern/cycles/kernel/svm/svm.h +++ b/intern/cycles/kernel/svm/svm.h @@ -267,6 +267,9 @@ ccl_device_noinline void svm_eval_nodes(KernelGlobals *kg, ShaderData *sd, ccl_a case NODE_SET_DISPLACEMENT: svm_node_set_displacement(kg, sd, stack, node.y); break; + case NODE_DISPLACEMENT: + svm_node_displacement(kg, sd, stack, node); + break; # endif /* NODES_FEATURE(NODE_FEATURE_BUMP) */ # ifdef __TEXTURES__ case NODE_TEX_IMAGE: diff --git a/intern/cycles/kernel/svm/svm_displace.h b/intern/cycles/kernel/svm/svm_displace.h index 656357be52d..3066a364684 100644 --- a/intern/cycles/kernel/svm/svm_displace.h +++ b/intern/cycles/kernel/svm/svm_displace.h @@ -22,8 +22,8 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac { #ifdef __RAY_DIFFERENTIALS__ /* get normal input */ - uint normal_offset, distance_offset, invert, use_object_space; - decode_node_uchar4(node.y, &normal_offset, &distance_offset, &invert, &use_object_space); + uint normal_offset, scale_offset, invert, use_object_space; + decode_node_uchar4(node.y, &normal_offset, &scale_offset, &invert, &use_object_space); float3 normal_in = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N; @@ -55,15 +55,15 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac float absdet = fabsf(det); float strength = stack_load_float(stack, strength_offset); - float distance = stack_load_float(stack, distance_offset); + float scale = stack_load_float(stack, scale_offset); if(invert) - distance *= -1.0f; + scale *= -1.0f; strength = max(strength, 0.0f); /* compute and output perturbed normal */ - float3 normal_out = safe_normalize(absdet*normal_in - distance*signf(det)*surfgrad); + float3 normal_out = safe_normalize(absdet*normal_in - scale*signf(det)*surfgrad); if(is_zero(normal_out)) { normal_out = normal_in; } @@ -83,16 +83,25 @@ ccl_device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stac ccl_device void svm_node_set_displacement(KernelGlobals *kg, ShaderData *sd, float *stack, uint fac_offset) { - float d = stack_load_float(stack, fac_offset); + float3 dP = stack_load_float3(stack, fac_offset); + sd->P += dP; +} - float3 dP = sd->N; - object_inverse_normal_transform(kg, sd, &dP); +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); - dP *= d*0.1f; /* todo: get rid of this factor */ + float height = stack_load_float(stack, height_offset); + float scale = stack_load_float(stack, scale_offset); + float3 normal = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N; + float3 dP = normal; + object_inverse_normal_transform(kg, sd, &dP); + dP *= height * scale; object_dir_transform(kg, sd, &dP); - sd->P += dP; + stack_store_float3(stack, displacement_offset, dP); } CCL_NAMESPACE_END diff --git a/intern/cycles/kernel/svm/svm_types.h b/intern/cycles/kernel/svm/svm_types.h index c7fe7948422..00c7752da8c 100644 --- a/intern/cycles/kernel/svm/svm_types.h +++ b/intern/cycles/kernel/svm/svm_types.h @@ -133,6 +133,7 @@ typedef enum ShaderNodeType { NODE_ENTER_BUMP_EVAL, NODE_LEAVE_BUMP_EVAL, NODE_BEVEL, + NODE_DISPLACEMENT, } ShaderNodeType; typedef enum NodeAttributeType { diff --git a/intern/cycles/render/graph.cpp b/intern/cycles/render/graph.cpp index 56434b39da5..fb2e34c2fc7 100644 --- a/intern/cycles/render/graph.cpp +++ b/intern/cycles/render/graph.cpp @@ -526,10 +526,10 @@ void ShaderGraph::constant_fold() * that happens to ensure there is still a valid graph for displacement. */ if(has_displacement && !output()->input("Displacement")->link) { - ValueNode *value = (ValueNode*)add(new ValueNode()); + ColorNode *value = (ColorNode*)add(new ColorNode()); value->value = output()->displacement; - connect(value->output("Value"), output()->input("Displacement")); + connect(value->output("Color"), output()->input("Displacement")); } } @@ -861,7 +861,7 @@ void ShaderGraph::bump_from_displacement(bool use_object_space) if(!displacement_in->link) return; - + /* find dependencies for the given input */ ShaderNodeSet nodes_displace; find_dependencies(nodes_displace, displacement_in); @@ -893,15 +893,34 @@ void ShaderGraph::bump_from_displacement(bool use_object_space) /* add bump node and connect copied graphs to it */ BumpNode *bump = (BumpNode*)add(new BumpNode()); bump->use_object_space = use_object_space; + bump->distance = 1.0f; ShaderOutput *out = displacement_in->link; ShaderOutput *out_center = nodes_center[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()); - connect(out_center, bump->input("SampleCenter")); - connect(out_dx, bump->input("SampleX")); - connect(out_dy, bump->input("SampleY")); + /* convert displacement vector to height */ + VectorMathNode *dot_center = (VectorMathNode*)add(new VectorMathNode()); + VectorMathNode *dot_dx = (VectorMathNode*)add(new VectorMathNode()); + VectorMathNode *dot_dy = (VectorMathNode*)add(new VectorMathNode()); + + dot_center->type = NODE_VECTOR_MATH_DOT_PRODUCT; + dot_dx->type = NODE_VECTOR_MATH_DOT_PRODUCT; + dot_dy->type = NODE_VECTOR_MATH_DOT_PRODUCT; + + GeometryNode *geom = (GeometryNode*)add(new GeometryNode()); + connect(geom->output("Normal"), dot_center->input("Vector2")); + connect(geom->output("Normal"), dot_dx->input("Vector2")); + connect(geom->output("Normal"), dot_dy->input("Vector2")); + + connect(out_center, dot_center->input("Vector1")); + connect(out_dx, dot_dx->input("Vector1")); + connect(out_dy, dot_dy->input("Vector1")); + + connect(dot_center->output("Value"), bump->input("SampleCenter")); + connect(dot_dx->output("Value"), bump->input("SampleX")); + connect(dot_dy->output("Value"), bump->input("SampleY")); /* connect the bump out to the set normal in: */ connect(bump->output("Normal"), set_normal->input("Direction")); diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 4452fadaf02..14c0dbab9f3 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -4780,7 +4780,7 @@ NODE_DEFINE(OutputNode) SOCKET_IN_CLOSURE(surface, "Surface"); SOCKET_IN_CLOSURE(volume, "Volume"); - SOCKET_IN_FLOAT(displacement, "Displacement", 0.0f); + SOCKET_IN_VECTOR(displacement, "Displacement", make_float3(0.0f, 0.0f, 0.0f)); SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f)); return type; @@ -5644,4 +5644,43 @@ void BevelNode::compile(OSLCompiler& compiler) compiler.add(this, "node_bevel"); } +/* Displacement */ + +NODE_DEFINE(DisplacementNode) +{ + NodeType* type = NodeType::add("displacement", create, NodeType::SHADER); + + SOCKET_IN_FLOAT(height, "Height", 0.0f); + SOCKET_IN_FLOAT(scale, "Scale", 1.0f); + SOCKET_IN_NORMAL(normal, "Normal", make_float3(0.0f, 0.0f, 0.0f), SocketType::LINK_NORMAL); + + SOCKET_OUT_VECTOR(displacement, "Displacement"); + + return type; +} + +DisplacementNode::DisplacementNode() +: ShaderNode(node_type) +{ +} + +void DisplacementNode::compile(SVMCompiler& compiler) +{ + ShaderInput *height_in = input("Height"); + 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(scale_in), + compiler.stack_assign_if_linked(normal_in), + compiler.stack_assign(displacement_out))); +} + +void DisplacementNode::compile(OSLCompiler& compiler) +{ + compiler.add(this, "node_displacement"); +} + CCL_NAMESPACE_END diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h index 64d7522a23a..578451cbcfa 100644 --- a/intern/cycles/render/nodes.h +++ b/intern/cycles/render/nodes.h @@ -154,7 +154,7 @@ public: void *surface; void *volume; - float displacement; + float3 displacement; float3 normal; /* Don't allow output node de-duplication. */ @@ -1027,6 +1027,18 @@ public: int samples; }; +class DisplacementNode : public ShaderNode { +public: + SHADER_NODE_CLASS(DisplacementNode) + virtual int get_feature() { + return NODE_FEATURE_BUMP; + } + + float height; + float scale; + float3 normal; +}; + CCL_NAMESPACE_END #endif /* __NODES_H__ */ diff --git a/release/scripts/startup/nodeitems_builtins.py b/release/scripts/startup/nodeitems_builtins.py index 13e5cfa192e..7a8e51d5590 100644 --- a/release/scripts/startup/nodeitems_builtins.py +++ b/release/scripts/startup/nodeitems_builtins.py @@ -300,6 +300,7 @@ shader_node_categories = [ ShaderNewNodeCategory("SH_NEW_OP_VECTOR", "Vector", items=[ NodeItem("ShaderNodeMapping"), NodeItem("ShaderNodeBump"), + NodeItem("ShaderNodeDisplacement"), NodeItem("ShaderNodeNormalMap"), NodeItem("ShaderNodeNormal"), NodeItem("ShaderNodeVectorCurve"), diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h index 27223afe4ff..ceb466ebdcd 100644 --- a/source/blender/blenkernel/BKE_blender_version.h +++ b/source/blender/blenkernel/BKE_blender_version.h @@ -28,7 +28,7 @@ * and keep comment above the defines. * Use STRINGIFY() rather than defining with quotes */ #define BLENDER_VERSION 280 -#define BLENDER_SUBVERSION 3 +#define BLENDER_SUBVERSION 4 /* Several breakages with 270, e.g. constraint deg vs rad */ #define BLENDER_MINVERSION 270 #define BLENDER_MINSUBVERSION 6 diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 5eec50019a9..4e30cb076d4 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -800,6 +800,7 @@ struct ShadeResult; #define SH_NODE_BSDF_PRINCIPLED 193 #define SH_NODE_EEVEE_SPECULAR 195 #define SH_NODE_BEVEL 197 +#define SH_NODE_DISPLACEMENT 198 /* custom defines options for Material node */ #define SH_NODE_MAT_DIFF 1 diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 5d1b4740645..cac2aab26dd 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -3589,6 +3589,7 @@ static void registerShaderNodes(void) register_node_type_sh_attribute(); register_node_type_sh_bevel(); + register_node_type_sh_displacement(); register_node_type_sh_geometry(); register_node_type_sh_light_path(); register_node_type_sh_light_falloff(); diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl index 07c3b1e782b..780f4f59fb9 100644 --- a/source/blender/gpu/shaders/gpu_shader_material.glsl +++ b/source/blender/gpu/shaders/gpu_shader_material.glsl @@ -4135,9 +4135,14 @@ void node_bevel(float radius, vec3 N, out vec3 result) result = N; } +void node_displacement(float height, float dist, vec3 N, out vec3 result) +{ + result = height * dist * N; +} + /* output */ -void node_output_material(Closure surface, Closure volume, float displacement, out Closure result) +void node_output_material(Closure surface, Closure volume, vec3 displacement, out Closure result) { #ifdef VOLUMETRICS result = volume; diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt index a6e04510b03..c83daa185a8 100644 --- a/source/blender/nodes/CMakeLists.txt +++ b/source/blender/nodes/CMakeLists.txt @@ -194,6 +194,7 @@ set(SRC shader/nodes/node_shader_subsurface_scattering.c shader/nodes/node_shader_tangent.c shader/nodes/node_shader_bevel.c + shader/nodes/node_shader_displacement.c shader/nodes/node_shader_tex_brick.c shader/nodes/node_shader_tex_checker.c shader/nodes/node_shader_tex_coord.c diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h index 62a92e8d084..cbdfd8d3dbf 100644 --- a/source/blender/nodes/NOD_shader.h +++ b/source/blender/nodes/NOD_shader.h @@ -79,6 +79,7 @@ void register_node_type_sh_tex_pointdensity(void); void register_node_type_sh_attribute(void); void register_node_type_sh_bevel(void); +void register_node_type_sh_displacement(void); void register_node_type_sh_geometry(void); void register_node_type_sh_light_path(void); void register_node_type_sh_light_falloff(void); diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h index a18ee154af8..e2c1fae1bde 100644 --- a/source/blender/nodes/NOD_static_types.h +++ b/source/blender/nodes/NOD_static_types.h @@ -128,6 +128,7 @@ DefNode( ShaderNode, SH_NODE_UVALONGSTROKE, def_sh_uvalongstroke, "UV DefNode( ShaderNode, SH_NODE_SEPXYZ, 0, "SEPXYZ", SeparateXYZ, "Separate XYZ", "" ) DefNode( ShaderNode, SH_NODE_COMBXYZ, 0, "COMBXYZ", CombineXYZ, "Combine XYZ", "" ) DefNode( ShaderNode, SH_NODE_BEVEL, def_sh_bevel, "BEVEL", Bevel, "Bevel", "" ) +DefNode( ShaderNode, SH_NODE_DISPLACEMENT, 0, "DISPLACEMENT", Displacement, "Displacement", "" ) DefNode( CompositorNode, CMP_NODE_VIEWER, def_cmp_viewer, "VIEWER", Viewer, "Viewer", "" ) DefNode( CompositorNode, CMP_NODE_RGB, 0, "RGB", RGB, "RGB", "" ) diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c index bd22a2be647..2f65188841e 100644 --- a/source/blender/nodes/shader/node_shader_tree.c +++ b/source/blender/nodes/shader/node_shader_tree.c @@ -460,6 +460,21 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree, * cycles in the Cycles material :) */ nodeRemLink(ntree, displacement_link); + + /* Convert displacement vector to bump height. */ + bNode *dot_node = nodeAddStaticNode(NULL, ntree, SH_NODE_VECT_MATH); + bNode *geo_node = nodeAddStaticNode(NULL, ntree, SH_NODE_NEW_GEOMETRY); + dot_node->custom1 = 3; /* dot product */ + + nodeAddLink(ntree, + displacement_node, displacement_socket, + dot_node, dot_node->inputs.first); + nodeAddLink(ntree, + geo_node, ntree_shader_node_find_output(geo_node, "Normal"), + dot_node, dot_node->inputs.last); + displacement_node = dot_node; + displacement_socket = ntree_shader_node_find_output(dot_node, "Value"); + /* We can't connect displacement to normal directly, use bump node for that * and hope that it gives good enough approximation. */ diff --git a/source/blender/nodes/shader/nodes/node_shader_displacement.c b/source/blender/nodes/shader/nodes/node_shader_displacement.c new file mode 100644 index 00000000000..d5c191b3966 --- /dev/null +++ b/source/blender/nodes/shader/nodes/node_shader_displacement.c @@ -0,0 +1,65 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2005 Blender Foundation. + * All rights reserved. + * + * The Original Code is: all of this file. + * + * Contributor(s): none yet. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#include "../node_shader_util.h" + +/* **************** OUTPUT ******************** */ + +static bNodeSocketTemplate sh_node_displacement_in[] = { + { SOCK_FLOAT, 0, N_("Height"), 0.00f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + { SOCK_FLOAT, 0, N_("Scale"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1000.0f}, + { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { -1, 0, "" } +}; + +static bNodeSocketTemplate sh_node_displacement_out[] = { + { SOCK_VECTOR, 0, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f}, + { -1, 0, "" } +}; + +static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out) +{ + if (!in[2].link) { + GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[2].link); + } + + return GPU_stack_link(mat, node, "node_displacement", in, out); +} + +/* node type definition */ +void register_node_type_sh_displacement(void) +{ + static bNodeType ntype; + + sh_node_type_base(&ntype, SH_NODE_DISPLACEMENT, "Displacement", NODE_CLASS_OP_VECTOR, 0); + node_type_compatibility(&ntype, NODE_NEW_SHADING); + node_type_socket_templates(&ntype, sh_node_displacement_in, sh_node_displacement_out); + node_type_storage(&ntype, "", NULL, NULL); + node_type_gpu(&ntype, gpu_shader_displacement); + + nodeRegisterType(&ntype); +} diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c index 0418b039337..e901e7c4590 100644 --- a/source/blender/nodes/shader/nodes/node_shader_output_material.c +++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c @@ -34,7 +34,7 @@ static bNodeSocketTemplate sh_node_output_material_in[] = { { SOCK_SHADER, 1, N_("Surface")}, { SOCK_SHADER, 1, N_("Volume")}, - { SOCK_FLOAT, 1, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, + { SOCK_VECTOR, 1, N_("Displacement"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, { -1, 0, "" } }; |