MaterialX: Implement Gradient Texture node. #28

Merged
Bogdan Nagirniak merged 6 commits from Vasyl-Pidhirskyi/blender:BLEN-550 into matx-export-material 2023-09-21 09:31:28 +02:00
Showing only changes of commit b74cc377a1 - Show all commits

View File

@ -177,10 +177,16 @@ 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:
/* 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. */
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

use res = res.dotproduct(res).sqrt()

use `res = res.dotproduct(res).sqrt()`
res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f)); res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f));
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

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

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);
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); ```

Added comment

Added comment
res = res * res; res = res * res;
break; break;
case SHD_BLEND_SPHERICAL: case SHD_BLEND_SPHERICAL:
/* 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. */
res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f)); res = (val(0.999999f) - vector.dotproduct(vector).sqrt()).max(val(0.0f));
Vasyl-Pidhirskyi marked this conversation as resolved Outdated

add default: BLI_assert_unreachable()

add `default: BLI_assert_unreachable()`
break; break;
default: default: