Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
xelatihy committed Jul 9, 2023
1 parent f0c46ab commit 0374651
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
12 changes: 6 additions & 6 deletions libs/yocto/yocto_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ array2d<vec4f> make_gnoisemap(const vec2i& extents, float scale,
return _make_proc_image(extents, [=](vec2i ij) -> vec4f {
auto uv = (8 * scale * ij) / extents;
auto value = gradient_noise(uv);
return lerp(color0, color1, clamp(value, 0, 1));
return lerp(color0, color1, clamp(value, 0.0f, 1.0f));
});
}

Expand All @@ -271,7 +271,7 @@ array2d<vec4f> make_vnoisemap(const vec2i& extents, float scale,
return _make_proc_image(extents, [=](vec2i ij) -> vec4f {
auto uv = (8 * scale * ij) / extents;
auto value = value_noise(uv);
return lerp(color0, color1, clamp(value, 0, 1));
return lerp(color0, color1, clamp(value, 0.0f, 1.0f));
});
}

Expand All @@ -280,7 +280,7 @@ array2d<vec4f> make_fnoisemap(const vec2i& extents, float scale,
return _make_proc_image(extents, [=](vec2i ij) -> vec4f {
auto uv = (8 * scale * ij) / extents;
auto value = fractal_noise(uv);
return lerp(color0, color1, clamp(value, 0, 1));
return lerp(color0, color1, clamp(value, 0.0f, 1.0f));
});
}

Expand All @@ -289,7 +289,7 @@ array2d<vec4f> make_tnoisemap(const vec2i& extents, float scale,
return _make_proc_image(extents, [=](vec2i ij) -> vec4f {
auto uv = (8 * scale * ij) / extents;
auto value = turbulence_noise(uv);
return lerp(color0, color1, clamp(value, 0, 1));
return lerp(color0, color1, clamp(value, 0.0f, 1.0f));
});
}

Expand All @@ -298,7 +298,7 @@ array2d<vec4f> make_rnoisemap(const vec2i& extents, float scale,
return _make_proc_image(extents, [=](vec2i ij) -> vec4f {
auto uv = (8 * scale * ij) / extents;
auto value = ridge_noise(uv);
return lerp(color0, color1, clamp(value, 0, 1));
return lerp(color0, color1, clamp(value, 0.0f, 1.0f));
});
}

Expand Down Expand Up @@ -442,7 +442,7 @@ array2d<vec4f> make_sunsky(const vec2i& extents, float theta_sun,
for (auto i : range(extents.x)) {
auto phi = 2 * pif * ((i + 0.5f) / extents.x);
auto w = vec3f{cos(phi) * sin(theta), cos(theta), sin(phi) * sin(theta)};
auto gamma = acos(clamp(dot(w, sun_direction), -1, 1));
auto gamma = acos(clamp(dot(w, sun_direction), -1.0f, 1.0f));
auto sky_col = sky(theta, gamma, theta_sun);
auto sun_col = sun(theta, gamma);
auto col = sky_col + sun_col;
Expand Down
7 changes: 1 addition & 6 deletions libs/yocto/yocto_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,12 @@ inline kernel float abs(float a) { return a < 0 ? -a : a; }
inline kernel float min(float a, float b) {
return (a < b) ? (float)a : (float)b;
}
inline kernel float min(float a, int b) { return (a < b) ? a : (float)b; }
inline kernel float max(float a, float b) {
return (a > b) ? (float)a : (float)b;
}
inline kernel float max(float a, int b) { return (a > b) ? a : (float)b; }
inline kernel float clamp(float a, float min_, float max_) {
return min(max(a, min_), max_);
}
inline kernel float clamp(float a, int min_, int max_) {
return min(max(a, min_), max_);
}
inline kernel float sign(float a) { return a < 0 ? (float)-1 : (float)1; }
inline kernel float sqr(float a) { return a * a; }
inline kernel float sqrt(float a) { return std::sqrt(a); }
Expand Down Expand Up @@ -889,7 +884,7 @@ inline kernel vec3f slerp(const vec3f& a, const vec3f& b, float u) {
d = -d;
}
if (d > (float)0.9995) return normalize(an + u * (bn - an));
auto theta = acos(clamp(d, (float)-1, (float)1));
auto theta = acos(clamp(d, -1.0f, 1.0f));
if (theta == 0) return an;
return an * (sin(theta * (1 - u)) / sin(theta)) +
bn * (sin(theta * u) / sin(theta));
Expand Down
2 changes: 1 addition & 1 deletion libs/yocto/yocto_shading.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ inline kernel vec3f sample_microfacet(float roughness, const vec3f& normal,
// TODO: check this line
auto Nh = t1 * T1 + t2 * T2 + sqrt(max(1 - t1 * t1 - t2 * t2, 0.0f)) * Vh;
// Section 3.4: transforming the normal back to the ellipsoid configuration
auto Ne = normalize(vec3f{alpha.x * Nh.x, alpha.y * Nh.y, max(Nh.z, 0)});
auto Ne = normalize(vec3f{alpha.x * Nh.x, alpha.y * Nh.y, max(Nh.z, 0.0f)});
// move to world coordinate
auto local_halfway = Ne;
return transform_direction(basis, local_halfway);
Expand Down

0 comments on commit 0374651

Please sign in to comment.