This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/intern/cycles/kernel/shaders/node_vector_math.osl
Charlie Jolly 635ab9d1dd Shading: Extend Vector Math Node with Sin, Cos, Tan and Wrap functions
This adds some extra functions recently added to the float Maths Node.
Not all functions have been ported over in this patch.

Also:
+ Tidy up menu
+ Change node color to match other vector nodes, this helps distinguish vector and float nodes in the tree
+ Move shared OSL functions to new header node_math.h

Reviewed By: brecht

Differential Revision: https://developer.blender.org/D6713
2020-02-14 22:14:05 +00:00

104 lines
2.7 KiB
Plaintext

/*
* 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 "stdcycles.h"
#include "node_math.h"
shader node_vector_math(string type = "add",
vector Vector1 = vector(0.0, 0.0, 0.0),
vector Vector2 = vector(0.0, 0.0, 0.0),
vector Vector3 = vector(0.0, 0.0, 0.0),
float Scale = 1.0,
output float Value = 0.0,
output vector Vector = vector(0.0, 0.0, 0.0))
{
if (type == "add") {
Vector = Vector1 + Vector2;
}
else if (type == "subtract") {
Vector = Vector1 - Vector2;
}
else if (type == "multiply") {
Vector = Vector1 * Vector2;
}
else if (type == "divide") {
Vector = safe_divide(Vector1, Vector2);
}
else if (type == "cross_product") {
Vector = cross(Vector1, Vector2);
}
else if (type == "project") {
Vector = project(Vector1, Vector2);
}
else if (type == "reflect") {
Vector = reflect(Vector1, normalize(Vector2));
}
else if (type == "dot_product") {
Value = dot(Vector1, Vector2);
}
else if (type == "distance") {
Value = distance(Vector1, Vector2);
}
else if (type == "length") {
Value = length(Vector1);
}
else if (type == "scale") {
Vector = Vector1 * Scale;
}
else if (type == "normalize") {
Vector = normalize(Vector1);
}
else if (type == "snap") {
Vector = snap(Vector1, Vector2);
}
else if (type == "floor") {
Vector = floor(Vector1);
}
else if (type == "ceil") {
Vector = ceil(Vector1);
}
else if (type == "modulo") {
Vector = fmod(Vector1, Vector2);
}
else if (type == "wrap") {
Vector = wrap(Vector1, Vector2, Vector3);
}
else if (type == "fraction") {
Vector = Vector1 - floor(Vector1);
}
else if (type == "absolute") {
Vector = abs(Vector1);
}
else if (type == "minimum") {
Vector = min(Vector1, Vector2);
}
else if (type == "maximum") {
Vector = max(Vector1, Vector2);
}
else if (type == "sine") {
Vector = sin(Vector1);
}
else if (type == "cosine") {
Vector = cos(Vector1);
}
else if (type == "tangent") {
Vector = tan(Vector1);
}
else {
warning("%s", "Unknown vector math operator!");
}
}