Skip to content

Commit db454c0

Browse files
committed
plain const for vector types
1 parent 3f3b5c9 commit db454c0

11 files changed

+34
-34
lines changed

include/nbl/builtin/hlsl/sampling/bilinear.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ struct Bilinear
2424
using vector3_type = vector<T, 3>;
2525
using vector4_type = vector<T, 4>;
2626

27-
static Bilinear<T> create(NBL_CONST_REF_ARG(vector4_type) bilinearCoeffs)
27+
static Bilinear<T> create(const vector4_type bilinearCoeffs)
2828
{
2929
Bilinear<T> retval;
3030
retval.bilinearCoeffs = bilinearCoeffs;
3131
retval.twiceAreasUnderXCurve = vector2_type(bilinearCoeffs[0] + bilinearCoeffs[1], bilinearCoeffs[2] + bilinearCoeffs[3]);
3232
return retval;
3333
}
3434

35-
vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector2_type) _u)
35+
vector2_type generate(NBL_REF_ARG(scalar_type) rcpPdf, const vector2_type _u)
3636
{
37-
vector2_type u = _u;
37+
vector2_type u;
3838
Linear<scalar_type> lineary = Linear<scalar_type>::create(twiceAreasUnderXCurve);
39-
u.y = lineary.generate(u.y);
39+
u.y = lineary.generate(_u.y);
4040

4141
const vector2_type ySliceEndPoints = vector2_type(nbl::hlsl::mix(bilinearCoeffs[0], bilinearCoeffs[2], u.y), nbl::hlsl::mix(bilinearCoeffs[1], bilinearCoeffs[3], u.y));
4242
Linear<scalar_type> linearx = Linear<scalar_type>::create(ySliceEndPoints);
43-
u.x = linearx.generate(u.x);
43+
u.x = linearx.generate(_u.x);
4444

4545
rcpPdf = (twiceAreasUnderXCurve[0] + twiceAreasUnderXCurve[1]) / (4.0 * nbl::hlsl::mix(ySliceEndPoints[0], ySliceEndPoints[1], u.x));
4646

4747
return u;
4848
}
4949

50-
scalar_type pdf(NBL_CONST_REF_ARG(vector2_type) u)
50+
scalar_type pdf(const vector2_type u)
5151
{
5252
return 4.0 * nbl::hlsl::mix(nbl::hlsl::mix(bilinearCoeffs[0], bilinearCoeffs[1], u.x), nbl::hlsl::mix(bilinearCoeffs[2], bilinearCoeffs[3], u.x), u.y) / (bilinearCoeffs[0] + bilinearCoeffs[1] + bilinearCoeffs[2] + bilinearCoeffs[3]);
5353
}

include/nbl/builtin/hlsl/sampling/box_muller_transform.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct BoxMullerTransform
2121
using scalar_type = T;
2222
using vector2_type = vector<T,2>;
2323

24-
vector2_type operator()(vector2_type xi)
24+
vector2_type operator()(const vector2_type xi)
2525
{
2626
scalar_type sinPhi, cosPhi;
2727
math::sincos<scalar_type>(2.0 * numbers::pi<scalar_type> * xi.y - numbers::pi<scalar_type>, sinPhi, cosPhi);

include/nbl/builtin/hlsl/sampling/concentric_mapping.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace sampling
1717
{
1818

1919
template<typename T>
20-
vector<T,2> concentricMapping(vector<T,2> _u)
20+
vector<T,2> concentricMapping(const vector<T,2> _u)
2121
{
2222
//map [0;1]^2 to [-1;1]^2
2323
vector<T,2> u = 2.0f * _u - hlsl::promote<vector<T,2> >(1.0);

include/nbl/builtin/hlsl/sampling/cos_weighted_spheres.hlsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ struct ProjectedHemisphere
2222
using vector_t2 = vector<T, 2>;
2323
using vector_t3 = vector<T, 3>;
2424

25-
static vector_t3 generate(vector_t2 _sample)
25+
static vector_t3 generate(const vector_t2 _sample)
2626
{
2727
vector_t2 p = concentricMapping<T>(_sample * T(0.99999) + T(0.000005));
2828
T z = hlsl::sqrt<T>(hlsl::max<T>(T(0.0), T(1.0) - p.x * p.x - p.y * p.y));
2929
return vector_t3(p.x, p.y, z);
3030
}
3131

32-
static T pdf(T L_z)
32+
static T pdf(const T L_z)
3333
{
3434
return L_z * numbers::inv_pi<float>;
3535
}
3636

3737
template<typename U=vector<T,1> >
38-
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(T L)
38+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const T L)
3939
{
4040
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L));
4141
}
4242

