@@ -87,7 +87,15 @@ float4 pomGetPatchCorners(Texture2D texture, SamplerState sampler, float2 boxCen
87
87
}
88
88
89
89
// cast a ray in tangent space. return an intersection point in tangent point (or an exit point if z > 1.0f)
90
- float3 pomTraceRay(Texture2D texture, SamplerState sampler, float3 origin, float3 direction, float2 textureGradientX, float2 textureGradientY, inout uint iterations, float neutralHeight)
90
+ float3 pomTraceRay(
91
+ Texture2D texture,
92
+ SamplerState sampler,
93
+ float3 origin,
94
+ float3 direction,
95
+ float2 textureGradientX,
96
+ float2 textureGradientY,
97
+ inout uint iterations,
98
+ float neutralHeight)
91
99
{
92
100
// Potential future improvements for outwards rays:
93
101
// 1) calculate starting height the same way the box intersection code does instead of just sampling at a pixel.
@@ -155,7 +163,7 @@ float3 pomTraceRay(Texture2D texture, SamplerState sampler, float3 origin, float
155
163
// causes smooth slops to turn jagged. It may be an improvement to use that approach only when the current
156
164
// pixel is the largest or smallest of all the neighbors, but that seemed too complex to be worth pursuing.
157
165
158
- // Calculate the point where the ray entered this box:
166
+ // Calculate the point where the ray entered this box:
159
167
const float2 boxNearCorner = boxCenter - forwardHalfStep * boxSize;
160
168
const float2 boxEntranceDist = (boxNearCorner - origin.xy) / direction.xy;
161
169
const float3 boxEntrance = origin + max(0.0f, max(boxEntranceDist.x, boxEntranceDist.y)) * direction;
@@ -217,10 +225,12 @@ float3 pomTraceRay(Texture2D texture, SamplerState sampler, float3 origin, float
217
225
}
218
226
219
227
// Outwards rays can go past the top of the POM surface, so limit it to there.
220
- if (curPos.z > 1) {
228
+ if (curPos.z > 1)
229
+ {
221
230
float distToOne = (1.0f - origin.z) / direction.z;
222
231
return origin + distToOne * direction;
223
232
}
233
+
224
234
return curPos;
225
235
}
226
236
@@ -445,13 +455,17 @@ OpaqueSurfaceMaterialInteraction opaqueSurfaceMaterialInteractionCreate(
445
455
f16vec3 viewDirTextureSpace = normalize(mul(worldToTexture, minimalRayInteraction.viewDirection));
446
456
// Note: -1.f * TextureGradientX has the same x,y direction as viewDirTextureSpace, but calculating the correct z value is non-obvious.
447
457
// Could potentially remove the need for the worldToTexture transform if a faster way to calculate that z value is found.
448
-
458
+
449
459
uint iterations = 0; // unused
450
- surfaceInteraction.textureCoordinates = pomCalculateTexcoord(
460
+ const vec2 pomTextureCoordinates = pomCalculateTexcoord(
451
461
opaqueSurfaceMaterial,
452
462
surfaceInteraction,
453
463
viewDirTextureSpace,
454
464
iterations).xy;
465
+
466
+ // WAR for REMIX-3709 - POM sometimes produces NaNs.
467
+ surfaceInteraction.textureCoordinates = sanitize(pomTextureCoordinates, surfaceInteraction.textureCoordinates);
468
+
455
469
opaqueSurfaceMaterialInteraction.flags |= OPAQUE_SURFACE_MATERIAL_INTERACTION_FLAG_HAS_HEIGHT_TEXTURE;
456
470
}
457
471
#endif
0 commit comments