Skip to content

Commit 633c89e

Browse files
committed
clang format
1 parent 6273937 commit 633c89e

3 files changed

Lines changed: 206 additions & 176 deletions

File tree

src/testrender/shading.cpp

Lines changed: 104 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,24 +1516,22 @@ struct ZeltnerBurleySheen final : public BSDF, MxSheenParams {
15161516

15171517
struct HenyeyGreenstein final : public BSDF {
15181518
const float g;
1519-
OSL_HOSTDEVICE HenyeyGreenstein(float g)
1520-
: BSDF(this),
1521-
g(g)
1522-
{
1523-
}
1519+
OSL_HOSTDEVICE HenyeyGreenstein(float g) : BSDF(this), g(g) {}
15241520

1525-
static OSL_HOSTDEVICE float PhaseHG(float cos_theta, float g) {
1521+
static OSL_HOSTDEVICE float PhaseHG(float cos_theta, float g)
1522+
{
15261523
const float denom = 1 + g * g + 2 * g * cos_theta;
15271524
return (1 - g * g) / (4 * M_PI * denom * sqrtf(denom));
15281525
}
15291526

1530-
OSL_HOSTDEVICE Sample eval(const Vec3& wo, const Vec3& wi) const
1527+
OSL_HOSTDEVICE Sample eval(const Vec3& wo, const Vec3& wi) const
15311528
{
15321529
const float pdf = PhaseHG(dot(wo, wi), g);
15331530
return { wi, Color3(pdf), pdf, 0.0f };
15341531
}
15351532

1536-
OSL_HOSTDEVICE Sample sample(const Vec3& wo, float rx, float ry, float rz) const
1533+
OSL_HOSTDEVICE Sample sample(const Vec3& wo, float rx, float ry,
1534+
float rz) const
15371535
{
15381536
TangentFrame frame = TangentFrame::from_normal(wo);
15391537

@@ -1542,20 +1540,21 @@ struct HenyeyGreenstein final : public BSDF {
15421540
cos_theta = 1.0f - 2.0f * rx;
15431541
} else {
15441542
float sqr_term = (1 - g * g) / (1 - g + 2 * g * rx);
1545-
cos_theta = (1 + g * g - sqr_term * sqr_term) / (2 * g);
1546-
cos_theta = OIIO::clamp(cos_theta, -1.0f, 1.0f);
1543+
cos_theta = (1 + g * g - sqr_term * sqr_term) / (2 * g);
1544+
cos_theta = OIIO::clamp(cos_theta, -1.0f, 1.0f);
15471545
}
15481546

1549-
float sin_theta = sqrtf(OIIO::clamp(1.0f - cos_theta * cos_theta, 0.0f, 1.0f));
1550-
float phi = 2 * M_PI * ry;
1551-
Vec3 local_wi = Vec3(sin_theta * cosf(phi), sin_theta * sinf(phi), cos_theta);
1547+
float sin_theta = sqrtf(
1548+
OIIO::clamp(1.0f - cos_theta * cos_theta, 0.0f, 1.0f));
1549+
float phi = 2 * M_PI * ry;
1550+
Vec3 local_wi = Vec3(sin_theta * cosf(phi), sin_theta * sinf(phi),
1551+
cos_theta);
15521552

1553-
Vec3 wi = frame.toworld(local_wi);
1553+
Vec3 wi = frame.toworld(local_wi);
15541554
float pdf_val = PhaseHG(cos_theta, g);
15551555

15561556
return { wi, Color3(1.0f), pdf_val, 0.0f };
15571557
}
1558-
15591558
};
15601559

15611560
struct HomogeneousMedium final : public Medium {
@@ -1566,46 +1565,43 @@ struct HomogeneousMedium final : public Medium {
15661565
{
15671566
}
15681567

1569-
OSL_HOSTDEVICE static HomogeneousMedium* create(void* storage, const MediumParams& params) {
1568+
OSL_HOSTDEVICE static HomogeneousMedium* create(void* storage,
1569+
const MediumParams& params)
1570+
{
15701571
HomogeneousMedium* volume = new (storage) HomogeneousMedium(params);
1571-
volume->phase_func = new HenyeyGreenstein(params.medium_g);
1572+
volume->phase_func = new HenyeyGreenstein(params.medium_g);
15721573
return volume;
15731574
}
15741575

1575-
OSL_HOSTDEVICE Medium::Sample sample(Ray& r, Sampler &sampler, Intersection& hit) const
1576+
OSL_HOSTDEVICE Medium::Sample sample(Ray& r, Sampler& sampler,
1577+
Intersection& hit) const
15761578
{
15771579
Vec3 rand_vol = sampler.get();
15781580

15791581
float t_volume = -logf(1.0f - rand_vol.x) / params.avg_sigma_t();
15801582

15811583
Color3 weight;
15821584
Color3 tr;
1583-
1585+
15841586
if (t_volume < hit.t) {
15851587
r.origin = r.point(t_volume);
1586-
tr = transmittance(t_volume);
1588+
tr = transmittance(t_volume);
15871589

15881590
Color3 albedo = params.sigma_s / params.sigma_t;
15891591

15901592
weight = albedo / tr;
15911593
} else {
1592-
tr = transmittance(hit.t);
1593-
weight = Color3(
1594-
1.0 / tr.x,
1595-
1.0 / tr.y,
1596-
1.0 / tr.z
1597-
);
1594+
tr = transmittance(hit.t);
1595+
weight = Color3(1.0 / tr.x, 1.0 / tr.y, 1.0 / tr.z);
15981596
}
1599-
1597+
16001598
return Medium::Sample { t_volume, tr, weight };
16011599
}
16021600

1603-
OSL_HOSTDEVICE const MediumParams* get_params() const {
1604-
return &params;
1605-
}
1601+
OSL_HOSTDEVICE const MediumParams* get_params() const { return &params; }
16061602

16071603
OSL_HOSTDEVICE Color3 transmittance(float distance) const
1608-
{ // Beer-Lambert law
1604+
{ // Beer-Lambert law
16091605
return Color3(expf(-params.sigma_t.x * distance),
16101606
expf(-params.sigma_t.y * distance),
16111607
expf(-params.sigma_t.z * distance));
@@ -1620,19 +1616,20 @@ struct EmptyMedium final : public Medium {
16201616
{
16211617
}
16221618

1623-
OSL_HOSTDEVICE static EmptyMedium* create(void* storage, const MediumParams& params) {
1619+
OSL_HOSTDEVICE static EmptyMedium* create(void* storage,
1620+
const MediumParams& params)
1621+
{
16241622
EmptyMedium* volume = new (storage) EmptyMedium(params);
16251623
return volume;
16261624
}
16271625

1628-
OSL_HOSTDEVICE Medium::Sample sample(Ray& ray, Sampler &sampler, Intersection& hit) const
1626+
OSL_HOSTDEVICE Medium::Sample sample(Ray& ray, Sampler& sampler,
1627+
Intersection& hit) const
16291628
{
16301629
return { 0.0f, Color3(1.0f), Color3(1.0f) };
16311630
}
16321631

1633-
OSL_HOSTDEVICE const MediumParams* get_params() const {
1634-
return &params;
1635-
}
1632+
OSL_HOSTDEVICE const MediumParams* get_params() const { return &params; }
16361633
};
16371634

16381635

@@ -1729,7 +1726,7 @@ evaluate_layer_opacity(const ShaderGlobalsType& sg, float path_roughness,
17291726

17301727
OSL_HOSTDEVICE void
17311728
process_medium_closure(const ShaderGlobalsType& sg, float path_roughness,
1732-
ShadingResult& result, MediumStack &medium_stack,
1729+
ShadingResult& result, MediumStack& medium_stack,
17331730
const ClosureColor* closure, const Color3& w)
17341731
{
17351732
if (!closure)
@@ -1772,45 +1769,50 @@ process_medium_closure(const ShaderGlobalsType& sg, float path_roughness,
17721769
const ClosureComponent* comp = closure->as_comp();
17731770
Color3 cw = weight * comp->w;
17741771
const auto& params = *comp->as<MxAnisotropicVdfParams>();
1775-
result.medium_data.sigma_t = cw * params.extinction;
1776-
result.medium_data.sigma_s = params.albedo * result.medium_data.sigma_t;
1777-
result.medium_data.medium_g = params.anisotropy;
1778-
result.medium_data.priority = 0;
1772+
result.medium_data.sigma_t = cw * params.extinction;
1773+
result.medium_data.sigma_s = params.albedo
1774+
* result.medium_data.sigma_t;
1775+
result.medium_data.medium_g = params.anisotropy;
1776+
result.medium_data.priority = 0;
17791777

1780-
if (!sg.backfacing) { // if entering
1778+
if (!sg.backfacing) { // if entering
17811779
if (result.medium_data.is_vaccum()) {
17821780
medium_stack.add_medium<EmptyMedium>(result.medium_data);
17831781
} else {
1784-
medium_stack.add_medium<HomogeneousMedium>(result.medium_data);
1782+
medium_stack.add_medium<HomogeneousMedium>(
1783+
result.medium_data);
17851784
}
17861785
}
17871786

1788-
closure = nullptr;
1787+
closure = nullptr;
17891788
break;
17901789
}
17911790
case MX_MEDIUM_VDF_ID: {
17921791
const ClosureComponent* comp = closure->as_comp();
17931792
Color3 cw = weight * comp->w;
17941793
const auto& params = *comp->as<MxMediumVdfParams>();
17951794

1796-
result.medium_data.sigma_t = Color3(
1797-
-OIIO::fast_log(params.transmission_color.x),
1798-
-OIIO::fast_log(params.transmission_color.y),
1799-
-OIIO::fast_log(params.transmission_color.z)
1800-
);
1801-
1795+
result.medium_data.sigma_t
1796+
= Color3(-OIIO::fast_log(params.transmission_color.x),
1797+
-OIIO::fast_log(params.transmission_color.y),
1798+
-OIIO::fast_log(params.transmission_color.z));
1799+
18021800
result.medium_data.sigma_t *= cw / params.transmission_depth;
1803-
result.medium_data.sigma_s = params.albedo * result.medium_data.sigma_t;
1801+
result.medium_data.sigma_s = params.albedo
1802+
* result.medium_data.sigma_t;
18041803
result.medium_data.medium_g = params.anisotropy;
1805-
1806-
result.medium_data.refraction_ior = sg.backfacing ? 1.0f / params.ior : params.ior;
1807-
result.medium_data.priority = params.priority;
1808-
1809-
if (!sg.backfacing) { // if entering
1804+
1805+
result.medium_data.refraction_ior = sg.backfacing
1806+
? 1.0f / params.ior
1807+
: params.ior;
1808+
result.medium_data.priority = params.priority;
1809+
1810+
if (!sg.backfacing) { // if entering
18101811
if (result.medium_data.is_vaccum()) {
18111812
medium_stack.add_medium<EmptyMedium>(result.medium_data);
18121813
} else {
1813-
medium_stack.add_medium<HomogeneousMedium>(result.medium_data);
1814+
medium_stack.add_medium<HomogeneousMedium>(
1815+
result.medium_data);
18141816
}
18151817
}
18161818

@@ -1822,12 +1824,16 @@ process_medium_closure(const ShaderGlobalsType& sg, float path_roughness,
18221824
const MxDielectric::Data& params = *comp->as<MxDielectric::Data>();
18231825
if (!is_black(weight * comp->w * params.refr_tint)) {
18241826
float new_ior = sg.backfacing ? 1.0f / params.IOR : params.IOR;
1825-
1826-
result.medium_data.refraction_ior = new_ior;
18271827

1828-
const MediumParams* current_params = medium_stack.current_params();
1829-
if (current_params && result.medium_data.priority <= current_params->priority) {
1830-
result.medium_data.refraction_ior = current_params->refraction_ior;
1828+
result.medium_data.refraction_ior = new_ior;
1829+
1830+
const MediumParams* current_params
1831+
= medium_stack.current_params();
1832+
if (current_params
1833+
&& result.medium_data.priority
1834+
<= current_params->priority) {
1835+
result.medium_data.refraction_ior
1836+
= current_params->refraction_ior;
18311837
}
18321838
}
18331839
closure = nullptr;
@@ -1837,17 +1843,22 @@ process_medium_closure(const ShaderGlobalsType& sg, float path_roughness,
18371843
const ClosureComponent* comp = closure->as_comp();
18381844
const auto& params = *comp->as<MxGeneralizedSchlickParams>();
18391845
if (!is_black(weight * comp->w * params.transmission_tint)) {
1840-
float avg_F0 = clamp((params.f0.x + params.f0.y + params.f0.z) / 3.0f,
1841-
0.0f, 0.99f);
1846+
float avg_F0 = clamp((params.f0.x + params.f0.y + params.f0.z)
1847+
/ 3.0f,
1848+
0.0f, 0.99f);
18421849
float sqrt_F0 = sqrtf(avg_F0);
18431850
float ior = (1 + sqrt_F0) / (1 - sqrt_F0);
18441851
float new_ior = sg.backfacing ? 1.0f / ior : ior;
1845-
1846-
result.medium_data.refraction_ior = new_ior;
18471852

1848-
const MediumParams* current_params = medium_stack.current_params();
1849-
if (current_params && result.medium_data.priority <= current_params->priority) {
1850-
result.medium_data.refraction_ior = current_params->refraction_ior;
1853+
result.medium_data.refraction_ior = new_ior;
1854+
1855+
const MediumParams* current_params
1856+
= medium_stack.current_params();
1857+
if (current_params
1858+
&& result.medium_data.priority
1859+
<= current_params->priority) {
1860+
result.medium_data.refraction_ior
1861+
= current_params->refraction_ior;
18511862
}
18521863
}
18531864
closure = nullptr;
@@ -1865,8 +1876,8 @@ process_medium_closure(const ShaderGlobalsType& sg, float path_roughness,
18651876
// recursively walk through the closure tree, creating bsdfs as we go
18661877
OSL_HOSTDEVICE void
18671878
process_bsdf_closure(const ShaderGlobalsType& sg, float path_roughness,
1868-
ShadingResult& result, MediumStack& medium_stack,
1869-
const ClosureColor* closure, const Color3& w,
1879+
ShadingResult& result, MediumStack& medium_stack,
1880+
const ClosureColor* closure, const Color3& w,
18701881
bool light_only)
18711882
{
18721883
static const ustringhash uh_ggx("ggx");
@@ -2000,12 +2011,15 @@ process_bsdf_closure(const ShaderGlobalsType& sg, float path_roughness,
20002011
case MxDielectric::closureid(): {
20012012
const MxDielectric::Data& params
20022013
= *comp->as<MxDielectric::Data>();
2003-
2004-
if (medium_stack.false_intersection_with(result.medium_data)) {
2014+
2015+
if (medium_stack.false_intersection_with(
2016+
result.medium_data)) {
20052017
ok = result.bsdf.add_bsdf<Transparent>(cw);
20062018
} else {
2007-
ok = result.bsdf.add_bsdf<MxDielectric>(cw, params, -sg.I,
2008-
sg.backfacing, path_roughness);
2019+
ok = result.bsdf.add_bsdf<MxDielectric>(cw, params,
2020+
-sg.I,
2021+
sg.backfacing,
2022+
path_roughness);
20092023
}
20102024
break;
20112025
}
@@ -2020,14 +2034,14 @@ process_bsdf_closure(const ShaderGlobalsType& sg, float path_roughness,
20202034
const MxGeneralizedSchlickParams& params
20212035
= *comp->as<MxGeneralizedSchlickParams>();
20222036

2023-
if (medium_stack.false_intersection_with(result.medium_data)) {
2037+
if (medium_stack.false_intersection_with(
2038+
result.medium_data)) {
20242039
ok = result.bsdf.add_bsdf<Transparent>(cw);
20252040
} else {
20262041
if (is_black(params.transmission_tint)) {
20272042
ok = result.bsdf.add_bsdf<MxMicrofacet<
2028-
MxGeneralizedSchlickParams, GGXDist, false>>(cw,
2029-
params,
2030-
1.0f);
2043+
MxGeneralizedSchlickParams, GGXDist, false>>(
2044+
cw, params, 1.0f);
20312045
} else {
20322046
ok = result.bsdf.add_bsdf<MxMicrofacet<
20332047
MxGeneralizedSchlickParams, GGXDist, true>>(
@@ -2122,12 +2136,14 @@ process_bsdf_closure(const ShaderGlobalsType& sg, float path_roughness,
21222136

21232137
OSL_HOSTDEVICE void
21242138
process_closure(const ShaderGlobalsType& sg, float path_roughness,
2125-
ShadingResult& result, MediumStack &medium_stack,
2139+
ShadingResult& result, MediumStack& medium_stack,
21262140
const ClosureColor* Ci, bool light_only)
21272141
{
21282142
if (!light_only)
2129-
process_medium_closure(sg, path_roughness, result, medium_stack, Ci, Color3(1));
2130-
process_bsdf_closure(sg, path_roughness, result, medium_stack, Ci, Color3(1), light_only);
2143+
process_medium_closure(sg, path_roughness, result, medium_stack, Ci,
2144+
Color3(1));
2145+
process_bsdf_closure(sg, path_roughness, result, medium_stack, Ci,
2146+
Color3(1), light_only);
21312147
}
21322148

21332149
OSL_HOSTDEVICE Vec3
@@ -2188,12 +2204,15 @@ BSDF::sample_vrtl(const Vec3& wo, float rx, float ry, float rz) const
21882204
return dispatch([&](auto bsdf) { return bsdf.sample(wo, rx, ry, rz); });
21892205
}
21902206

2191-
Medium::Sample Medium::sample_vrtl(Ray& ray, Sampler &sampler, Intersection& hit) const
2207+
Medium::Sample
2208+
Medium::sample_vrtl(Ray& ray, Sampler& sampler, Intersection& hit) const
21922209
{
2193-
return dispatch([&](const auto& medium) { return medium.sample(ray, sampler, hit); });
2210+
return dispatch(
2211+
[&](const auto& medium) { return medium.sample(ray, sampler, hit); });
21942212
}
21952213

2196-
const MediumParams* Medium::get_params_vrtl() const
2214+
const MediumParams*
2215+
Medium::get_params_vrtl() const
21972216
{
21982217
return dispatch([&](const auto& medium) { return medium.get_params(); });
21992218
}

0 commit comments

Comments
 (0)