4343
template<typename U=vector<T,1> >
44-
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
44+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const vector_t3 L)
4545
{
4646
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
4747
}
@@ -77,7 +77,7 @@ struct ProjectedSphere
7777
}
7878

7979
template<typename U=vector<T,1> >
80-
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(vector_t3 L)
80+
static sampling::quotient_and_pdf<U, T> quotient_and_pdf(const vector_t3 L)
8181
{
8282
return sampling::quotient_and_pdf<U, T>::create(hlsl::promote<U>(1.0), pdf(L.z));
8383
}

include/nbl/builtin/hlsl/sampling/linear.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct Linear
2121
using scalar_type = T;
2222
using vector2_type = vector<T, 2>;
2323

24-
static Linear<T> create(NBL_CONST_REF_ARG(vector2_type) linearCoeffs) // start and end importance values (start, end)
24+
static Linear<T> create(const vector2_type linearCoeffs) // start and end importance values (start, end)
2525
{
2626
Linear<T> retval;
2727
retval.linearCoeffStart = linearCoeffs[0];
@@ -32,7 +32,7 @@ struct Linear
3232
return retval;
3333
}
3434

35-
scalar_type generate(scalar_type u)
35+
scalar_type generate(const scalar_type u)
3636
{
3737
return hlsl::mix(u, (linearCoeffStart - hlsl::sqrt(squaredCoeffStart + u * squaredCoeffDiff)) * rcpDiff, hlsl::abs(rcpDiff) < numeric_limits<scalar_type>::max);
3838
}

include/nbl/builtin/hlsl/sampling/projected_spherical_triangle.hlsl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ struct ProjectedSphericalTriangle
3333
return retval;
3434
}
3535

36-
vector4_type computeBilinearPatch(NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF)
36+
vector4_type computeBilinearPatch(const vector3_type receiverNormal, bool isBSDF)
3737
{
3838
const scalar_type minimumProjSolidAngle = 0.0;
3939

4040
matrix<T, 3, 3> m = matrix<T, 3, 3>(tri.vertex0, tri.vertex1, tri.vertex2);
41-
const vector3_type bxdfPdfAtVertex = math::conditionalAbsOrMax(isBSDF, nbl::hlsl::mul(m, receiverNormal), (vector3_type)minimumProjSolidAngle);
41+
const vector3_type bxdfPdfAtVertex = math::conditionalAbsOrMax(isBSDF, nbl::hlsl::mul(m, receiverNormal), hlsl::promote<vector3_type>(minimumProjSolidAngle));
4242

4343
return bxdfPdfAtVertex.yyxz;
4444
}
4545

46-
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF, NBL_CONST_REF_ARG(vector2_type) _u)
46+
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector3_type receiverNormal, bool isBSDF, const vector2_type _u)
4747
{
4848
vector2_type u;
4949
// pre-warp according to proj solid angle approximation
@@ -58,15 +58,15 @@ struct ProjectedSphericalTriangle
5858
return L;
5959
}
6060

61-
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool isBSDF, NBL_CONST_REF_ARG(vector2_type) u)
61+
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, const vector3_type receiverNormal, bool isBSDF, const vector2_type u)
6262
{
6363
scalar_type cos_a, cos_c, csc_b, csc_c;
6464
vector3_type cos_vertices, sin_vertices;
6565
const scalar_type solidAngle = tri.solidAngleOfTriangle(cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c);
6666
return generate(rcpPdf, solidAngle, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, receiverNormal, isBSDF, u);
6767
}
6868

