Skip to content

Commit

Permalink
Run clang-format
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Kulla <ckulla@gmail.com>
  • Loading branch information
fpsunflower committed Jun 6, 2024
1 parent 78a621e commit 4caeef0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
16 changes: 10 additions & 6 deletions src/testrender/sampling.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,22 @@ OSL_NAMESPACE_ENTER

struct TangentFrame {
// build frame from unit normal
static TangentFrame from_normal(const Vec3& n) {
static TangentFrame from_normal(const Vec3& n)
{
// https://graphics.pixar.com/library/OrthonormalB/paper.pdf
const float sign = copysignf(1.0f, n.z);
const float a = -1 / (sign + n.z);
const float b = n.x * n.y * a;
const float a = -1 / (sign + n.z);
const float b = n.x * n.y * a;
const Vec3 u = Vec3(1 + sign * n.x * n.x * a, sign * b, -sign * n.x);
const Vec3 v = Vec3(b, sign + n.y * n.y * a, -n.y);
return { u, v, n };
}

// build frame from unit normal and unit tangent
// fallsback to an arbitrary basis if the tangent is 0 or colinear with n
static TangentFrame from_normal_and_tangent(const Vec3& n, const Vec3& t) {
Vec3 y = n.cross(t);
static TangentFrame from_normal_and_tangent(const Vec3& n, const Vec3& t)
{
Vec3 y = n.cross(t);
float ylen2 = dot(y, y);
if (ylen2 > 0) {
y *= 1.0f / sqrtf(ylen2);
Expand Down Expand Up @@ -95,7 +97,9 @@ struct Sampling {
float phi = float(2 * M_PI) * rndx;
float cos_theta = rndy;
float sin_theta = sqrtf(1 - cos_theta * cos_theta);
out = TangentFrame::from_normal(N).get(sin_theta * cosf(phi), sin_theta * sinf(phi), cos_theta);
out = TangentFrame::from_normal(N).get(sin_theta * cosf(phi),
sin_theta * sinf(phi),
cos_theta);
pdf = float(0.5 * M_1_PI);
}
};
Expand Down
13 changes: 8 additions & 5 deletions src/testrender/shading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -593,14 +593,15 @@ struct Phong final : public BSDF, PhongParams {
float cosNO = N.dot(wo);
if (cosNO > 0) {
// reflect the view vector
Vec3 R = (2 * cosNO) * N - wo;
Vec3 R = (2 * cosNO) * N - wo;
float phi = 2 * float(M_PI) * rx;
float sp, cp;
OIIO::fast_sincos(phi, &sp, &cp);
float cosTheta = OIIO::fast_safe_pow(ry, 1 / (exponent + 1));
float sinTheta2 = 1 - cosTheta * cosTheta;
float sinTheta = sinTheta2 > 0 ? sqrtf(sinTheta2) : 0;
Vec3 wi = TangentFrame::from_normal(R).get(cp * sinTheta, sp * sinTheta, cosTheta);
Vec3 wi = TangentFrame::from_normal(R).get(cp * sinTheta,
sp * sinTheta, cosTheta);
return eval(wo, wi);
}
return {};
Expand Down Expand Up @@ -1036,7 +1037,8 @@ struct MxMicrofacet final : public BSDF, MxMicrofacetParams {
MxMicrofacet(const MxMicrofacetParams& params, float refraction_ior)
: BSDF()
, MxMicrofacetParams(params)
, tf(TangentFrame::from_normal_and_tangent(MxMicrofacetParams::N, MxMicrofacetParams::U))
, tf(TangentFrame::from_normal_and_tangent(MxMicrofacetParams::N,
MxMicrofacetParams::U))
, refraction_ior(refraction_ior)
{
}
Expand Down Expand Up @@ -1470,7 +1472,8 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {
const float NdotV = clamp(N.dot(V), 0.0f, 1.0f);
const Vec3 ltc = fetch_ltc(NdotV);

const Vec3 localL = TangentFrame::from_normal_and_tangent(N, V).tolocal(L);
const Vec3 localL = TangentFrame::from_normal_and_tangent(N, V).tolocal(
L);

const float aInv = ltc.x, bInv = ltc.y, R = ltc.z;
Vec3 wiOriginal(aInv * localL.x + bInv * localL.z, aInv * localL.y,
Expand Down Expand Up @@ -1507,7 +1510,7 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {
const float jacobian = len2 * len2 / (aInv * aInv);
const Vec3 wn = w / sqrtf(len2);

const Vec3 L = TangentFrame::from_normal_and_tangent(N, V).toworld(wn);
const Vec3 L = TangentFrame::from_normal_and_tangent(N, V).toworld(wn);

pdf = jacobian * std::max(wn.z, 0.0f) * float(M_1_PI);

Expand Down

0 comments on commit 4caeef0

Please sign in to comment.