@@ -159,7 +159,11 @@ Ray rayCreatePosition(
159
159
vec3 targetPosition, bool penetrateSurface)
160
160
{
161
161
const vec3 rayVector = targetPosition - minimalSurfaceInteraction.position;
162
- const f16vec3 direction = f16vec3(normalize(rayVector));
162
+ // Note: safeNormalizeGetLength not used here as while it could be used to calculate tMax, the length that should be returned
163
+ // is a bit ambigious. If it's supposed to be the length of the input vector then this would fork fine as the length would be
164
+ // 0 for zero vectors, but if it's set to 1 to match the fallback vector then the ray will have an incorrect tMax. As such we
165
+ // just calculate the tMax manually for clarity and hope the compiler optimizes the redundant length calculations together.
166
+ const f16vec3 direction = f16vec3(safeNormalize(rayVector, vec3(0.0f, 0.0f, 1.0f)));
163
167
const float tMax = length(rayVector);
164
168
165
169
return rayCreateInternal(minimalRayInteraction, minimalSurfaceInteraction, viewRay, direction, tMax, penetrateSurface);
@@ -170,7 +174,7 @@ Ray rayCreatePosition(
170
174
vec3 targetPosition)
171
175
{
172
176
const vec3 rayVector = targetPosition - volumeInteraction.position;
173
- const f16vec3 direction = f16vec3(normalize (rayVector));
177
+ const f16vec3 direction = f16vec3(safeNormalize (rayVector, vec3(0.0f, 0.0f, 1.0f) ));
174
178
const float tMax = length(rayVector);
175
179
176
180
return rayCreateInternal(minimalRayInteraction, volumeInteraction, viewRay, direction, tMax);
@@ -181,7 +185,7 @@ Ray rayCreatePositionSubsurface(
181
185
vec3 targetPosition, vec3 shadingNormal)
182
186
{
183
187
const vec3 rayVector = targetPosition - minimalSurfaceInteraction.position;
184
- const f16vec3 direction = f16vec3(normalize (rayVector));
188
+ const f16vec3 direction = f16vec3(safeNormalize (rayVector, vec3(0.0f, 0.0f, 1.0f) ));
185
189
const float tMax = length(rayVector);
186
190
187
191
// If the new tracing ray is on the other side of SSS surface, treat the surface as penetrateSurface
0 commit comments