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
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/render/nodes.cpp')
-rw-r--r--intern/cycles/render/nodes.cpp126
1 files changed, 109 insertions, 17 deletions
diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp
index e8476bfac4c..7a39811cacd 100644
--- a/intern/cycles/render/nodes.cpp
+++ b/intern/cycles/render/nodes.cpp
@@ -11,12 +11,13 @@
* 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
+ * limitations under the License.
*/
#include "image.h"
#include "nodes.h"
#include "svm.h"
+#include "svm_math_util.h"
#include "osl.h"
#include "sky_model.h"
@@ -173,8 +174,10 @@ static ShaderEnum image_projection_init()
{
ShaderEnum enm;
- enm.insert("Flat", 0);
- enm.insert("Box", 1);
+ enm.insert("Flat", NODE_IMAGE_PROJ_FLAT);
+ enm.insert("Box", NODE_IMAGE_PROJ_BOX);
+ enm.insert("Sphere", NODE_IMAGE_PROJ_SPHERE);
+ enm.insert("Tube", NODE_IMAGE_PROJ_TUBE);
return enm;
}
@@ -265,14 +268,15 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
tex_mapping.compile(compiler, vector_in->stack_offset, vector_offset);
}
- if(projection == "Flat") {
+ if(projection != "Box") {
compiler.add_node(NODE_TEX_IMAGE,
slot,
compiler.encode_uchar4(
vector_offset,
color_out->stack_offset,
alpha_out->stack_offset,
- srgb));
+ srgb),
+ projection_enum[projection]);
}
else {
compiler.add_node(NODE_TEX_IMAGE_BOX,
@@ -284,7 +288,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler)
srgb),
__float_as_int(projection_blend));
}
-
+
if(vector_offset != vector_in->stack_offset)
compiler.stack_clear_offset(vector_in->type, vector_offset);
}
@@ -1945,6 +1949,8 @@ void EmissionNode::compile(OSLCompiler& compiler)
BackgroundNode::BackgroundNode()
: ShaderNode("background")
{
+ special_type = SHADER_SPECIAL_TYPE_BACKGROUND;
+
add_input("Color", SHADER_SOCKET_COLOR, make_float3(0.8f, 0.8f, 0.8f));
add_input("Strength", SHADER_SOCKET_FLOAT, 1.0f);
add_input("SurfaceMixWeight", SHADER_SOCKET_FLOAT, 0.0f, ShaderInput::USE_SVM);
@@ -2165,13 +2171,18 @@ GeometryNode::GeometryNode()
add_output("Incoming", SHADER_SOCKET_VECTOR);
add_output("Parametric", SHADER_SOCKET_POINT);
add_output("Backfacing", SHADER_SOCKET_FLOAT);
+ add_output("Pointiness", SHADER_SOCKET_FLOAT);
}
void GeometryNode::attributes(Shader *shader, AttributeRequestSet *attributes)
{
if(shader->has_surface) {
- if(!output("Tangent")->links.empty())
+ if(!output("Tangent")->links.empty()) {
attributes->add(ATTR_STD_GENERATED);
+ }
+ if(!output("Pointiness")->links.empty()) {
+ attributes->add(ATTR_STD_POINTINESS);
+ }
}
ShaderNode::attributes(shader, attributes);
@@ -2181,11 +2192,16 @@ void GeometryNode::compile(SVMCompiler& compiler)
{
ShaderOutput *out;
NodeType geom_node = NODE_GEOMETRY;
+ NodeType attr_node = NODE_ATTR;
- if(bump == SHADER_BUMP_DX)
+ if(bump == SHADER_BUMP_DX) {
geom_node = NODE_GEOMETRY_BUMP_DX;
- else if(bump == SHADER_BUMP_DY)
+ attr_node = NODE_ATTR_BUMP_DX;
+ }
+ else if(bump == SHADER_BUMP_DY) {
geom_node = NODE_GEOMETRY_BUMP_DY;
+ attr_node = NODE_ATTR_BUMP_DY;
+ }
out = output("Position");
if(!out->links.empty()) {
@@ -2228,6 +2244,15 @@ void GeometryNode::compile(SVMCompiler& compiler)
compiler.stack_assign(out);
compiler.add_node(NODE_LIGHT_PATH, NODE_LP_backfacing, out->stack_offset);
}
+
+ out = output("Pointiness");
+ if(!out->links.empty()) {
+ compiler.stack_assign(out);
+ compiler.add_node(attr_node,
+ ATTR_STD_POINTINESS,
+ out->stack_offset,
+ NODE_ATTR_FLOAT);
+ }
}
void GeometryNode::compile(OSLCompiler& compiler)
@@ -2257,6 +2282,8 @@ TextureCoordinateNode::TextureCoordinateNode()
add_output("Reflection", SHADER_SOCKET_NORMAL);
from_dupli = false;
+ use_transform = false;
+ ob_tfm = transform_identity();
}
void TextureCoordinateNode::attributes(Shader *shader, AttributeRequestSet *attributes)
@@ -2344,7 +2371,14 @@ void TextureCoordinateNode::compile(SVMCompiler& compiler)
out = output("Object");
if(!out->links.empty()) {
compiler.stack_assign(out);
- compiler.add_node(texco_node, NODE_TEXCO_OBJECT, out->stack_offset);
+ compiler.add_node(texco_node, NODE_TEXCO_OBJECT, out->stack_offset, use_transform);
+ if(use_transform) {
+ Transform ob_itfm = transform_inverse(ob_tfm);
+ compiler.add_node(ob_itfm.x);
+ compiler.add_node(ob_itfm.y);
+ compiler.add_node(ob_itfm.z);
+ compiler.add_node(ob_itfm.w);
+ }
}
out = output("Camera");
@@ -2385,7 +2419,10 @@ void TextureCoordinateNode::compile(OSLCompiler& compiler)
compiler.parameter("is_background", true);
if(compiler.output_type() == SHADER_TYPE_VOLUME)
compiler.parameter("is_volume", true);
-
+ compiler.parameter("use_transform", use_transform);
+ Transform ob_itfm = transform_transpose(transform_inverse(ob_tfm));
+ compiler.parameter("object_itfm", ob_itfm);
+
compiler.parameter("from_dupli", from_dupli);
compiler.add(this, "node_texture_coordinate");
@@ -3540,14 +3577,34 @@ void WireframeNode::compile(SVMCompiler& compiler)
{
ShaderInput *size_in = input("Size");
ShaderOutput *fac_out = output("Fac");
-
+ NodeBumpOffset bump_offset = NODE_BUMP_OFFSET_CENTER;
+ if(bump == SHADER_BUMP_DX) {
+ bump_offset = NODE_BUMP_OFFSET_DX;
+ }
+ else if(bump == SHADER_BUMP_DY) {
+ bump_offset = NODE_BUMP_OFFSET_DY;
+ }
compiler.stack_assign(size_in);
compiler.stack_assign(fac_out);
- compiler.add_node(NODE_WIREFRAME, size_in->stack_offset, fac_out->stack_offset, use_pixel_size);
+ compiler.add_node(NODE_WIREFRAME,
+ size_in->stack_offset,
+ fac_out->stack_offset,
+ compiler.encode_uchar4(use_pixel_size,
+ bump_offset,
+ 0, 0));
}
void WireframeNode::compile(OSLCompiler& compiler)
{
+ if(bump == SHADER_BUMP_DX) {
+ compiler.parameter("bump_offset", "dx");
+ }
+ else if(bump == SHADER_BUMP_DY) {
+ compiler.parameter("bump_offset", "dy");
+ }
+ else {
+ compiler.parameter("bump_offset", "center");
+ }
compiler.parameter("use_pixel_size", use_pixel_size);
compiler.add(this, "node_wireframe");
}
@@ -3669,7 +3726,7 @@ static ShaderEnum math_type_init()
enm.insert("Less Than", NODE_MATH_LESS_THAN);
enm.insert("Greater Than", NODE_MATH_GREATER_THAN);
enm.insert("Modulo", NODE_MATH_MODULO);
- enm.insert("Absolute", NODE_MATH_ABSOLUTE);
+ enm.insert("Absolute", NODE_MATH_ABSOLUTE);
return enm;
}
@@ -3682,9 +3739,24 @@ void MathNode::compile(SVMCompiler& compiler)
ShaderInput *value2_in = input("Value2");
ShaderOutput *value_out = output("Value");
+ compiler.stack_assign(value_out);
+
+ /* Optimize math node without links to a single value node. */
+ if(value1_in->link == NULL && value2_in->link == NULL) {
+ float optimized_value = svm_math((NodeMath)type_enum[type],
+ value1_in->value.x,
+ value2_in->value.x);
+ if(use_clamp) {
+ optimized_value = clamp(optimized_value, 0.0f, 1.0f);
+ }
+ compiler.add_node(NODE_VALUE_F,
+ __float_as_int(optimized_value),
+ value_out->stack_offset);
+ return;
+ }
+
compiler.stack_assign(value1_in);
compiler.stack_assign(value2_in);
- compiler.stack_assign(value_out);
compiler.add_node(NODE_MATH, type_enum[type], value1_in->stack_offset, value2_in->stack_offset);
compiler.add_node(NODE_MATH, value_out->stack_offset);
@@ -3738,11 +3810,31 @@ void VectorMathNode::compile(SVMCompiler& compiler)
ShaderOutput *value_out = output("Value");
ShaderOutput *vector_out = output("Vector");
- compiler.stack_assign(vector1_in);
- compiler.stack_assign(vector2_in);
compiler.stack_assign(value_out);
compiler.stack_assign(vector_out);
+ /* Optimize vector math node without links to a single value node. */
+ if(vector1_in->link == NULL && vector2_in->link == NULL) {
+ float optimized_value;
+ float3 optimized_vector;
+ svm_vector_math(&optimized_value,
+ &optimized_vector,
+ (NodeVectorMath)type_enum[type],
+ vector1_in->value,
+ vector2_in->value);
+
+ compiler.add_node(NODE_VALUE_F,
+ __float_as_int(optimized_value),
+ value_out->stack_offset);
+
+ compiler.add_node(NODE_VALUE_V, vector_out->stack_offset);
+ compiler.add_node(NODE_VALUE_V, optimized_vector);
+ return;
+ }
+
+ compiler.stack_assign(vector1_in);
+ compiler.stack_assign(vector2_in);
+
compiler.add_node(NODE_VECTOR_MATH, type_enum[type], vector1_in->stack_offset, vector2_in->stack_offset);
compiler.add_node(NODE_VECTOR_MATH, value_out->stack_offset, vector_out->stack_offset);
}