Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2013-05-10 20:57:17 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2013-05-10 20:57:17 +0400
commiteaa6479ae3482b643e6e5d553f09b1a1100b48ee (patch)
treea7fcb0702a4b463df1777f395575b4b5d0d9386d /intern
parent2f9f3dd5903eeec514640de05a45cfd21d168397 (diff)
Cycles: bump node changes to add a Distance input that controls the overall displacement
distance, and an Invert option to invert the bump effect.
Diffstat (limited to 'intern')
-rw-r--r--intern/cycles/blender/blender_shader.cpp5
-rw-r--r--intern/cycles/kernel/shaders/node_bump.osl12
-rw-r--r--intern/cycles/kernel/svm/svm_displace.h14
-rw-r--r--intern/cycles/render/nodes.cpp16
-rw-r--r--intern/cycles/render/nodes.h1
5 files changed, 36 insertions, 12 deletions
diff --git a/intern/cycles/blender/blender_shader.cpp b/intern/cycles/blender/blender_shader.cpp
index 7deb826a1e1..94415514e7b 100644
--- a/intern/cycles/blender/blender_shader.cpp
+++ b/intern/cycles/blender/blender_shader.cpp
@@ -394,7 +394,10 @@ static ShaderNode *add_node(Scene *scene, BL::BlendData b_data, BL::Scene b_scen
node = new HairInfoNode();
}
else if (b_node.is_a(&RNA_ShaderNodeBump)) {
- node = new BumpNode();
+ BL::ShaderNodeBump b_bump_node(b_node);
+ BumpNode *bump = new BumpNode();
+ bump->invert = b_bump_node.invert();
+ node = bump;
}
else if (b_node.is_a(&RNA_ShaderNodeScript)) {
#ifdef WITH_OSL
diff --git a/intern/cycles/kernel/shaders/node_bump.osl b/intern/cycles/kernel/shaders/node_bump.osl
index a7dd805149f..6d0ec51a9da 100644
--- a/intern/cycles/kernel/shaders/node_bump.osl
+++ b/intern/cycles/kernel/shaders/node_bump.osl
@@ -22,8 +22,10 @@
* Morten S. Mikkelsen, 2010 */
surface node_bump(
+ int invert = 0,
normal NormalIn = N,
- float Strength = 0.0,
+ float Strength = 0.1,
+ float Distance = 1.0,
float SampleCenter = 0.0,
float SampleX = 0.0,
float SampleY = 0.0,
@@ -42,10 +44,14 @@ surface node_bump(
float absdet = fabs(det);
- float strength = clamp(Strength, 0.0, 1.0);
+ float strength = max(Strength, 0.0);
+ float dist = Distance;
+
+ if (invert)
+ dist *= -1.0;
/* compute and output perturbed normal */
- NormalOut = normalize(absdet * NormalIn - sign(det) * surfgrad);
+ NormalOut = normalize(absdet * NormalIn - dist * sign(det) * surfgrad);
NormalOut = normalize(strength*NormalOut + (1.0 - strength)*NormalIn);
}
diff --git a/intern/cycles/kernel/svm/svm_displace.h b/intern/cycles/kernel/svm/svm_displace.h
index 5d0300c5855..ee3c0c6fd21 100644
--- a/intern/cycles/kernel/svm/svm_displace.h
+++ b/intern/cycles/kernel/svm/svm_displace.h
@@ -24,7 +24,10 @@ __device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stack,
{
#ifdef __RAY_DIFFERENTIALS__
/* get normal input */
- float3 normal_in = stack_valid(node.y)? stack_load_float3(stack, node.y): sd->N;
+ uint normal_offset, distance_offset, invert;
+ decode_node_uchar4(node.y, &normal_offset, &distance_offset, &invert, NULL);
+
+ float3 normal_in = stack_valid(normal_offset)? stack_load_float3(stack, normal_offset): sd->N;
/* get surface tangents from normal */
float3 Rx = cross(sd->dP.dy, normal_in);
@@ -45,10 +48,15 @@ __device void svm_node_set_bump(KernelGlobals *kg, ShaderData *sd, float *stack,
float absdet = fabsf(det);
float strength = stack_load_float(stack, strength_offset);
- strength = clamp(strength, 0.0f, 1.0f);
+ float distance = stack_load_float(stack, distance_offset);
+
+ if(invert)
+ distance *= -1.0f;
+
+ strength = max(strength, 0.0f);
/* compute and output perturbed normal */
- float3 normal_out = normalize(absdet*normal_in - signf(det)*surfgrad);
+ float3 normal_out = normalize(absdet*normal_in - distance*signf(det)*surfgrad);
normal_out = normalize(strength*normal_out + (1.0f - strength)*normal_in);
stack_store_float3(stack, node.w, normal_out);
#endif
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index 406b5876a4b..d7ac379739d 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -3047,6 +3047,8 @@ void VectorMathNode::compile(OSLCompiler& compiler)
BumpNode::BumpNode()
: ShaderNode("bump")
{
+ invert = false;
+
/* this input is used by the user, but after graph transform it is no longer
* used and moved to sampler center/x/y instead */
add_input("Height", SHADER_SOCKET_FLOAT);
@@ -3055,7 +3057,8 @@ BumpNode::BumpNode()
add_input("SampleX", SHADER_SOCKET_FLOAT);
add_input("SampleY", SHADER_SOCKET_FLOAT);
add_input("Normal", SHADER_SOCKET_NORMAL, ShaderInput::NORMAL);
- add_input("Strength", SHADER_SOCKET_FLOAT, 0.1f);
+ add_input("Strength", SHADER_SOCKET_FLOAT, 1.0f);
+ add_input("Distance", SHADER_SOCKET_FLOAT, 0.1f);
add_output("Normal", SHADER_SOCKET_NORMAL);
}
@@ -3066,13 +3069,15 @@ void BumpNode::compile(SVMCompiler& compiler)
ShaderInput *dx_in = input("SampleX");
ShaderInput *dy_in = input("SampleY");
ShaderInput *normal_in = input("Normal");
- ShaderInput *intensity_in = input("Strength");
+ ShaderInput *strength_in = input("Strength");
+ ShaderInput *distance_in = input("Distance");
ShaderOutput *normal_out = output("Normal");
compiler.stack_assign(center_in);
compiler.stack_assign(dx_in);
compiler.stack_assign(dy_in);
- compiler.stack_assign(intensity_in);
+ compiler.stack_assign(strength_in);
+ compiler.stack_assign(distance_in);
compiler.stack_assign(normal_out);
if(normal_in->link)
@@ -3080,14 +3085,15 @@ void BumpNode::compile(SVMCompiler& compiler)
/* pack all parameters in the node */
compiler.add_node(NODE_SET_BUMP,
- normal_in->stack_offset,
+ compiler.encode_uchar4(normal_in->stack_offset, distance_in->stack_offset, invert),
compiler.encode_uchar4(center_in->stack_offset, dx_in->stack_offset,
- dy_in->stack_offset, intensity_in->stack_offset),
+ dy_in->stack_offset, strength_in->stack_offset),
normal_out->stack_offset);
}
void BumpNode::compile(OSLCompiler& compiler)
{
+ compiler.parameter("invert", invert);
compiler.add(this, "node_bump");
}
diff --git a/intern/cycles/render/nodes.h b/intern/cycles/render/nodes.h
index 85829e00782..41fa87a3859 100644
--- a/intern/cycles/render/nodes.h
+++ b/intern/cycles/render/nodes.h
@@ -470,6 +470,7 @@ public:
class BumpNode : public ShaderNode {
public:
SHADER_NODE_CLASS(BumpNode)
+ bool invert;
};
class RGBCurvesNode : public ShaderNode {