@@ -203,32 +203,32 @@ struct Shape;
203203template<>
204204struct Shape<PST_SPHERE>
205205{
206- static Shape<PST_SPHERE> create (NBL_CONST_REF_ARG (float32_t3) position, float32_t radius , uint32_t bsdfLightIDs)
206+ static Shape<PST_SPHERE> create (NBL_CONST_REF_ARG (float32_t3) position, float32_t radius2 , uint32_t bsdfLightIDs)
207207 {
208208 Shape<PST_SPHERE> retval;
209209 retval.position = position;
210- retval.radius2 = radius * radius ;
210+ retval.radius2 = radius2 ;
211211 retval.bsdfLightIDs = bsdfLightIDs;
212212 return retval;
213213 }
214214
215215 static Shape<PST_SPHERE> create (NBL_CONST_REF_ARG (float32_t3) position, float32_t radius, uint32_t bsdfID, uint32_t lightID)
216216 {
217217 uint32_t bsdfLightIDs = glsl::bitfieldInsert<uint32_t>(bsdfID, lightID, 16 , 16 );
218- return create (position, radius, bsdfLightIDs);
218+ return create (position, radius * radius , bsdfLightIDs);
219219 }
220220
221221 // return intersection distance if found, nan otherwise
222222 float intersect (NBL_CONST_REF_ARG (float32_t3) origin, NBL_CONST_REF_ARG (float32_t3) direction)
223223 {
224224 float32_t3 relOrigin = origin - position;
225- float relOriginLen2 = nbl:: hlsl::dot (relOrigin, relOrigin);
225+ float relOriginLen2 = hlsl::dot<float32_t3> (relOrigin, relOrigin);
226226
227- float dirDotRelOrigin = nbl:: hlsl::dot (direction, relOrigin);
227+ float dirDotRelOrigin = hlsl::dot<float32_t3> (direction, relOrigin);
228228 float det = radius2 - relOriginLen2 + dirDotRelOrigin * dirDotRelOrigin;
229229
230230 // do some speculative math here
231- float detsqrt = nbl:: hlsl::sqrt (det);
231+ float detsqrt = hlsl::sqrt<float32_t> (det);
232232 return -dirDotRelOrigin + (relOriginLen2 > radius2 ? (-detsqrt) : detsqrt);
233233 }
234234
@@ -241,7 +241,7 @@ struct Shape<PST_SPHERE>
241241 float getSolidAngle (NBL_CONST_REF_ARG (float32_t3) origin)
242242 {
243243 float32_t3 dist = position - origin;
244- float cosThetaMax = nbl:: hlsl::sqrt (1.0 - radius2 / nbl:: hlsl::dot (dist, dist));
244+ float cosThetaMax = hlsl::sqrt<float32_t> (1.0 - radius2 / hlsl::dot<float32_t3> (dist, dist));
245245 return 2.0 * numbers::pi<float > * (1.0 - cosThetaMax);
246246 }
247247
@@ -255,28 +255,28 @@ struct Shape<PST_SPHERE>
255255 float32_t3 generate_and_pdf (NBL_REF_ARG (float32_t) pdf, NBL_REF_ARG (float32_t) newRayMaxT, NBL_CONST_REF_ARG (float32_t3) origin, NBL_CONST_REF_ARG (Aniso) interaction, bool isBSDF, float32_t3 xi)
256256 {
257257 float32_t3 Z = position - origin;
258- const float distanceSQ = nbl:: hlsl::dot (Z,Z);
258+ const float distanceSQ = hlsl::dot<float32_t3> (Z,Z);
259259 const float cosThetaMax2 = 1.0 - radius2 / distanceSQ;
260260 if (cosThetaMax2 > 0.0 )
261261 {
262- const float rcpDistance = 1.0 / nbl:: hlsl::sqrt (distanceSQ);
262+ const float rcpDistance = 1.0 / hlsl::sqrt<float32_t> (distanceSQ);
263263 Z *= rcpDistance;
264264
265- const float cosThetaMax = nbl:: hlsl::sqrt (cosThetaMax2);
265+ const float cosThetaMax = hlsl::sqrt<float32_t> (cosThetaMax2);
266266 const float cosTheta = nbl::hlsl::mix<float >(1.0 , cosThetaMax, xi.x);
267267
268268 float32_t3 L = Z * cosTheta;
269269
270270 const float cosTheta2 = cosTheta * cosTheta;
271- const float sinTheta = nbl:: hlsl::sqrt (1.0 - cosTheta2);
271+ const float sinTheta = hlsl::sqrt<float32_t> (1.0 - cosTheta2);
272272 float sinPhi, cosPhi;
273- math::sincos (2.0 * numbers::pi<float > * xi.y - numbers::pi<float >, sinPhi, cosPhi);
273+ math::sincos< float > (2.0 * numbers::pi<float > * xi.y - numbers::pi<float >, sinPhi, cosPhi);
274274 float32_t3 X, Y;
275275 math::frisvad<float32_t3>(Z, X, Y);
276276
277277 L += (X * cosPhi + Y * sinPhi) * sinTheta;
278278
279- newRayMaxT = (cosTheta - nbl:: hlsl::sqrt (cosTheta2 - cosThetaMax2)) / rcpDistance;
279+ newRayMaxT = (cosTheta - hlsl::sqrt<float32_t> (cosTheta2 - cosThetaMax2)) / rcpDistance;
280280 pdf = 1.0 / (2.0 * numbers::pi<float > * (1.0 - cosThetaMax));
281281 return L;
282282 }
@@ -315,26 +315,26 @@ struct Shape<PST_TRIANGLE>
315315 {
316316 const float32_t3 edges[2 ] = { vertex1 - vertex0, vertex2 - vertex0 };
317317
318- const float32_t3 h = nbl:: hlsl::cross (direction, edges[1 ]);
319- const float a = nbl:: hlsl::dot (edges[0 ], h);
318+ const float32_t3 h = hlsl::cross<float32_t3> (direction, edges[1 ]);
319+ const float a = hlsl::dot<float32_t3> (edges[0 ], h);
320320
321321 const float32_t3 relOrigin = origin - vertex0;
322322
323- const float u = nbl:: hlsl::dot (relOrigin, h) / a;
323+ const float u = hlsl::dot<float32_t3> (relOrigin, h) / a;
324324
325- const float32_t3 q = nbl:: hlsl::cross (relOrigin, edges[0 ]);
326- const float v = nbl:: hlsl::dot (direction, q) / a;
325+ const float32_t3 q = hlsl::cross<float32_t3> (relOrigin, edges[0 ]);
326+ const float v = hlsl::dot<float32_t3> (direction, q) / a;
327327
328- const float t = nbl:: hlsl::dot (edges[1 ], q) / a;
328+ const float t = hlsl::dot<float32_t3> (edges[1 ], q) / a;
329329
330330 const bool intersection = t > 0.f && u >= 0.f && v >= 0.f && (u + v) <= 1.f ;
331- return intersection ? t : numeric_limits<float >::infinity;
331+ return intersection ? t : bit_cast< float , uint32_t>( numeric_limits<float >::infinity) ;
332332 }
333333
334334 float32_t3 getNormalTimesArea ()
335335 {
336336 const float32_t3 edges[2 ] = { vertex1 - vertex0, vertex2 - vertex0 };
337- return nbl:: hlsl::cross (edges[0 ], edges[1 ]) * 0.5f ;
337+ return hlsl::cross<float32_t3> (edges[0 ], edges[1 ]) * 0.5f ;
338338 }
339339
340340 template<typename Ray>
@@ -347,7 +347,7 @@ struct Shape<PST_TRIANGLE>
347347 {
348348 const float dist = ray.intersectionT;
349349 const float32_t3 L = ray.direction;
350- return dist * dist / nbl:: hlsl::abs (nbl:: hlsl::dot (getNormalTimesArea (), L));
350+ return dist * dist / hlsl::abs<float32_t>( hlsl::dot<float32_t3> (getNormalTimesArea (), L));
351351 }
352352 break ;
353353 case PPM_SOLID_ANGLE:
@@ -381,15 +381,15 @@ struct Shape<PST_TRIANGLE>
381381 {
382382 const float32_t3 edge0 = vertex1 - vertex0;
383383 const float32_t3 edge1 = vertex2 - vertex0;
384- const float sqrtU = nbl:: hlsl::sqrt (xi.x);
384+ const float sqrtU = hlsl::sqrt<float32_t> (xi.x);
385385 float32_t3 pnt = vertex0 + edge0 * (1.0 - sqrtU) + edge1 * sqrtU * xi.y;
386386 float32_t3 L = pnt - origin;
387387
388- const float distanceSq = nbl:: hlsl::dot (L,L);
389- const float rcpDistance = 1.0 / nbl:: hlsl::sqrt (distanceSq);
388+ const float distanceSq = hlsl::dot<float32_t3> (L,L);
389+ const float rcpDistance = 1.0 / hlsl::sqrt<float32_t> (distanceSq);
390390 L *= rcpDistance;
391391
392- pdf = distanceSq / nbl:: hlsl::abs (nbl:: hlsl::dot (nbl:: hlsl::cross (edge0, edge1) * 0.5f , L));
392+ pdf = distanceSq / hlsl::abs<float32_t>( hlsl::dot<float32_t3>( hlsl::cross<float32_t3> (edge0, edge1) * 0.5f , L));
393393 newRayMaxT = 1.0 / rcpDistance;
394394 return L;
395395 }
@@ -406,7 +406,7 @@ struct Shape<PST_TRIANGLE>
406406 pdf = rcpPdf > numeric_limits<float >::min ? (1.0 / rcpPdf) : 0.0 ;
407407
408408 const float32_t3 N = getNormalTimesArea ();
409- newRayMaxT = nbl:: hlsl::dot (N, vertex0 - origin) / nbl:: hlsl::dot (N, L);
409+ newRayMaxT = hlsl::dot<float32_t3> (N, vertex0 - origin) / hlsl::dot<float32_t3> (N, L);
410410 return L;
411411 }
412412 break ;
@@ -422,7 +422,7 @@ struct Shape<PST_TRIANGLE>
422422 pdf = rcpPdf > numeric_limits<float >::min ? (1.0 / rcpPdf) : 0.0 ;
423423
424424 const float32_t3 N = getNormalTimesArea ();
425- newRayMaxT = nbl:: hlsl::dot (N, vertex0 - origin) / nbl:: hlsl::dot (N, L);
425+ newRayMaxT = hlsl::dot<float32_t3> (N, vertex0 - origin) / hlsl::dot<float32_t3> (N, L);
426426 return L;
427427 }
428428 break ;
@@ -462,25 +462,25 @@ struct Shape<PST_RECTANGLE>
462462
463463 float intersect (NBL_CONST_REF_ARG (float32_t3) origin, NBL_CONST_REF_ARG (float32_t3) direction)
464464 {
465- const float32_t3 h = nbl:: hlsl::cross (direction, edge1);
466- const float a = nbl:: hlsl::dot (edge0, h);
465+ const float32_t3 h = hlsl::cross<float32_t3> (direction, edge1);
466+ const float a = hlsl::dot<float32_t3> (edge0, h);
467467
468468 const float32_t3 relOrigin = origin - offset;
469469
470- const float u = nbl:: hlsl::dot (relOrigin,h)/a;
470+ const float u = hlsl::dot<float32_t3> (relOrigin,h)/a;
471471
472- const float32_t3 q = nbl:: hlsl::cross (relOrigin, edge0);
473- const float v = nbl:: hlsl::dot (direction, q) / a;
472+ const float32_t3 q = hlsl::cross<float32_t3> (relOrigin, edge0);
473+ const float v = hlsl::dot<float32_t3> (direction, q) / a;
474474
475- const float t = nbl:: hlsl::dot (edge1, q) / a;
475+ const float t = hlsl::dot<float32_t3> (edge1, q) / a;
476476
477477 const bool intersection = t > 0.f && u >= 0.f && v >= 0.f && u <= 1.f && v <= 1.f ;
478- return intersection ? t : numeric_limits<float >::infinity;
478+ return intersection ? t : bit_cast< float , uint32_t>( numeric_limits<float >::infinity) ;
479479 }
480480
481481 float32_t3 getNormalTimesArea ()
482482 {
483- return nbl:: hlsl::cross (edge0, edge1);
483+ return hlsl::cross<float32_t3> (edge0, edge1);
484484 }
485485
486486 void getNormalBasis (NBL_REF_ARG (float32_t3x3) basis, NBL_REF_ARG (float32_t2) extents)
@@ -502,7 +502,7 @@ struct Shape<PST_RECTANGLE>
502502 {
503503 const float dist = ray.intersectionT;
504504 const float32_t3 L = ray.direction;
505- return dist * dist / nbl:: hlsl::abs (nbl:: hlsl::dot (getNormalTimesArea (), L));
505+ return dist * dist / hlsl::abs<float32_t>( hlsl::dot<float32_t3> (getNormalTimesArea (), L));
506506 }
507507 break ;
508508 // #ifdef TRIANGLE_REFERENCE ?
@@ -542,10 +542,10 @@ struct Shape<PST_RECTANGLE>
542542 case PPM_AREA:
543543 {
544544 float32_t3 L = origin2origin + edge0 * xi.x + edge1 * xi.y;
545- const float distSq = nbl:: hlsl::dot (L, L);
546- const float rcpDist = 1.0 / nbl:: hlsl::sqrt (distSq);
545+ const float distSq = hlsl::dot<float32_t3> (L, L);
546+ const float rcpDist = 1.0 / hlsl::sqrt<float32_t> (distSq);
547547 L *= rcpDist;
548- pdf = distSq / nbl:: hlsl::abs (nbl:: hlsl::dot (N, L));
548+ pdf = distSq / hlsl::abs<float32_t>( hlsl::dot<float32_t3> (N, L));
549549 newRayMaxT = 1.0 / rcpDist;
550550 return L;
551551 }
@@ -572,7 +572,7 @@ struct Shape<PST_RECTANGLE>
572572 else
573573 pdf = numeric_limits<float >::infinity;
574574
575- newRayMaxT = nbl:: hlsl::dot (N, origin2origin) / nbl:: hlsl::dot (N, L);
575+ newRayMaxT = hlsl::dot<float32_t3> (N, origin2origin) / hlsl::dot<float32_t3> (N, L);
576576 return L;
577577 }
578578 break ;
0 commit comments