forked from blender/blender
MaterialX: Implement Gradient Texture node. #28
@ -233,7 +233,8 @@ NodeItem NodeItem::max(const NodeItem &other) const
|
|||||||
|
|
||||||
NodeItem NodeItem::dotproduct(const NodeItem &other) const
|
NodeItem NodeItem::dotproduct(const NodeItem &other) const
|
||||||
{
|
{
|
||||||
NodeItem d = arithmetic(other, "dotproduct", [](float a, float b) { return a * b; });
|
NodeItem d = arithmetic(
|
||||||
|
other, "dotproduct", [](float a, float b) { return a * b; }, Type::Float);
|
||||||
if (d.value) {
|
if (d.value) {
|
||||||
float f = 0.0f;
|
float f = 0.0f;
|
||||||
switch (d.type()) {
|
switch (d.type()) {
|
||||||
@ -830,12 +831,13 @@ NodeItem NodeItem::arithmetic(const std::string &category, std::function<float(f
|
|||||||
|
|
||||||
NodeItem NodeItem::arithmetic(const NodeItem &other,
|
NodeItem NodeItem::arithmetic(const NodeItem &other,
|
||||||
const std::string &category,
|
const std::string &category,
|
||||||
std::function<float(float, float)> func) const
|
std::function<float(float, float)> func,
|
||||||
|
Type to_type) const
|
||||||
{
|
{
|
||||||
NodeItem res = empty();
|
NodeItem res = empty();
|
||||||
NodeItem item1 = *this;
|
NodeItem item1 = *this;
|
||||||
NodeItem item2 = other;
|
NodeItem item2 = other;
|
||||||
Type to_type = cast_types(item1, item2);
|
to_type = (to_type == Type::Any) ? cast_types(item1, item2) : to_type;
|
||||||
if (to_type == Type::Empty) {
|
if (to_type == Type::Empty) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,8 @@ class NodeItem {
|
|||||||
NodeItem arithmetic(const std::string &category, std::function<float(float)> func) const;
|
NodeItem arithmetic(const std::string &category, std::function<float(float)> func) const;
|
||||||
NodeItem arithmetic(const NodeItem &other,
|
NodeItem arithmetic(const NodeItem &other,
|
||||||
const std::string &category,
|
const std::string &category,
|
||||||
std::function<float(float, float)> func) const;
|
std::function<float(float, float)> func,
|
||||||
|
Type to_type = Type::Any) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T> NodeItem NodeItem::val(const T &data) const
|
template<class T> NodeItem NodeItem::val(const T &data) const
|
||||||
|
@ -177,13 +177,11 @@ NODE_SHADER_MATERIALX_BEGIN
|
|||||||
res = vector.extract(1).atan2(vector.extract(0)) / (val(float(M_PI * 2.0f))) + val(0.5f);
|
res = vector.extract(1).atan2(vector.extract(0)) / (val(float(M_PI * 2.0f))) + val(0.5f);
|
||||||
break;
|
break;
|
||||||
case SHD_BLEND_QUADRATIC_SPHERE:
|
case SHD_BLEND_QUADRATIC_SPHERE:
|
||||||
res = create_node("dotproduct", NodeItem::Type::Float, {{"in1", vector}, {"in2", vector}}).sqrt();
|
res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f));
|
||||||
res = (val(0.999999f) - res).max(val(0.0f));
|
|
||||||
res = res * res;
|
res = res * res;
|
||||||
break;
|
break;
|
||||||
Vasyl-Pidhirskyi marked this conversation as resolved
Outdated
|
|||||||
case SHD_BLEND_SPHERICAL:
|
case SHD_BLEND_SPHERICAL:
|
||||||
Vasyl-Pidhirskyi marked this conversation as resolved
Outdated
Bogdan Nagirniak
commented
Why not 1.0f? Need comment why 0.999999f is used instead of 1.0f Why not 1.0f? Need comment why 0.999999f is used instead of 1.0f
Vasyl Pidhirskyi
commented
It's made according to Blender's implementation.
It's made according to Blender's implementation.
```
/* Bias a little bit for the case where input is a unit length vector,
* to get exactly zero instead of a small random value depending
* on float precision. */
const float r = std::max(0.999999f - math::length(vector[i]), 0.0f);
```
Vasyl Pidhirskyi
commented
Added comment Added comment
|
|||||||
res = create_node("dotproduct", NodeItem::Type::Float, {{"in1", vector}, {"in2", vector}}).sqrt();
|
res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f));
|
||||||
res = (val(0.999999f) - res).max(val(0.0f));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
BLI_assert_unreachable();
|
BLI_assert_unreachable();
|
||||||
|
Loading…
Reference in New Issue
Block a user
use
res = res.dotproduct(res).sqrt()