Skip to content

Commit

Permalink
Merge pull request #1473 from zenustech/noiseImage
Browse files Browse the repository at this point in the history
small fix for noise sign
  • Loading branch information
zhouhang95 authored Oct 17, 2023
2 parents b0d7d32 + 0ba2dac commit 9b8aece
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions zeno/src/nodes/prim/WBNoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,12 @@ float scnoise(float x, float y, float z, int pulsenum, int griddist) {
//}

struct NoiseImageGen : INode {
// quick tofix source:
// https://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
template <typename T> int sgn(T val) {
return (T(0) < val) - (val < T(0));
}

virtual void apply() override {
auto perC = get_input2<bool>("noise per component");
auto image_size = get_input2<vec2i>("image size");
Expand Down Expand Up @@ -944,10 +950,15 @@ struct NoiseImageGen : INode {
}

if (perC) {
image->verts[i] = pow(vec3f(r, g, b), exponent);
alpha[i] = r+g+b; // tofix: proper expression? as well as amplitude related
image->verts[i] = vec3f(
sgn(r) * pow(abs(r), exponent),
sgn(g) * pow(abs(g), exponent),
sgn(b) * pow(abs(b), exponent)
);
alpha[i] = r+g+b; // tofix: proper expression? is amplitude itrelated?
} else {
image->verts[i] = pow(vec3f(r, r, r), exponent);
float er = sgn(r) * pow(abs(r), exponent);
image->verts[i] = vec3f(er, er, er);
alpha[i] = r;
}
}
Expand Down

0 comments on commit 9b8aece

Please sign in to comment.