MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / quantizeTexCoords

Method quantizeTexCoords

Source/Falcor/Scene/SceneBuilder.cpp:2591–2642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2589 }
2590
2591 void SceneBuilder::quantizeTexCoords()
2592 {
2593 // Match texture coordinate quantization for textured emissives to format of PackedEmissiveTriangle.
2594 // This is to avoid mismatch when sampling and evaluating emissive triangles.
2595 // Note that non-emissive meshes are unmodified and use full precision texcoords.
2596 for (auto& mesh : mMeshes)
2597 {
2598 const auto& pMaterial = mSceneData.pMaterials->getMaterial(mesh.materialId)->toBasicMaterial();
2599 if (pMaterial && pMaterial->getEmissiveTexture() != nullptr)
2600 {
2601 // Quantize texture coordinates to fp16. Also track the bounds and max error.
2602 float2 minTexCrd = float2(std::numeric_limits<float>::infinity());
2603 float2 maxTexCrd = float2(-std::numeric_limits<float>::infinity());
2604 float2 maxError = float2(0);
2605
2606 for (uint32_t i = 0; i < mesh.staticVertexCount; ++i)
2607 {
2608 auto& v = mSceneData.meshStaticData[mesh.staticVertexOffset + i];
2609 float2 texCrd = v.texCrd;
2610 minTexCrd = min(minTexCrd, texCrd);
2611 maxTexCrd = max(maxTexCrd, texCrd);
2612 v.texCrd = f16tof32(f32tof16(texCrd));
2613 maxError = max(maxError, abs(v.texCrd - texCrd));
2614 }
2615
2616 // Issue warning if quantization errors are too large.
2617 float2 maxAbsCrd = max(abs(minTexCrd), abs(maxTexCrd));
2618 if (maxAbsCrd.x > HLF_MAX || maxAbsCrd.y > HLF_MAX)
2619 {
2620 logWarning("Texture coordinates for emissive textured mesh '{}' are outside the representable range, expect rendering errors.", mesh.name);
2621 }
2622 else
2623 {
2624 // Compute maximum quantization error in texels.
2625 // The texcoords are used for all texture channels so taking the maximum dimensions.
2626 uint2 maxTexDim = pMaterial->getMaxTextureDimensions();
2627 maxError *= float2(maxTexDim);
2628 float maxTexelError = std::max(maxError.x, maxError.y);
2629
2630 if (maxTexelError > kMaxTexelError)
2631 {
2632 logWarning(
2633 "Texture coordinates for emissive textured mesh '{}' have a large quantization error of {} texels."
2634 "The coordinate range is [{},{}] x [{},{}] for maximum texture dimensions ({},{}).",
2635 mesh.name, maxTexelError,
2636 minTexCrd.x, maxTexCrd.x, minTexCrd.y, maxTexCrd.y, maxTexDim.x, maxTexDim.y
2637 );
2638 }
2639 }
2640 }
2641 }
2642 }
2643
2644 void SceneBuilder::removeDuplicateSDFGrids()
2645 {

Callers

nothing calls this directly

Calls 9

toBasicMaterialMethod · 0.80
getMaterialMethod · 0.80
minFunction · 0.50
maxFunction · 0.50
f16tof32Function · 0.50
f32tof16Function · 0.50
absFunction · 0.50
logWarningFunction · 0.50

Tested by

no test coverage detected