69-
scalar_type pdf(scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool receiverWasBSDF, NBL_CONST_REF_ARG(vector3_type) L)
69+
scalar_type pdf(scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector3_type receiverNormal, bool receiverWasBSDF, const vector3_type L)
7070
{
7171
scalar_type pdf;
7272
const vector2_type u = sphtri.generateInverse(pdf, solidAngle, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, L);
@@ -76,7 +76,7 @@ struct ProjectedSphericalTriangle
7676
return pdf * bilinear.pdf(u);
7777
}
7878

79-
scalar_type pdf(NBL_CONST_REF_ARG(vector3_type) receiverNormal, bool receiverWasBSDF, NBL_CONST_REF_ARG(vector3_type) L)
79+
scalar_type pdf(const vector3_type receiverNormal, bool receiverWasBSDF, const vector3_type L)
8080
{
8181
scalar_type pdf;
8282
const vector2_type u = sphtri.generateInverse(pdf, L);

include/nbl/builtin/hlsl/sampling/spherical_rectangle.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct SphericalRectangle
3232
return retval;
3333
}
3434

35-
vector2_type generate(NBL_CONST_REF_ARG(vector2_type) rectangleExtents, NBL_CONST_REF_ARG(vector2_type) uv, NBL_REF_ARG(scalar_type) S)
35+
vector2_type generate(const vector2_type rectangleExtents, const vector2_type uv, NBL_REF_ARG(scalar_type) S)
3636
{
3737
const vector4_type denorm_n_z = vector4_type(-rect.r0.y, rect.r0.x + rectangleExtents.x, rect.r0.y + rectangleExtents.y, -rect.r0.x);
3838
const vector4_type n_z = denorm_n_z / hlsl::sqrt<vector4_type>(hlsl::promote<vector4_type>(rect.r0.z * rect.r0.z) + denorm_n_z * denorm_n_z);

include/nbl/builtin/hlsl/sampling/spherical_triangle.hlsl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct SphericalTriangle
3333
}
3434

3535
// WARNING: can and will return NAN if one or three of the triangle edges are near zero length
36-
vector3_type generate(scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector2_type) u)
36+
vector3_type generate(scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector2_type u)
3737
{
3838
scalar_type negSinSubSolidAngle,negCosSubSolidAngle;
3939
math::sincos(solidAngle * u.x - numbers::pi<scalar_type>, negSinSubSolidAngle, negCosSubSolidAngle);
@@ -66,7 +66,7 @@ struct SphericalTriangle
6666
return retval;
6767
}
6868

69-
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, NBL_CONST_REF_ARG(vector2_type) u)
69+
vector3_type generate(NBL_REF_ARG(scalar_type) rcpPdf, const vector2_type u)
7070
{
7171
scalar_type cos_a, cos_c, csc_b, csc_c;
7272
vector3_type cos_vertices, sin_vertices;
@@ -76,7 +76,7 @@ struct SphericalTriangle
7676
return generate(rcpPdf, cos_vertices, sin_vertices, cos_a, cos_c, csc_b, csc_c, u);
7777
}
7878

79-
vector2_type generateInverse(NBL_REF_ARG(scalar_type) pdf, scalar_type solidAngle, NBL_CONST_REF_ARG(vector3_type) cos_vertices, NBL_CONST_REF_ARG(vector3_type) sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, NBL_CONST_REF_ARG(vector3_type) L)
79+
vector2_type generateInverse(NBL_REF_ARG(scalar_type) pdf, scalar_type solidAngle, const vector3_type cos_vertices, const vector3_type sin_vertices, scalar_type cos_a, scalar_type cos_c, scalar_type csc_b, scalar_type csc_c, const vector3_type L)
8080
{
8181
pdf = 1.0 / solidAngle;
8282

@@ -102,7 +102,7 @@ struct SphericalTriangle
102102
return vector2_type(u,v);
103103
}
104104

105-
vector2_type generateInverse(NBL_REF_ARG(scalar_type) pdf, NBL_CONST_REF_ARG(vector3_type) L)
105+
vector2_type generateInverse(NBL_REF_ARG(scalar_type) pdf, const vector3_type L)
106106
{
107107
scalar_type cos_a, cos_c, csc_b, csc_c;
108108
vector3_type cos_vertices, sin_vertices;

include/nbl/builtin/hlsl/sampling/uniform_spheres.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct UniformHemisphere
2323
using vector_t2 = vector<T, 2>;
2424
using vector_t3 = vector<T, 3>;
2525

26-
static vector_t3 generate(vector_t2 _sample)
26+
static vector_t3 generate(const vector_t2 _sample)
2727
{
2828
T z = _sample.x;
2929
T r = hlsl::sqrt<T>(hlsl::max<T>(T(0.0), T(1.0) - z * z));
@@ -49,7 +49,7 @@ struct UniformSphere
4949
using vector_t2 = vector<T, 2>;
5050
using vector_t3 = vector<T, 3>;
5151

52-
static vector_t3 generate(vector_t2 _sample)
52+
static vector_t3 generate(const vector_t2 _sample)
5353
{
5454
T z = T(1.0) - T(2.0) * _sample.x;
5555
T r = hlsl::sqrt<T>(hlsl::max<T>(T(0.0), T(1.0) - z * z));

include/nbl/builtin/hlsl/shapes/spherical_rectangle.hlsl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ struct SphericalRectangle
2525
using vector4_type = vector<Scalar, 4>;
2626
using matrix3x3_type = matrix<Scalar, 3, 3>;
2727

28-
static SphericalRectangle<scalar_type> create(NBL_CONST_REF_ARG(vector3_type) observer, NBL_CONST_REF_ARG(vector3_type) rectangleOrigin, NBL_CONST_REF_ARG(matrix3x3_type) basis)
28+
static SphericalRectangle<scalar_type> create(const vector3_type observer, const vector3_type rectangleOrigin, const matrix3x3_type basis)
2929
{
3030
SphericalRectangle<scalar_type> retval;
3131
retval.r0 = nbl::hlsl::mul(basis, rectangleOrigin - observer);
3232
return retval;
3333
}
3434

35-
static SphericalRectangle<Scalar> create(NBL_CONST_REF_ARG(vector3_type) observer, NBL_CONST_REF_ARG(vector3_type) rectangleOrigin, NBL_CONST_REF_ARG(vector3_type) T, NBL_CONST_REF_ARG(vector3_type) B, NBL_CONST_REF_ARG(vector3_type) N)
35+
static SphericalRectangle<Scalar> create(const vector3_type observer, const vector3_type rectangleOrigin, const vector3_type T, vector3_type B, const vector3_type N)
3636
{
3737
SphericalRectangle<scalar_type> retval;
3838
matrix3x3_type TBN = nbl::hlsl::transpose<matrix3x3_type>(matrix3x3_type(T, B, N));
3939
retval.r0 = nbl::hlsl::mul(TBN, rectangleOrigin - observer);
4040
return retval;
4141
}
4242

43-
scalar_type solidAngleOfRectangle(NBL_CONST_REF_ARG(vector<scalar_type, 2>) rectangleExtents)
43+
scalar_type solidAngleOfRectangle(const vector<scalar_type, 2> rectangleExtents)
4444
{
4545
const vector4_type denorm_n_z = vector4_type(-r0.y, r0.x + rectangleExtents.x, r0.y + rectangleExtents.y, -r0.x);
4646
const vector4_type n_z = denorm_n_z / nbl::hlsl::sqrt((vector4_type)(r0.z * r0.z) + denorm_n_z * denorm_n_z);

0 commit comments

Comments
 (0)