Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

small fix for noise sign #1473

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading