diff --git a/devices/rtx/apps/tests/api/RendererFogSupport.h b/devices/rtx/apps/tests/api/RendererFogSupport.h index 08f412de1..9324d7445 100644 --- a/devices/rtx/apps/tests/api/RendererFogSupport.h +++ b/devices/rtx/apps/tests/api/RendererFogSupport.h @@ -30,6 +30,13 @@ struct Image std::vector primitive, object, instance; }; +// Print named contracts before execution so failures remain attributable. +inline void logCase(const std::string &name) +{ + fprintf(stderr, "[fog-case] %s\n", name.c_str()); + fflush(stderr); +} + /* Owns one public ANARI reference; the Device must outlive this scope. */ class ObjectOwner { diff --git a/devices/rtx/apps/tests/api/TestRendererFogCoverage.cpp b/devices/rtx/apps/tests/api/TestRendererFogCoverage.cpp index 7413b5725..8ddabe3b3 100644 --- a/devices/rtx/apps/tests/api/TestRendererFogCoverage.cpp +++ b/devices/rtx/apps/tests/api/TestRendererFogCoverage.cpp @@ -43,6 +43,7 @@ struct Scene void fog(const char *mode, const char *metric, bool full = false); void rayBuffer(); Image render(); + void setSamples(int count); anari::Device device; const char *subtype; @@ -50,6 +51,7 @@ struct Scene anari::Camera camera; anari::Renderer renderer; anari::Frame frame; + int samples = 1; std::vector materials; std::vector instances; }; @@ -215,9 +217,16 @@ void Scene::rayBuffer() anari::commitParameters(device, frame); } +void Scene::setSamples(int count) +{ + anari::setParameter(device, renderer, "pixelSamples", count); + samples = count; +} + Image Scene::render() { anari::render(device, frame); + anari::wait(device, frame); return readImage(device, frame, SIZE); } @@ -232,9 +241,14 @@ bool expect(const Scene &scene, const Image &actual, const std::vector &expected) { + double maxError = 0., maxToleranceFraction = 0.; for (unsigned p = 0; p < PIXELS; ++p) { for (unsigned c = 0; c < 4; ++c) { const double ref = expected[p][c]; + const double error = std::abs(actual.color[p][c] - ref); + maxError = std::fmax(maxError, error); + maxToleranceFraction = std::fmax( + maxToleranceFraction, error / (1e-5 + 1e-4 * std::abs(ref))); if (!std::isfinite(actual.color[p][c]) || std::abs(actual.color[p][c] - ref) > 1e-5 + 1e-4 * std::abs(ref)) { fprintf(stderr, @@ -249,6 +263,12 @@ bool expect(const Scene &scene, } } } + printf("%s %s: %d spp, max error=%g, tolerance fraction=%g\n", + scene.subtype, + label.c_str(), + scene.samples, + maxError, + maxToleranceFraction); return true; } @@ -291,80 +311,118 @@ bool expectCoverage(const Scene &scene, return maxPixelError <= 0.05 && maxMeanError <= 0.008; } +struct FogCase +{ + const char *name; + const char *mode; + const char *metric; + bool full = false; +}; + +// Oblique rays distinguish the metrics. Keep every active curve/metric pair, +// but only one saturated endpoint and one disable-after-active transition. +constexpr FogCase LAYER_FOG[] = {{"linear-view", "linear", "viewDepth"}, + {"exp-view", "exp", "viewDepth"}, + {"exp2-view", "exp2", "viewDepth"}, + {"linear-ray", "linear", "rayDistance"}, + {"exp-ray", "exp", "rayDistance"}, + {"exp2-ray", "exp2", "rayDistance"}, + {"saturated", "linear", "viewDepth", true}, + {"disabled-restoration", "none", "rayDistance"}}; + +// Orthographic planar depths agree under both metrics. Retain a ray-metric +// composition witness, all curves and the endpoint; cheap Distance anchors +// separately distinguish the metrics rather than repeating equal distances. +constexpr FogCase PLANAR_FOG[] = {{"linear-view", "linear", "viewDepth"}, + {"exp-view", "exp", "viewDepth"}, + {"exp2-view", "exp2", "viewDepth"}, + {"linear-ray", "linear", "rayDistance"}, + {"saturated", "linear", "viewDepth", true}}; + int testLayers(anari::Device d, const char *subtype, bool background = false) { int failures = 0; constexpr Vec3 FRONT{0.2f, 0.3f, 0.1f}, BACK{0.1f, 0.2f, 0.4f}; const Vec3 target = background ? Vec3{0.15f, 0.65f, 0.35f} : FOG_COLOR; - for (float alpha : {0.f, 0.25f, 1.f}) { - for (float backAlpha : {0.f, 0.5f, 1.f}) { - Scene scene(d, subtype); - if (background) { - anari::setParameter(d, - scene.renderer, - "background", - Vec4{target[0], target[1], target[2], 1.f}); - anari::setParameter(d, scene.renderer, "fogColorSource", "background"); - } - if (std::string(subtype) == "quality") - anari::setParameter(d, scene.renderer, "pixelSamples", 4096); - scene.addPlane(4.f, FRONT, alpha); - scene.addPlane(12.f, BACK, backAlpha); - scene.rayBuffer(); - scene.fog("none", "viewDepth"); - const auto baseline = scene.render(); - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"none", "linear", "exp", "exp2"}) { - scene.fog(mode, metric); - std::vector expected(PIXELS); - for (unsigned p = 0; p < PIXELS; ++p) { - const bool radial = std::string(metric) == "rayDistance"; - const double t0 = - visibility(mode, radial ? (4. - p % 3) * 1.25 : 5.); - const double t1 = - visibility(mode, radial ? (12. - p % 3) * 1.25 : 13.); - for (unsigned c = 0; c < 3; ++c) { - // Independently composited premultiplied contributions at two - // depths. - expected[p][c] = alpha * (t0 * FRONT[c] + (1. - t0) * target[c]) - + (1. - alpha) * backAlpha - * (t1 * BACK[c] + (1. - t1) * target[c]) - + (background ? (1. - alpha) * (1. - backAlpha) * target[c] - : 0.); - } - expected[p][3] = - background ? 1.f : alpha + (1.f - alpha) * backAlpha; - } - const auto image = scene.render(); - failures += !expectCoverage(scene, - std::string(background ? "background layers " : "layers ") + mode - + " " + metric, - image, - expected); - failures += !sameAuxiliary(baseline, image, scene.subtype); - } - scene.fog("linear", metric, true); - const auto full = scene.render(); - std::vector expected(PIXELS); - for (auto &pixel : expected) { - pixel[3] = background ? 1.f : alpha + (1.f - alpha) * backAlpha; - for (unsigned c = 0; c < 3; ++c) - pixel[c] = pixel[3] * target[c]; + const struct LayerCase + { + const char *name; + float front, rear; + bool occlusionOnly = false; + } cases[] = {{"empty", 0.f, 0.f}, + {"rear-partial", 0.f, 0.5f}, + {"rear-opaque", 0.f, 1.f}, + {"front-partial", 0.25f, 0.f}, + {"both-partial", 0.25f, 0.5f}, + {"partial-over-opaque", 0.25f, 1.f}, + {"opaque-over-empty", 1.f, 0.f, true}, + {"opaque-over-partial", 1.f, 0.5f, true}, + {"opaque-over-opaque", 1.f, 1.f}}; + for (const auto &layer : cases) { + const float alpha = layer.front, backAlpha = layer.rear; + logCase(std::string(subtype) + "/layers/" + layer.name + + (background ? "/background" : "/constant")); + Scene scene(d, subtype); + if (background) { + anari::setParameter(d, + scene.renderer, + "background", + Vec4{target[0], target[1], target[2], 1.f}); + anari::setParameter(d, scene.renderer, "fogColorSource", "background"); + } + if (std::string(subtype) == "quality") + scene.setSamples(4096); + scene.addPlane(4.f, FRONT, alpha); + scene.addPlane(12.f, BACK, backAlpha); + scene.rayBuffer(); + scene.fog("none", "viewDepth"); + const auto baseline = scene.render(); + for (const auto &fog : LAYER_FOG) { + // Rear opacity cannot affect an opaque front. Keep live unfogged, + // oblique partial-fog and disable witnesses at both other opacities; + // opaque-over-opaque carries the complete setting table. + if (layer.occlusionOnly && std::string(fog.name) != "linear-ray" + && std::string(fog.mode) != "none") + continue; + fprintf(stderr, "[fog-setting] %s/%s\n", layer.name, fog.name); + scene.fog(fog.mode, fog.metric, fog.full); + std::vector expected(PIXELS); + for (unsigned p = 0; p < PIXELS; ++p) { + const bool radial = std::string(fog.metric) == "rayDistance"; + const double t0 = fog.full + ? 0. + : visibility(fog.mode, radial ? (4. - p % 3) * 1.25 : 5.); + const double t1 = fog.full + ? 0. + : visibility(fog.mode, radial ? (12. - p % 3) * 1.25 : 13.); + for (unsigned c = 0; c < 3; ++c) { + // Independently composited premultiplied contributions at two + // depths. + expected[p][c] = alpha * (t0 * FRONT[c] + (1. - t0) * target[c]) + + (1. - alpha) * backAlpha + * (t1 * BACK[c] + (1. - t1) * target[c]) + + (background ? (1. - alpha) * (1. - backAlpha) * target[c] : 0.); } - failures += !expectCoverage(scene, "full fog layers", full, expected); - failures += !sameAuxiliary(baseline, full, scene.subtype); - } - // Make ID assertions non-vacuous, including the transparent front case. - if (baseline.primitive[0] == ~0u || baseline.object[0] != 200 - || baseline.instance[0] != 300) { - fprintf(stderr, - "%s unexpected baseline IDs: %u %u %u\n", - subtype, - baseline.primitive[0], - baseline.object[0], - baseline.instance[0]); - ++failures; + expected[p][3] = background ? 1.f : alpha + (1.f - alpha) * backAlpha; } + const auto image = scene.render(); + failures += !expectCoverage(scene, + std::string(layer.name) + (background ? " background " : " ") + + fog.name, + image, + expected); + failures += !sameAuxiliary(baseline, image, scene.subtype); + } + // Make ID assertions non-vacuous, including the transparent front case. + if (baseline.primitive[0] == ~0u || baseline.object[0] != 200 + || baseline.instance[0] != 300) { + fprintf(stderr, + "%s unexpected baseline IDs: %u %u %u\n", + subtype, + baseline.primitive[0], + baseline.object[0], + baseline.instance[0]); + ++failures; } } return failures; @@ -375,6 +433,8 @@ int testTransmission(anari::Device d, const char *subtype) int failures = 0; constexpr Vec3 TINT{0.25f, 0.5f, 0.75f}, BACK{0.1f, 0.2f, 0.3f}; for (float alpha : {0.5f, 1.f}) { + logCase( + std::string(subtype) + "/transmission/alpha=" + std::to_string(alpha)); Scene scene(d, subtype); scene.addPlane(4.f, TINT, alpha, -100.f, 100.f, 0.75f); scene.addPlane(12.f, BACK, 0.5f); @@ -385,34 +445,34 @@ int testTransmission(anari::Device d, const char *subtype) scene.rayBuffer(); scene.fog("none", "viewDepth"); const auto baseline = scene.render(); - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"none", "linear", "exp", "exp2", "full"}) { - const bool full = std::string(mode) == "full"; - scene.fog(full ? "linear" : mode, metric, full); - std::vector expected(PIXELS); - for (unsigned p = 0; p < PIXELS; ++p) { - const bool radial = std::string(metric) == "rayDistance"; - const double t0 = - full ? 0. : visibility(mode, radial ? (4. - p % 3) * 1.25 : 5.); - const double t1 = - full ? 0. : visibility(mode, radial ? (12. - p % 3) * 1.25 : 13.); - for (unsigned c = 0; c < 3; ++c) { - // Thin native PBR: no metal/volume attenuation, so the material's - // straight-through filter is transmission * baseColor. This is - // independent of fog visibility and of the scalar coverage alpha. - const double through = 1. - alpha + alpha * 0.75 * TINT[c]; - expected[p][c] = - (alpha * (1. - t0) + through * 0.5 * (1. - t1)) * FOG_COLOR[c]; - } - expected[p][3] = alpha + (1.f - alpha) * 0.5f; + for (const auto &fog : LAYER_FOG) { + const auto mode = fog.mode, metric = fog.metric; + const bool full = fog.full; + fprintf(stderr, "[fog-setting] transmission/%s\n", fog.name); + scene.fog(mode, metric, full); + std::vector expected(PIXELS); + for (unsigned p = 0; p < PIXELS; ++p) { + const bool radial = std::string(metric) == "rayDistance"; + const double t0 = + full ? 0. : visibility(mode, radial ? (4. - p % 3) * 1.25 : 5.); + const double t1 = + full ? 0. : visibility(mode, radial ? (12. - p % 3) * 1.25 : 13.); + for (unsigned c = 0; c < 3; ++c) { + // Thin native PBR: no metal/volume attenuation, so the material's + // straight-through filter is transmission * baseColor. This is + // independent of fog visibility and of the scalar coverage alpha. + const double through = 1. - alpha + alpha * 0.75 * TINT[c]; + expected[p][c] = + (alpha * (1. - t0) + through * 0.5 * (1. - t1)) * FOG_COLOR[c]; } - const auto image = scene.render(); - failures += !expect(scene, - std::string("colored transmission ") + mode + " " + metric, - image, - expected); - failures += !sameAuxiliary(baseline, image, scene.subtype); + expected[p][3] = alpha + (1.f - alpha) * 0.5f; } + const auto image = scene.render(); + failures += !expect(scene, + std::string("colored transmission ") + fog.name, + image, + expected); + failures += !sameAuxiliary(baseline, image, scene.subtype); } } return failures; @@ -420,9 +480,10 @@ int testTransmission(anari::Device d, const char *subtype) int testCutouts(anari::Device d, const char *subtype) { + logCase(std::string(subtype) + "/cutouts"); Scene scene(d, subtype); if (std::string(subtype) == "quality") - anari::setParameter(d, scene.renderer, "pixelSamples", 4096); + scene.setSamples(4096); constexpr Vec3 FRONT{0.2f, 0.3f, 0.1f}, BACK{0.1f, 0.2f, 0.4f}; // Two adjoining masked patches form a genuine discarded hole in front of a // half-covered rear layer, not a geometric hole or a zero-valued fog color. @@ -432,29 +493,32 @@ int testCutouts(anari::Device d, const char *subtype) scene.fog("none", "viewDepth"); const auto baseline = scene.render(); int failures = 0; - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"none", "linear", "exp", "exp2", "full"}) { - const bool full = std::string(mode) == "full"; - scene.fog(full ? "linear" : mode, metric, full); - std::vector expected(PIXELS); - for (unsigned p = 0; p < PIXELS; ++p) { - // Camera right is -X for direction +Z and up +Y. - const bool covered = p % SIZE[0] < SIZE[0] / 2; - const double t = full ? 0. : visibility(mode, covered ? 4. : 12.); - const auto &color = covered ? FRONT : BACK; - const float alpha = covered ? 1.f : 0.5f; - for (unsigned c = 0; c < 3; ++c) - expected[p][c] = alpha * (t * color[c] + (1. - t) * FOG_COLOR[c]); - expected[p][3] = alpha; - } - const auto image = scene.render(); - failures += !expectCoverage(scene, - std::string("masked hole ") + mode + " " + metric, - image, - expected); - failures += !sameAuxiliary(baseline, image, scene.subtype); + for (const auto &fog : PLANAR_FOG) { + const auto mode = fog.mode; + const bool full = fog.full; + fprintf(stderr, "[fog-setting] cutouts/%s\n", fog.name); + scene.fog(mode, fog.metric, full); + std::vector expected(PIXELS); + for (unsigned p = 0; p < PIXELS; ++p) { + // Camera right is -X for direction +Z and up +Y. + const bool covered = p % SIZE[0] < SIZE[0] / 2; + const double t = full ? 0. : visibility(mode, covered ? 4. : 12.); + const auto &color = covered ? FRONT : BACK; + const float alpha = covered ? 1.f : 0.5f; + for (unsigned c = 0; c < 3; ++c) + expected[p][c] = alpha * (t * color[c] + (1. - t) * FOG_COLOR[c]); + expected[p][3] = alpha; } + const auto image = scene.render(); + failures += !expectCoverage( + scene, std::string("masked hole ") + fog.name, image, expected); + failures += !sameAuxiliary(baseline, image, scene.subtype); } + scene.fog("none", "rayDistance"); + const auto restored = scene.render(); + failures += + !expect(scene, "cutout disabled restoration", restored, baseline.color); + failures += !sameAuxiliary(baseline, restored, scene.subtype); return failures; } @@ -470,6 +534,7 @@ int testEdges(anari::Device d, const char *subtype) int failures = 0; constexpr Vec3 FRONT{0.1f, 0.2f, 0.3f}, BACK{0.4f, 0.1f, 0.2f}; for (bool depthEdge : {false, true}) { + logCase(std::string(subtype) + (depthEdge ? "/depth-edge" : "/silhouette")); Scene scene(d, subtype); const bool layeredSilhouette = !depthEdge && std::string(subtype) == "quality"; @@ -481,73 +546,75 @@ int testEdges(anari::Device d, const char *subtype) // happens to commute with premultiplied fog. Two adjoining depths plus // empty background make a resolved-depth operation distinguishable. scene.addPlane(12.f, BACK, 1.f, 0.02f, 0.07f); - // 256 camera samples per pixel, paired by fresh accumulation on Commit. + // 64 camera samples per pixel, paired by fresh accumulation on Commit. // No statistical tolerance is needed: the reference uses the same geometry // and sampling with independently pre-cued material colors. Orthographic // planar layers have constant depth under BOTH metrics for every sample. - anari::setParameter(d, scene.renderer, "pixelSamples", 256); + scene.setSamples(64); scene.fog("none", "viewDepth"); const auto baseline = scene.render(); - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"linear", "exp", "exp2", "full"}) { - const bool full = std::string(mode) == "full"; - scene.fog(full ? "linear" : mode, metric, full); - const auto image = scene.render(); - failures += !sameAuxiliary(baseline, image, scene.subtype); - scene.setColor(0, cueColor(FRONT, full ? 0. : visibility(mode, 4.))); - if (depthEdge || layeredSilhouette) - scene.setColor(1, cueColor(BACK, full ? 0. : visibility(mode, 12.))); - scene.fog("none", metric); - const auto reference = scene.render(); - failures += !expect(scene, - std::string(depthEdge ? "depth edge " : "silhouette ") + mode + " " - + metric, - image, - reference.color); - - unsigned mixed = 0, distinguishable = 0; - double maxPostError = 0.; - for (unsigned p = 0; p < PIXELS; ++p) { - const double coverage = depthEdge - ? (baseline.color[p][0] - BACK[0]) / (FRONT[0] - BACK[0]) - : baseline.color[p][3]; - if (coverage <= 0.05 || coverage >= 0.95) - continue; - ++mixed; - // A tempting but wrong resolved-depth implementation, evaluated on - // unfogged output. Assert that the oracle can reject it, not just - // that two equivalent public-ANARI renders happen to agree. - const double t = full ? 0. : visibility(mode, baseline.depth[p]); - double error = 0.; - for (unsigned c = 0; c < 3; ++c) { - const double post = t * baseline.color[p][c] - + baseline.color[p][3] * (1. - t) * FOG_COLOR[c]; - error = std::fmax(error, std::abs(post - reference.color[p][c])); - } - maxPostError = std::fmax(maxPostError, error); - distinguishable += error > 0.01; - } - if (mixed < SIZE[1] / 2 || (!full && distinguishable < SIZE[1] / 2)) { - fprintf(stderr, - "%s insensitive %s %s edge oracle: mixed=%u distinct=%u\n", - subtype, - depthEdge ? "depth" : "silhouette", - mode, - mixed, - distinguishable); - ++failures; + for (const auto &fog : PLANAR_FOG) { + const auto mode = fog.mode, metric = fog.metric; + const bool full = fog.full; + fprintf(stderr, "[fog-setting] edges/%s\n", fog.name); + scene.fog(mode, metric, full); + const auto image = scene.render(); + failures += !sameAuxiliary(baseline, image, scene.subtype); + scene.setColor(0, cueColor(FRONT, full ? 0. : visibility(mode, 4.))); + if (depthEdge || layeredSilhouette) + scene.setColor(1, cueColor(BACK, full ? 0. : visibility(mode, 12.))); + scene.fog("none", metric); + const auto reference = scene.render(); + failures += !expect(scene, + std::string(depthEdge ? "depth edge " : "silhouette ") + mode + " " + + metric, + image, + reference.color); + + unsigned mixed = 0, distinguishable = 0; + double maxPostError = 0.; + for (unsigned p = 0; p < PIXELS; ++p) { + const double coverage = depthEdge + ? (baseline.color[p][0] - BACK[0]) / (FRONT[0] - BACK[0]) + : baseline.color[p][3]; + if (coverage <= 0.05 || coverage >= 0.95) + continue; + ++mixed; + // A tempting but wrong resolved-depth implementation, evaluated on + // unfogged output. Assert that the oracle can reject it, not just + // that two equivalent public-ANARI renders happen to agree. + const double t = full ? 0. : visibility(mode, baseline.depth[p]); + double error = 0.; + for (unsigned c = 0; c < 3; ++c) { + const double post = t * baseline.color[p][c] + + baseline.color[p][3] * (1. - t) * FOG_COLOR[c]; + error = std::fmax(error, std::abs(post - reference.color[p][c])); } - printf("%s %s %s %s: 256 spp, mixed=%u, max resolved-depth error=%g\n", + maxPostError = std::fmax(maxPostError, error); + distinguishable += error > 0.01; + } + if (mixed < SIZE[1] / 2 || (!full && distinguishable < SIZE[1] / 2)) { + fprintf(stderr, + "%s insensitive %s %s edge oracle: mixed=%u distinct=%u\n", subtype, - depthEdge ? "depth edge" : "silhouette", + depthEdge ? "depth" : "silhouette", mode, - metric, mixed, - maxPostError); - scene.setColor(0, FRONT); - if (depthEdge || layeredSilhouette) - scene.setColor(1, BACK); + distinguishable); + ++failures; } + printf( + "%s %s %s %s: 64 spp, mixed=%u distinct=%u, max resolved-depth error=%g\n", + subtype, + depthEdge ? "depth edge" : "silhouette", + mode, + metric, + mixed, + distinguishable, + maxPostError); + scene.setColor(0, FRONT); + if (depthEdge || layeredSilhouette) + scene.setColor(1, BACK); } scene.fog("none", "viewDepth"); const auto restored = scene.render(); @@ -560,6 +627,7 @@ int testEdges(anari::Device d, const char *subtype) int testLighting(anari::Device d, const char *subtype) { + logCase(std::string(subtype) + "/lighting-AO"); Scene scene(d, subtype); constexpr Vec3 GRAY{0.4f, 0.4f, 0.4f}; // Pixel-aligned opaque planes: every sample in a pixel sees the same depth. @@ -588,7 +656,7 @@ int testLighting(anari::Device d, const char *subtype) d, scene.renderer, "ambientOcclusionDistance", distance); }; setAoDistance(20.f); - anari::setParameter(d, scene.renderer, "pixelSamples", 64); + scene.setSamples(64); int failures = 0; // Quality path-traces ambient illumination; only straight-through renderers // expose the bounded AO estimator. Remove direct lighting to isolate it. @@ -658,24 +726,24 @@ int testLighting(anari::Device d, const char *subtype) backMean); ++failures; } - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"linear", "exp", "exp2", "full"}) { - const bool full = std::string(mode) == "full"; - scene.fog(full ? "linear" : mode, metric, full); - auto expected = baseline.color; - for (unsigned p = 0; p < PIXELS; ++p) { - const double z = p % SIZE[0] >= SIZE[0] / 2 ? 4. : 12.; - const double t = full ? 0. : visibility(mode, z); - for (unsigned c = 0; c < 3; ++c) - expected[p][c] = t * expected[p][c] + (1. - t) * FOG_COLOR[c]; - } - const auto image = scene.render(); - failures += !expect(scene, - std::string("paired lighting/AO ") + mode + " " + metric, - image, - expected); - failures += !sameAuxiliary(baseline, image, scene.subtype); + for (const auto &fog : PLANAR_FOG) { + const auto mode = fog.mode, metric = fog.metric; + const bool full = fog.full; + fprintf(stderr, "[fog-setting] lighting/%s\n", fog.name); + scene.fog(mode, metric, full); + auto expected = baseline.color; + for (unsigned p = 0; p < PIXELS; ++p) { + const double z = p % SIZE[0] >= SIZE[0] / 2 ? 4. : 12.; + const double t = full ? 0. : visibility(mode, z); + for (unsigned c = 0; c < 3; ++c) + expected[p][c] = t * expected[p][c] + (1. - t) * FOG_COLOR[c]; } + const auto image = scene.render(); + failures += !expect(scene, + std::string("paired lighting/AO ") + mode + " " + metric, + image, + expected); + failures += !sameAuxiliary(baseline, image, scene.subtype); } printf("%s paired lighting/AO: 64 spp x 16 AO samples, front=%g back=%g\n", subtype, @@ -686,11 +754,12 @@ int testLighting(anari::Device d, const char *subtype) int testDisabledChannels(anari::Device d, const char *subtype) { + logCase(std::string(subtype) + "/disabled-channels"); Scene scene(d, subtype); scene.addPlane(4.f, {0.2f, 0.3f, 0.1f}, 0.25f, -100.f, 0.f); scene.addPlane(12.f, {0.1f, 0.2f, 0.4f}, 0.5f); // Paired 64-spp realizations test exact preservation, not convergence. - anari::setParameter(d, scene.renderer, "pixelSamples", 64); + scene.setSamples(64); anari::commitParameters(d, scene.renderer); const auto omitted = scene.render(); int failures = 0; @@ -727,10 +796,8 @@ void configureLayers( Scene &scene, const char *mode, const char *metric, bool background) { const auto d = scene.device; - anari::setParameter(d, - scene.renderer, - "pixelSamples", - std::string(scene.subtype) == "quality" ? 4096 : 1); + // This is a paired fresh/reused oracle, not the independent coverage mean. + scene.setSamples(std::string(scene.subtype) == "quality" ? 64 : 1); anari::setParameter(d, scene.renderer, "background", @@ -744,6 +811,7 @@ void configureLayers( int testLayeredRecommit(anari::Device d, const char *subtype) { + logCase(std::string(subtype) + "/layered-recommit"); Scene reused(d, subtype); reused.addPlane(4.f, {0.2f, 0.3f, 0.1f}, 0.25f); reused.addPlane(12.f, {0.1f, 0.2f, 0.4f}, 0.5f); @@ -754,6 +822,9 @@ int testLayeredRecommit(anari::Device d, const char *subtype) // Deliberately leave old accumulated color, not merely a committed setting. for (unsigned i = 0; i < 4; ++i) reused.render(); + int oldSamples = -1; + const bool haveOldSamples = anari::getProperty( + d, reused.frame, "numSamples", oldSamples, ANARI_WAIT); const bool background = std::string(mode) == "exp"; const char *metric = background ? "rayDistance" : "viewDepth"; configureLayers(reused, mode, metric, background); @@ -764,6 +835,31 @@ int testLayeredRecommit(anari::Device d, const char *subtype) fresh.rayBuffer(); configureLayers(fresh, mode, metric, background); const auto reference = fresh.render(); + int actualSamples = -1, freshSamples = -1; + const bool haveActualSamples = anari::getProperty( + d, reused.frame, "numSamples", actualSamples, ANARI_WAIT); + const bool haveFreshSamples = anari::getProperty( + d, fresh.frame, "numSamples", freshSamples, ANARI_WAIT); + // The default sampleLimit can cap the old renders. Require actual retained + // accumulation beyond one render, not an assumed four-times-spp count. + if (!haveOldSamples || !haveActualSamples || !haveFreshSamples + || oldSamples <= reused.samples || actualSamples != reused.samples + || freshSamples != reused.samples) { + fprintf(stderr, + "%s %s incorrect accumulation counts: old=%d changed=%d fresh=%d\n", + subtype, + mode, + oldSamples, + actualSamples, + freshSamples); + ++failures; + } + printf("%s %s accumulation counts: old=%d changed=%d fresh=%d\n", + subtype, + mode, + oldSamples, + actualSamples, + freshSamples); // Fresh/reused realizations use identical accumulation-frame-zero samples; // unlike the analytic coverage mean above, this comparison is paired. failures += !expect(reused, @@ -774,9 +870,9 @@ int testLayeredRecommit(anari::Device d, const char *subtype) } printf( "%s layered recommits: fresh-renderer paired checks, %d spp, " - "four old accumulation frames per transition\n", + "four old render calls per transition (subject to sampleLimit)\n", subtype, - std::string(subtype) == "quality" ? 4096 : 1); + reused.samples); return failures; } diff --git a/devices/rtx/apps/tests/api/TestRendererFogDistance.cpp b/devices/rtx/apps/tests/api/TestRendererFogDistance.cpp index 08794360b..18f23af22 100644 --- a/devices/rtx/apps/tests/api/TestRendererFogDistance.cpp +++ b/devices/rtx/apps/tests/api/TestRendererFogDistance.cpp @@ -375,6 +375,137 @@ int testRayBuffer(anari::Device d, const char *subtype) return failures; } +// The black distance fixtures cannot detect a lost albedo, and world-level +// surfaces do not supply an application instance ID. Keep one colored, +// explicitly instanced surface as a non-vacuous auxiliary-channel anchor. +int testSurfaceChannels(anari::Device d, const char *subtype) +{ + fprintf(stderr, "[fog-case] surface-channels %s baseline\n", subtype); + fflush(stderr); + Scene scene(d, subtype, "orthographic"); + constexpr Vec3 COLOR = {0.2f, 0.4f, 0.8f}; + constexpr Vec3 FOG = {0.8f, 0.3f, 0.1f}; + constexpr Vec4 BACKDROP = {0.1f, 0.6f, 0.9f, 0.25f}; + auto material = anari::newObject(d, "matte"); + const ObjectOwner materialOwner(d, material); + anari::setParameter(d, material, "color", COLOR); + anari::commitParameters(d, material); + anari::setParameter(d, scene.surface, "material", material); + anari::commitParameters(d, scene.surface); + auto group = anari::newObject(d); + const ObjectOwner groupOwner(d, group); + anari::setParameterArray1D(d, group, "surface", &scene.surface, 1); + anari::commitParameters(d, group); + auto instance = anari::newObject(d, "transform"); + const ObjectOwner instanceOwner(d, instance); + anari::setParameter(d, instance, "group", group); + anari::setParameter(d, instance, "id", 73u); + anari::commitParameters(d, instance); + anari::unsetParameter(d, scene.world, "surface"); + anari::setParameterArray1D(d, scene.world, "instance", &instance, 1); + anari::commitParameters(d, scene.world); + anari::setParameter(d, scene.renderer, "ambientRadiance", 1.f); + anari::setParameter(d, scene.renderer, "background", BACKDROP); + anari::setParameter(d, scene.renderer, "premultiplyBackground", false); + anari::setParameter(d, scene.renderer, "fogColor", FOG); + scene.fog("none", nullptr); + scene.render(); + const auto baseline = auxiliary(scene); + int failures = 0; + for (unsigned p = 0; p < PIXELS; ++p) { + bool valid = near(baseline.depth[p], 10.) + && near(std::abs(baseline.normal[p][2]), 1.) + && baseline.primitive[p] <= 1u && baseline.object[p] == 42u + && baseline.instance[p] == 73u && near(baseline.color[p][3], 1.); + for (int c = 0; c < 3; ++c) + valid &= near(baseline.color[p][c], COLOR[c]) + && near(baseline.albedo[p][c], COLOR[c]); + if (!valid) { + fprintf(stderr, + "%s surface-channel baseline invalid at %u: depth=%g normal=%g " + "albedo=(%g,%g,%g) IDs=%u/%u/%u\n", + subtype, + p, + baseline.depth[p], + baseline.normal[p][2], + baseline.albedo[p][0], + baseline.albedo[p][1], + baseline.albedo[p][2], + baseline.primitive[p], + baseline.object[p], + baseline.instance[p]); + ++failures; + } + } + struct Case + { + const char *mode; + const char *metric; + const char *source; + float end; + }; + constexpr Case CASES[] = { + {"linear", "viewDepth", "constant", FOG_END}, + {"linear", "rayDistance", "background", FOG_END}, + {"exp", "viewDepth", "background", FOG_END}, + {"exp", "rayDistance", "constant", FOG_END}, + {"exp2", "viewDepth", "constant", FOG_END}, + {"exp2", "rayDistance", "background", FOG_END}, + {"linear", "rayDistance", "background", 1.f}, + }; + for (const auto &test : CASES) { + fprintf(stderr, + "[fog-case] surface-channels %s %s %s %s end=%g\n", + subtype, + test.mode, + test.metric, + test.source, + test.end); + fflush(stderr); + scene.fog(test.mode, test.metric); + anari::setParameter(d, scene.renderer, "fogColorSource", test.source); + anari::setParameter(d, scene.renderer, "fogEnd", test.end); + anari::commitParameters(d, scene.renderer); + scene.render(); + const auto actual = auxiliary(scene); + // Opaque contribution: V*C + (1-V)*F, alpha=1. This specification + // equation is independent of shading output and production fog helpers. + const double visibility = + referenceVisibility(test.mode, 10., 0., test.end, FOG_DENSITY); + const bool background = std::string(test.source) == "background"; + for (unsigned p = 0; p < PIXELS; ++p) { + for (int c = 0; c < 3; ++c) { + const double expected = visibility * COLOR[c] + + (1. - visibility) * (background ? BACKDROP[c] : FOG[c]); + if (!near(actual.color[p][c], expected)) { + fprintf(stderr, + "%s %s %s %s pixel %u channel %d: %g expected %g\n", + subtype, + test.mode, + test.metric, + test.source, + p, + c, + actual.color[p][c], + expected); + ++failures; + } + } + } + failures += !sameAuxiliary(baseline, actual, subtype); + } + // Disable after full fog, without a Frame commit or manual reset. + scene.fog("none", "rayDistance"); + failures += scene.render() != baseline.color; + failures += !sameAuxiliary(baseline, auxiliary(scene), subtype); + printf( + "%s colored surface channels: 7 fog settings, positive albedo, " + "depth/normal and IDs (0 or 1)/42/73, %d failures\n", + subtype, + failures); + return failures; +} + int testOpaqueCutPlane(anari::Device d) { Scene scene(d, "quality", "orthographic"); @@ -554,6 +685,7 @@ int main() for (const char *subtype : {"fast", "interactive", "default", "quality"}) { failures += testPlanes(device, subtype); failures += testRayBuffer(device, subtype); + failures += testSurfaceChannels(device, subtype); failures += testAperture(device, subtype); failures += testMetricLifecycle(device, subtype, warnings); } diff --git a/devices/rtx/apps/tests/api/TestRendererFogInteractions.cpp b/devices/rtx/apps/tests/api/TestRendererFogInteractions.cpp index 85a9f31df..73aee7ba4 100644 --- a/devices/rtx/apps/tests/api/TestRendererFogInteractions.cpp +++ b/devices/rtx/apps/tests/api/TestRendererFogInteractions.cpp @@ -121,7 +121,9 @@ Image Scene::render(int samples) anari::setParameter(d, frame, "camera", camera); anari::setParameter(d, frame, "renderer", renderer); anari::commitParameters(d, frame); + anari::render(d, frame); + anari::wait(d, frame); return readImage(d, frame, {WIDTH, WIDTH}); } @@ -213,6 +215,7 @@ anari::Light quadLight(anari::Device d) int testProxy(Scene &scene) { + logCase(std::string(scene.subtype) + "/proxy"); int failures = 0; const auto d = scene.d; auto light = quadLight(d); @@ -270,6 +273,7 @@ int testProxy(Scene &scene) // This isolates light transport from fog on the receiver itself. int testIllumination(Scene &scene) { + logCase(std::string(scene.subtype) + "/illumination"); if (std::string(scene.subtype) == "fast") return 0; // Fast uses headlight shading, not analytic-light illumination. const auto d = scene.d; @@ -345,6 +349,7 @@ anari::Volume slab(anari::Device d, int testVolume(Scene &scene) { + logCase(std::string(scene.subtype) + "/volume"); const auto d = scene.d; int failures = 0; auto volume = slab(d, 2.f); @@ -452,6 +457,7 @@ bool expectSlabMean(const Scene &scene, int testJitteredVolume(Scene &scene) { + logCase(std::string(scene.subtype) + "/jittered-volume"); const auto d = scene.d; int failures = 0; auto volume = slab(d, 2.03125f); @@ -523,6 +529,7 @@ void configureObliqueRayBuffer(Scene &scene) anari::setParameter(d, scene.renderer, "premultiplyBackground", false); anari::setParameter(d, scene.renderer, "ambientRadiance", 0.f); anari::setParameter(d, scene.renderer, "maxRayDepth", 4); + anari::commitParameters(d, scene.renderer); } double qualityFraction(unsigned p, float z, bool radial, bool full) @@ -537,6 +544,59 @@ Vec3 qualityTarget(bool background) return background ? Vec3{BACKDROP[0], BACKDROP[1], BACKDROP[2]} : FOG_COLOR; } +struct FogCase +{ + const char *name; + const char *mode; + bool radial; + bool background; + bool full; + bool representativeOnly = false; +}; + +// Complete selector products belong to the absorbing surface representative. +// Other paths distinguish both distances/sources locally, and retain both full +// colors; at saturation the metrics are equivalent for every supplied hit. +constexpr FogCase QUALITY_CASES[] = { + {"linear-view-constant", "linear", false, false, false}, + {"linear-ray-background", "linear", true, true, false}, + {"linear-view-background", "linear", false, true, false, true}, + {"linear-ray-constant", "linear", true, false, false, true}, + {"full-constant", "linear", false, false, true}, + {"full-background", "linear", true, true, true}}; + +// All curves still exercise volume/proxy composition on every contribution +// path. Only the volume+surface representative repeats the other source at +// each metric. Independent cheap formula/selector anchors cover those products +// without multiplying every physical interaction (see the coverage ledger). +constexpr FogCase STRAIGHT_CASES[] = { + {"linear-view-constant", "linear", false, false, false}, + {"linear-ray-background", "linear", true, true, false}, + {"exp-view-constant", "exp", false, false, false}, + {"exp-ray-background", "exp", true, true, false}, + {"exp2-view-constant", "exp2", false, false, false}, + {"exp2-ray-background", "exp2", true, true, false}, + {"linear-view-background", "linear", false, true, false, true}, + {"linear-ray-constant", "linear", true, false, false, true}, + {"exp-view-background", "exp", false, true, false, true}, + {"exp-ray-constant", "exp", true, false, false, true}, + {"exp2-view-background", "exp2", false, true, false, true}, + {"exp2-ray-constant", "exp2", true, false, false, true}, + {"full-constant", "linear", false, false, true}, + {"full-background", "linear", true, true, true}, + {"disabled-restoration", "none", true, true, false}}; + +void caseLabel(const Scene &scene, const std::string &path, const char *name) +{ + fflush(stdout); + fprintf(stderr, + "[fog-interaction] %s/%s/%s\n", + scene.subtype, + path.c_str(), + name); + fflush(stderr); +} + void qualityFog(Scene &scene, bool radial, bool background, bool full) { anari::setParameter(scene.d, @@ -553,25 +613,29 @@ void qualityFog(Scene &scene, bool radial, bool background, bool full) bool expectQuality(const char *label, const Image &image, const std::vector &expected, - double sampleRange = 0.) + double sampleRange = 0., + int samples = QUALITY_SAMPLES) { // A Bernoulli camera survival/coverage decision has range <= sampleRange. // Hoeffding, two-sided failure probability 1e-9 per assertion, gives the // per-pixel and per-origin-group bounds independently of measured error. - // Each group has 120 pixels * 4096 samples. Paired volume-lighting estimates + // Each group has 120 pixels * samples. Paired volume-lighting estimates // cancel when testing the added surface term, so only survival is random. + // All nonzero-range assertions retain 4096 spp. Zero-opacity primary proxies + // are deterministic and use 1 spp with the same original numeric criterion. const double pixelBound = - sampleRange * std::sqrt(std::log(2. / 1e-9) / (2. * QUALITY_SAMPLES)); + sampleRange * std::sqrt(std::log(2. / 1e-9) / (2. * samples)); const double groupBound = pixelBound / std::sqrt(120.); double meanError[2][4] = {}; - double maxError = 0., maxMean = 0.; + double maxError = 0., maxMean = 0., maxBoundRatio = 0.; bool ok = true; for (unsigned p = 0; p < PIXELS; ++p) { for (unsigned c = 0; c < 4; ++c) { const double error = double(image.color[p][c]) - expected[p][c]; const double numeric = 1e-5 + 1e-4 * std::abs(expected[p][c]); - ok &= std::isfinite(error) - && std::abs(error) <= numeric + (isMiss(p) ? 0. : pixelBound); + const double bound = numeric + (isMiss(p) ? 0. : pixelBound); + ok &= std::isfinite(error) && std::abs(error) <= bound; + maxBoundRatio = std::max(maxBoundRatio, std::abs(error) / bound); maxError = std::max(maxError, std::abs(error)); if (!isMiss(p)) meanError[p % 2][c] += error / 120.; @@ -581,20 +645,26 @@ bool expectQuality(const char *label, for (double error : group) { maxMean = std::max(maxMean, std::abs(error)); ok &= std::abs(error) <= groupBound + 0.00011; + maxBoundRatio = + std::max(maxBoundRatio, std::abs(error) / (groupBound + 0.00011)); } - printf("quality %s: max error=%g mean=%g bounds=%g/%g (%d spp)%s\n", + printf( + "quality %s: max error=%g mean=%g bounds=%g/%g (%d spp) max-bound-ratio=%g%s\n", label, maxError, maxMean, pixelBound, groupBound, - QUALITY_SAMPLES, + samples, + maxBoundRatio, ok ? "" : " FAILED"); + fflush(stdout); return ok; } int testQualityProxyCoverage(Scene &scene) { + logCase("quality/proxy-coverage"); const auto d = scene.d; configureObliqueRayBuffer(scene); auto light = quadLight(d); @@ -605,11 +675,17 @@ int testQualityProxyCoverage(Scene &scene) anari::commitParameters(d, light); int failures = 0; for (float coverage : {0.f, 0.25f}) { + // Zero-opacity camera pass-through has no sampled coverage decision. + // The fractional witness keeps its independent 4096-spp coverage anchor. + const int samples = coverage == 0.f ? 1 : QUALITY_SAMPLES; + const std::string path = + coverage == 0.f ? "proxy-pass-through" : "proxy-fractional"; + caseLabel(scene, path, "baseline"); auto front = plane(d, 2.5f, {}, 0.f, false, 20.f, coverage); const ObjectOwner frontOwner(d, front); scene.attach(front, light); scene.fog("none"); - const auto baseline = scene.render(QUALITY_SAMPLES); + const auto baseline = scene.render(samples); auto expected = baseline.color; for (unsigned p = 0; p < PIXELS; ++p) { expected[p] = BACKDROP; @@ -622,44 +698,54 @@ int testQualityProxyCoverage(Scene &scene) failures += !expectQuality("proxy coverage baseline", baseline, expected, - coverage > 0.f ? 1. : 0.); - for (bool radial : {false, true}) { - for (bool background : {false, true}) { - for (bool full : {false, true}) { - qualityFog(scene, radial, background, full); - const auto image = scene.render(QUALITY_SAMPLES); - const auto target = qualityTarget(background); - for (unsigned p = 0; p < PIXELS; ++p) { - if (isMiss(p)) - continue; - const double f = qualityFraction(p, 10.f, radial, full); - const double frontF = qualityFraction(p, 2.5f, radial, full); - for (unsigned c = 0; c < 3; ++c) - expected[p][c] = coverage * frontF * target[c] - + (1. - coverage) * ((1. - f) * RADIANCE[c] + f * target[c]); - } - failures += !expectQuality("proxy through coverage", - image, - expected, - coverage > 0.f ? 1. : 0.); - failures += !sameAuxiliary(baseline, image, scene.subtype); - } + coverage > 0.f ? 1. : 0., + samples); + for (const auto &setting : QUALITY_CASES) { + if (setting.representativeOnly) + continue; + caseLabel(scene, path, setting.name); + qualityFog(scene, setting.radial, setting.background, setting.full); + const auto image = scene.render(samples); + const auto target = qualityTarget(setting.background); + for (unsigned p = 0; p < PIXELS; ++p) { + if (isMiss(p)) + continue; + const double f = qualityFraction(p, 10.f, setting.radial, setting.full); + const double frontF = + qualityFraction(p, 2.5f, setting.radial, setting.full); + for (unsigned c = 0; c < 3; ++c) + expected[p][c] = coverage * frontF * target[c] + + (1. - coverage) * ((1. - f) * RADIANCE[c] + f * target[c]); } + failures += !expectQuality("proxy through coverage", + image, + expected, + coverage > 0.f ? 1. : 0., + samples); + failures += !sameAuxiliary(baseline, image, scene.subtype); } + caseLabel(scene, path, "disabled-restoration"); + scene.fog("none"); + const auto restored = scene.render(samples); + failures += !check( + restored.color == baseline.color, scene, "proxy disable restores RGB"); + failures += !sameAuxiliary(baseline, restored, scene.subtype); // Primary visibility must survive even a zero-opacity pass-through. anari::setParameter(d, light, "visible", false); anari::commitParameters(d, light); scene.fog("none"); - const auto hidden = scene.render(QUALITY_SAMPLES); + caseLabel(scene, path, "hidden-baseline"); + const auto hidden = scene.render(samples); qualityFog(scene, true, false, true); - const auto hiddenFog = scene.render(QUALITY_SAMPLES); + caseLabel(scene, path, "hidden-full"); + const auto hiddenFog = scene.render(samples); expected = hidden.color; for (unsigned p = 0; p < PIXELS; ++p) if (!isMiss(p)) for (unsigned c = 0; c < 3; ++c) expected[p][c] += coverage * FOG_COLOR[c]; - failures += - !expectQuality("hidden proxy through coverage", hiddenFog, expected); + failures += !expectQuality( + "hidden proxy through coverage", hiddenFog, expected, 0., samples); failures += !sameAuxiliary(hidden, hiddenFog, scene.subtype); anari::setParameter(d, light, "visible", true); anari::commitParameters(d, light); @@ -669,6 +755,8 @@ int testQualityProxyCoverage(Scene &scene) int testQualityVolume(Scene &scene, bool scattering) { + logCase( + std::string("quality/volume/scattering=") + std::to_string(scattering)); const auto d = scene.d; configureObliqueRayBuffer(scene); anari::setParameter( @@ -678,6 +766,8 @@ int testQualityVolume(Scene &scene, bool scattering) const ObjectOwner volumeOwner(d, volume); scene.attach({}, {}, volume); scene.fog("none"); + const std::string medium = scattering ? "scattering" : "absorbing"; + caseLabel(scene, medium + "/volume-only", "baseline"); const auto only = scene.render(QUALITY_SAMPLES); // sigma_t = -log(1-opacity)/unitDistance = log(2). The oblique rays // cross a two-unit slab with cos(theta)=4/5: P(no collision)=2^(-2.5). @@ -708,15 +798,15 @@ int testQualityVolume(Scene &scene, bool scattering) int(scattering), volumeRadiance, survival); - for (bool radial : {false, true}) { - for (bool background : {false, true}) { - qualityFog(scene, radial, background, true); - const auto active = scene.render(QUALITY_SAMPLES); - failures += !check(only.color == active.color, - scene, - "sampled volume-only RGB unchanged"); - failures += !sameAuxiliary(only, active, scene.subtype); - } + for (const auto &setting : QUALITY_CASES) { + if (!setting.full) + continue; + caseLabel(scene, medium + "/volume-only", setting.name); + qualityFog(scene, setting.radial, setting.background, true); + const auto active = scene.render(QUALITY_SAMPLES); + failures += !check( + only.color == active.color, scene, "sampled volume-only RGB unchanged"); + failures += !sameAuxiliary(only, active, scene.subtype); } // Absorbing media isolate the transmitted emitter against a fully @@ -736,6 +826,8 @@ int testQualityVolume(Scene &scene, bool scattering) anari::setParameter(d, light, "edge2", Vec3{0.f, 40.f, 0.f}); anari::commitParameters(d, light); for (bool proxy : {false, true}) { + const std::string path = medium + (proxy ? "/proxy" : "/surface"); + caseLabel(scene, path, "baseline"); scene.attach(proxy ? anari::Surface{} : surface, proxy ? light : anari::Light{}, volume); @@ -755,35 +847,40 @@ int testQualityVolume(Scene &scene, bool scattering) expected, 1.); } - for (bool radial : {false, true}) { - for (bool background : {false, true}) { - for (bool full : {false, true}) { - qualityFog(scene, radial, background, full); - const auto image = scene.render(QUALITY_SAMPLES); - const auto target = qualityTarget(background); - expected = baseline.color; - for (unsigned p = 0; p < PIXELS; ++p) { - if (isMiss(p)) - continue; - const double f = qualityFraction(p, 10.f, radial, full); - for (unsigned c = 0; c < 3; ++c) - expected[p][c] = scattering - ? baseline.color[p][c] - + survival * f * (target[c] - (proxy ? RADIANCE[c] : 0.f)) - : survival * ((1. - f) * RADIANCE[c] + f * target[c]); - } - failures += - !expectQuality(scattering ? (proxy ? "proxy with scattering" - : "surface after scattering") - : proxy ? "proxy behind absorbing volume" - : "surface behind absorbing volume", - image, - expected, - 1.); - failures += !sameAuxiliary(baseline, image, scene.subtype); - } + for (const auto &setting : QUALITY_CASES) { + if (setting.representativeOnly && (scattering || proxy)) + continue; + caseLabel(scene, path, setting.name); + qualityFog(scene, setting.radial, setting.background, setting.full); + const auto image = scene.render(QUALITY_SAMPLES); + const auto target = qualityTarget(setting.background); + expected = baseline.color; + for (unsigned p = 0; p < PIXELS; ++p) { + if (isMiss(p)) + continue; + const double f = qualityFraction(p, 10.f, setting.radial, setting.full); + for (unsigned c = 0; c < 3; ++c) + expected[p][c] = scattering + ? baseline.color[p][c] + + survival * f * (target[c] - (proxy ? RADIANCE[c] : 0.f)) + : survival * ((1. - f) * RADIANCE[c] + f * target[c]); } + failures += !expectQuality(scattering + ? (proxy ? "proxy with scattering" : "surface after scattering") + : proxy ? "proxy behind absorbing volume" + : "surface behind absorbing volume", + image, + expected, + 1.); + failures += !sameAuxiliary(baseline, image, scene.subtype); } + caseLabel(scene, path, "disabled-restoration"); + scene.fog("none"); + const auto restored = scene.render(QUALITY_SAMPLES); + failures += !check(restored.color == baseline.color, + scene, + "volume path disable restores RGB"); + failures += !sameAuxiliary(baseline, restored, scene.subtype); } return failures; } @@ -795,11 +892,12 @@ enum class Contribution PROXY }; -// Release cross-product for the straight-through Renderers. Oblique supplied +// Named composition contracts for straight-through Renderers. Oblique supplied // rays distinguish the two metrics; the black homogeneous slab has exactly // forty march steps and transmission 2^(-2.5), independent of sample jitter. -int testStraightThroughMatrix(Scene &scene) +int testStraightThroughContracts(Scene &scene) { + logCase(std::string(scene.subtype) + "/straight-through"); const auto d = scene.d; configureObliqueRayBuffer(scene); anari::setParameter(d, scene.renderer, "ambientRadiance", 1.f); @@ -825,72 +923,79 @@ int testStraightThroughMatrix(Scene &scene) const bool hit = contribution == Contribution::SURFACE || (contribution == Contribution::PROXY && std::string(scene.subtype) != "fast"); + const std::string path = std::string(hasVolume ? "volume/" : "clear/") + + (contribution == Contribution::SURFACE ? "surface" + : contribution == Contribution::PROXY ? "proxy" + : "backdrop"); + caseLabel(scene, path, "baseline"); scene.attach( contribution == Contribution::SURFACE ? surface : anari::Surface{}, contribution == Contribution::PROXY ? light : anari::Light{}, hasVolume ? volume : anari::Volume{}); scene.fog("none"); const auto baseline = scene.render(); - for (bool radial : {false, true}) { - for (bool background : {false, true}) { - for (const char *mode : {"none", "linear", "exp", "exp2", "full"}) { - const bool full = std::string(mode) == "full"; - qualityFog(scene, radial, background, full); - scene.fog(full ? "linear" : mode, 0.f, full ? 0.01f : 20.f); - const auto image = scene.render(); - const auto target = qualityTarget(background); - bool ok = true; - for (unsigned p = 0; p < PIXELS; ++p) { - Vec4 expected = BACKDROP; - if (!isMiss(p)) { - const double survival = hasVolume ? std::pow(2., -2.5) : 1.; - const double distance = - radial ? (10. - 2 * (p % 2)) * 1.25 : 11.; - const std::string curve(mode); - const double visibility = curve == "none" ? 1. - : full ? 0. - : curve == "linear" - ? 1. - distance / 20. - : std::exp(curve == "exp" ? -0.05 * distance - : -std::pow(0.05 * distance, 2)); - for (unsigned c = 0; c < 3; ++c) - expected[c] = survival - * (hit ? visibility * RADIANCE[c] - + (1. - visibility) * target[c] - : BACKDROP[c]); - expected[3] = hit ? 1. : 1. - survival * (1. - BACKDROP[3]); - } - for (unsigned c = 0; c < 4; ++c) { - const double error = - std::abs(double(image.color[p][c]) - expected[c]); - maximumError = std::max(maximumError, error); - ok &= std::isfinite(error) - && error <= 1e-5 + 1e-4 * std::abs(expected[c]); - } - } - if (!ok) - fprintf(stderr, - "%s cross interaction: volume=%d contribution=%d metric=%s source=%s curve=%s\n", - scene.subtype, - int(hasVolume), - int(contribution), - radial ? "rayDistance" : "viewDepth", - background ? "background" : "constant", - mode); - failures += !ok; - failures += !sameAuxiliary(baseline, image, scene.subtype); - if (!hit) - failures += !check(image.color == baseline.color, - scene, - "volume-only/miss output unchanged in cross-product"); - ++cases; + for (const auto &setting : STRAIGHT_CASES) { + if (setting.representativeOnly + && !(hasVolume && contribution == Contribution::SURFACE)) + continue; + caseLabel(scene, path, setting.name); + const auto *mode = setting.mode; + const bool radial = setting.radial; + const bool background = setting.background; + const bool full = setting.full; + qualityFog(scene, radial, background, full); + scene.fog(mode, 0.f, full ? 0.01f : 20.f); + const auto image = scene.render(); + const auto target = qualityTarget(background); + bool ok = true; + for (unsigned p = 0; p < PIXELS; ++p) { + Vec4 expected = BACKDROP; + if (!isMiss(p)) { + const double survival = hasVolume ? std::pow(2., -2.5) : 1.; + const double distance = radial ? (10. - 2 * (p % 2)) * 1.25 : 11.; + const std::string curve(mode); + const double visibility = curve == "none" ? 1. + : full ? 0. + : curve == "linear" + ? 1. - distance / 20. + : std::exp(curve == "exp" ? -0.05 * distance + : -std::pow(0.05 * distance, 2)); + for (unsigned c = 0; c < 3; ++c) + expected[c] = survival + * (hit ? visibility * RADIANCE[c] + + (1. - visibility) * target[c] + : BACKDROP[c]); + expected[3] = hit ? 1. : 1. - survival * (1. - BACKDROP[3]); + } + for (unsigned c = 0; c < 4; ++c) { + const double error = + std::abs(double(image.color[p][c]) - expected[c]); + maximumError = std::max(maximumError, error); + ok &= std::isfinite(error) + && error <= 1e-5 + 1e-4 * std::abs(expected[c]); } } + if (!ok) + fprintf(stderr, + "%s cross interaction: volume=%d contribution=%d metric=%s source=%s curve=%s\n", + scene.subtype, + int(hasVolume), + int(contribution), + radial ? "rayDistance" : "viewDepth", + background ? "background" : "constant", + mode); + failures += !ok; + failures += !sameAuxiliary(baseline, image, scene.subtype); + if (!hit || std::string(mode) == "none") + failures += !check(image.color == baseline.color, + scene, + "volume-only/miss or disabled output unchanged"); + ++cases; } } } printf( - "%s straight-through interaction matrix: %u cases, max absolute error=%g\n", + "%s straight-through interaction contracts: %u cases, max absolute error=%g\n", scene.subtype, cases, maximumError); @@ -913,7 +1018,7 @@ int main() failures += testIllumination(scene); failures += testVolume(scene); failures += testJitteredVolume(scene); - failures += testStraightThroughMatrix(scene); + failures += testStraightThroughContracts(scene); } { Scene scene(d, "quality"); diff --git a/devices/rtx/apps/tests/api/TestRendererFogTransport.cpp b/devices/rtx/apps/tests/api/TestRendererFogTransport.cpp index ef1987b9b..0261a2b85 100644 --- a/devices/rtx/apps/tests/api/TestRendererFogTransport.cpp +++ b/devices/rtx/apps/tests/api/TestRendererFogTransport.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include @@ -25,9 +27,73 @@ constexpr Vec3 FOG{0.3f, 0.9f, 0.2f}; constexpr Vec3 EMISSION{1.6f, 0.8f, 1.2f}; constexpr Vec3 TINT{0.6f, 0.8f, 0.4f}; constexpr int SAMPLES = 4096; +constexpr int PAIRED_SAMPLES = 64; constexpr float FOG_END = 20.f; constexpr float FOG_DENSITY = 0.1f; +struct FogSetting +{ + const char *name; + const char *mode; + const char *metric; + bool background; +}; + +// These representatives cover every active combination on both BSDF paths and +// indirect volume radiance. Saturated metrics and disabled selectors are +// equivalent here; restore none after active fog, not before it. +constexpr FogSetting COMPLETE_FOG[] = { + {"linear-depth-constant", "linear", "viewDepth", false}, + {"exp-depth-constant", "exp", "viewDepth", false}, + {"exp2-depth-constant", "exp2", "viewDepth", false}, + {"linear-ray-constant", "linear", "rayDistance", false}, + {"exp-ray-constant", "exp", "rayDistance", false}, + {"exp2-ray-constant", "exp2", "rayDistance", false}, + {"linear-depth-image", "linear", "viewDepth", true}, + {"exp-depth-image", "exp", "viewDepth", true}, + {"exp2-depth-image", "exp2", "viewDepth", true}, + {"linear-ray-image", "linear", "rayDistance", true}, + {"exp-ray-image", "exp", "rayDistance", true}, + {"exp2-ray-image", "exp2", "rayDistance", true}, + {"saturated-constant", "full", "viewDepth", false}, + {"saturated-image", "full", "viewDepth", true}, + {"disabled-restoration", "none", "rayDistance", true}}; + +// Distance, proxy, fractional coverage and roulette retain both unequal camera +// metrics, both sources, all curves and both endpoints. Cheap independent fog +// anchors plus COMPLETE_FOG carry the selector products, not these variations. +constexpr FogSetting VARIATION_FOG[] = { + {"linear-depth-constant", "linear", "viewDepth", false}, + {"linear-ray-constant", "linear", "rayDistance", false}, + {"exp-depth-image", "exp", "viewDepth", true}, + {"exp2-ray-image", "exp2", "rayDistance", true}, + {"saturated-constant", "full", "viewDepth", false}, + {"disabled-restoration", "none", "rayDistance", true}}; + +struct TransportCase +{ + const char *name; + bool transmission; + float emitterZ; + float coverage; + unsigned panes; + bool proxy; + bool completeSettings; +}; + +constexpr TransportCase TRANSPORT_CASES[] = { + {"reflection-matrix", false, -3.f, 0.f, 1, false, true}, + {"reflection-distant-emitter", false, -19.f, 0.f, 1, false, false}, + {"refraction-matrix", true, 13.f, 0.f, 1, false, true}, + {"refraction-distant-emitter", true, 29.f, 0.f, 1, false, false}, + {"reflection-fractional-coverage", false, -19.f, .25f, 1, false, false}, + {"refraction-fractional-coverage", true, 29.f, .25f, 1, false, false}, + {"refraction-four-panes-roulette", true, 29.f, 0.f, 4, false, false}, + {"reflection-hidden-proxy", false, -3.f, 0.f, 1, true, false}, + {"reflection-distant-hidden-proxy", false, -19.f, 0.f, 1, true, false}, + {"refraction-hidden-proxy", true, 13.f, 0.f, 1, true, false}, + {"refraction-distant-hidden-proxy", true, 29.f, 0.f, 1, true, false}}; + /* Public-ANARI transport fixture with paired camera samples and controlled * indirect radiance; no production fog evaluator defines its references. */ @@ -44,7 +110,9 @@ struct Scene float opacity = 1.f, bool metal = false); void fog(const char *mode, const char *metric, bool background); - Image render(); + anari::Frame newFrame(); + Image render(anari::Frame target = nullptr); + Image pairedBaseline(int &failures); Vec3 backdrop(unsigned pixel) const; anari::Device d; @@ -52,6 +120,7 @@ struct Scene anari::Renderer renderer; anari::Camera camera; anari::Frame frame; + int samples = SAMPLES; std::vector surfaces; std::vector materials; }; @@ -102,24 +171,30 @@ Scene::Scene(anari::Device device) : d(device) anari::setParameter(d, camera, "position", Vec3{0.f, 0.f, -1.f}); anari::setParameter(d, camera, "direction", Vec3{0.f, 0.f, 1.f}); anari::commitParameters(d, camera); - frame = anari::newObject(d); - ObjectOwner frameOwner(d, frame); - anari::setParameter(d, frame, "size", SIZE); - anari::setParameter(d, frame, "channel.color", ANARI_FLOAT32_VEC4); - anari::setParameter(d, frame, "channel.depth", ANARI_FLOAT32); - anari::setParameter(d, frame, "channel.normal", ANARI_FLOAT32_VEC3); - anari::setParameter(d, frame, "channel.albedo", ANARI_FLOAT32_VEC3); - for (const char *name : - {"channel.primitiveId", "channel.objectId", "channel.instanceId"}) - anari::setParameter(d, frame, name, ANARI_UINT32); - anari::setParameter(d, frame, "world", world); - anari::setParameter(d, frame, "camera", camera); - anari::setParameter(d, frame, "renderer", renderer); - anari::commitParameters(d, frame); + frame = newFrame(); worldOwner.release(); rendererOwner.release(); cameraOwner.release(); +} + +anari::Frame Scene::newFrame() +{ + auto result = anari::newObject(d); + ObjectOwner frameOwner(d, result); + anari::setParameter(d, result, "size", SIZE); + anari::setParameter(d, result, "channel.color", ANARI_FLOAT32_VEC4); + anari::setParameter(d, result, "channel.depth", ANARI_FLOAT32); + anari::setParameter(d, result, "channel.normal", ANARI_FLOAT32_VEC3); + anari::setParameter(d, result, "channel.albedo", ANARI_FLOAT32_VEC3); + for (const char *name : + {"channel.primitiveId", "channel.objectId", "channel.instanceId"}) + anari::setParameter(d, result, name, ANARI_UINT32); + anari::setParameter(d, result, "world", world); + anari::setParameter(d, result, "camera", camera); + anari::setParameter(d, result, "renderer", renderer); + anari::commitParameters(d, result); frameOwner.release(); + return result; } Scene::~Scene() @@ -207,11 +282,43 @@ void Scene::fog(const char *mode, const char *metric, bool background) anari::commitParameters(d, renderer); } -Image Scene::render() +Image Scene::render(anari::Frame target) { - anari::render(d, frame); - anari::wait(d, frame); - return readImage(d, frame, SIZE); + if (!target) + target = frame; + + anari::render(d, target); + + anari::wait(d, target); + + auto image = readImage(d, target, SIZE); + + int observed = 0; + if (!anari::getProperty(d, target, "numSamples", observed, ANARI_WAIT) + || observed != samples) + throw std::runtime_error("transport sample count: expected " + + std::to_string(samples) + ", observed " + std::to_string(observed)); + return image; +} + +Image Scene::pairedBaseline(int &failures) +{ + // Change only Renderer parameters; old high-sample Frame content must reset + // automatically. A separate fresh Frame observes the same low-sample streams. + samples = PAIRED_SAMPLES; + anari::setParameter(d, renderer, "pixelSamples", samples); + fog("none", "viewDepth", false); + const auto baseline = render(); + auto fresh = newFrame(); + const ObjectOwner freshOwner(d, fresh); + const auto independentFrame = render(fresh); + const bool paired = baseline.color == independentFrame.color + && sameAuxiliary(baseline, independentFrame, "fresh transport baseline"); + printf("paired baseline: fresh/reused %d spp, exact match=%s\n", + samples, + paired ? "yes" : "NO"); + failures += !paired; + return baseline; } double visibility(const char *mode, double distance) @@ -227,7 +334,7 @@ bool expect(const std::string &label, bool stochastic = false, int samples = SAMPLES) { - double maxError = 0., meanErrors[2][3] = {}; + double maxError = 0., maxToleranceFraction = 0., meanErrors[2][3] = {}; bool passed = true; for (unsigned p = 0; p < PIXELS; ++p) { for (unsigned c = 0; c < 3; ++c) { @@ -238,6 +345,8 @@ bool expect(const std::string &label, meanErrors[p % 2][c] += error / (PIXELS / 2); const double limit = stochastic ? 0.05 : 1e-5 + 1e-4 * std::abs(reference[p][c]); + maxToleranceFraction = + std::fmax(maxToleranceFraction, std::abs(error) / limit); passed &= std::abs(error) <= limit; } } @@ -247,12 +356,16 @@ bool expect(const std::string &label, maxMeanError = std::fmax(maxMeanError, std::abs(error)); if (stochastic) passed &= maxMeanError <= 0.009; - printf("%s: %d spp, max RGB error=%g, grouped mean error=%g%s\n", + printf( + "%s: %d spp, max RGB error=%g, grouped mean error=%g, " + "tolerance fraction=%g%s\n", label.c_str(), samples, maxError, maxMeanError, + maxToleranceFraction, passed ? "" : " FAILED"); + fflush(stdout); return passed; } @@ -260,13 +373,20 @@ bool expect(const std::string &label, // setting, pairing transport random streams without a private seed interface. // The expected affine operation is applied to the *unfogged* shaded result; // no production fog helper or resolved-depth channel defines the reference. -int testTransport(anari::Device d, - bool transmission, - float emitterZ, - float coverage, - unsigned panes, - bool proxy = false) +int testTransport(anari::Device d, const TransportCase &test) { + const auto [name, + transmission, + emitterZ, + coverage, + panes, + proxy, + completeSettings] = test; + fprintf(stderr, "[transport-fixture] %s\n", name); + logCase(std::string(transmission ? "refraction" : "reflection") + + (proxy ? "/hidden-proxy" : "/emitter") + "/z=" + + std::to_string(emitterZ) + "/coverage=" + std::to_string(coverage) + + "/panes=" + std::to_string(panes)); Scene scene(d); // Coverage rejection is camera visibility, including numerical re-origining. // The zero-opacity case also ensures a discarded contribution injects no fog. @@ -348,44 +468,48 @@ int testTransport(anari::Device d, } } - for (bool background : {false, true}) { - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"linear", "exp", "exp2", "full", "none"}) { - scene.fog(mode, metric, background); - const auto image = scene.render(); - auto expected = baseline.color; - for (unsigned p = 0; p < PIXELS; ++p) { - const bool radial = std::string(metric) == "rayDistance"; - const double distance = radial ? (5. - 2 * (p % 2)) * 1.25 : 6.; - const double frontDistance = radial ? (3. - 2 * (p % 2)) * 1.25 : 4.; - const double t = visibility(mode, distance); - const double frontT = visibility(mode, frontDistance); - const auto target = background ? scene.backdrop(p) : FOG; - for (unsigned c = 0; c < 3; ++c) { - // Existing frame backdrop compositing is not surface shading. - const double miss = - (1. - baseline.color[p][3]) * scene.backdrop(p)[c]; - expected[p][c] = t * (baseline.color[p][c] - miss) + miss - + (coverage * (1. - frontT) + (1. - coverage) * (1. - t)) - * target[c]; - } - } - // Only the additive rear-layer coverage term is unpaired. Its range - // <=.9 gives six-SE bounds .043/pixel and .0075 per 32-pixel origin - // group at 4096 spp; use .05/.009 including float accumulation error. - const std::string label = - std::string(transmission ? "refraction " : "reflection ") + mode - + " " + metric + (background ? " image" : " constant") - + " coverage=" + std::to_string(coverage) + " panes=" - + std::to_string(panes) + (proxy ? " hidden proxy" : " emitter"); - failures += !expect(label, image, expected, coverage > 0.f); - failures += !sameAuxiliary(baseline, image, "transport"); - if (std::string(mode) == "none" && image.color != baseline.color) { - fprintf(stderr, "disabled fog changed paired transport RGB\n"); - ++failures; - } + // Independent radiance/direct-only anchors above stay at 4096 spp. + // Coverage's additive term does not cancel, so it keeps that budget too. + const auto paired = + coverage == 0.f ? scene.pairedBaseline(failures) : baseline; + const auto *settings = completeSettings ? COMPLETE_FOG : VARIATION_FOG; + const auto count = + completeSettings ? std::size(COMPLETE_FOG) : std::size(VARIATION_FOG); + for (std::size_t i = 0; i < count; ++i) { + const auto [settingName, mode, metric, background] = settings[i]; + fprintf(stderr, "[transport-setting] %s/%s\n", name, settingName); + scene.fog(mode, metric, background); + const auto image = scene.render(); + auto expected = paired.color; + for (unsigned p = 0; p < PIXELS; ++p) { + const bool radial = std::string(metric) == "rayDistance"; + const double distance = radial ? (5. - 2 * (p % 2)) * 1.25 : 6.; + const double frontDistance = radial ? (3. - 2 * (p % 2)) * 1.25 : 4.; + const double t = visibility(mode, distance); + const double frontT = visibility(mode, frontDistance); + const auto target = background ? scene.backdrop(p) : FOG; + for (unsigned c = 0; c < 3; ++c) { + // Existing frame backdrop compositing is not surface shading. + const double miss = (1. - paired.color[p][3]) * scene.backdrop(p)[c]; + expected[p][c] = t * (paired.color[p][c] - miss) + miss + + (coverage * (1. - frontT) + (1. - coverage) * (1. - t)) + * target[c]; } } + // Only the additive rear-layer coverage term is unpaired. Its range + // <=.9 gives six-SE bounds .043/pixel and .0075 per 32-pixel origin + // group at 4096 spp; use .05/.009 including float accumulation error. + const std::string label = + std::string(transmission ? "refraction " : "reflection ") + mode + " " + + metric + (background ? " image" : " constant") + " coverage=" + + std::to_string(coverage) + " panes=" + std::to_string(panes) + + (proxy ? " hidden proxy" : " emitter"); + failures += !expect(label, image, expected, coverage > 0.f, scene.samples); + failures += !sameAuxiliary(paired, image, "transport"); + if (std::string(mode) == "none" && image.color != paired.color) { + fprintf(stderr, "disabled fog changed paired transport RGB\n"); + ++failures; + } } return failures; } @@ -395,10 +519,12 @@ int testHdrRadiance(anari::Device d) int failures = 0; constexpr Vec3 HDR_EMISSION{1e38f, 5e37f, 2e37f}; for (bool indirect : {false, true}) { + logCase(indirect ? "HDR/reflection" : "HDR/emission"); Scene scene(d); // One paired sample avoids overflow in the unfogged accumulation sum. // The accepted surface is at view depth 10, including for reflection. anari::setParameter(d, scene.renderer, "pixelSamples", 1); + scene.samples = 1; anari::setParameter(d, scene.renderer, "fogColor", Vec3{}); if (indirect) scene.plane(9.f, TINT, {}, 0.f, 1.f, true); @@ -449,6 +575,7 @@ int testHdrRadiance(anari::Device d) int testIndirectVolume(anari::Device d) { + logCase("refraction/indirect-volume"); Scene scene(d); scene.plane(3.f, {}, {}, 0.f, 0.f); scene.plane(5.f, TINT, {}, 1.f); @@ -500,34 +627,32 @@ int testIndirectVolume(anari::Device d) // volume NEE and subsequent scattering/RR. Only camera-surface distance is // used, never a sampled volume position. Existing backdrop compositing is // not surface radiance; leave that term unchanged even through refraction. - for (bool background : {false, true}) { - for (const char *metric : {"viewDepth", "rayDistance"}) { - for (const char *mode : {"linear", "exp", "exp2", "full", "none"}) { - scene.fog(mode, metric, background); - const auto image = scene.render(); - auto expected = baseline.color; - for (unsigned p = 0; p < PIXELS; ++p) { - const double distance = std::string(metric) == "rayDistance" - ? (5. - 2 * (p % 2)) * 1.25 - : 6.; - const double t = visibility(mode, distance); - const auto target = background ? scene.backdrop(p) : FOG; - for (unsigned c = 0; c < 3; ++c) { - const double miss = - (1. - baseline.color[p][3]) * scene.backdrop(p)[c]; - expected[p][c] = - t * (baseline.color[p][c] - miss) + miss + (1. - t) * target[c]; - } - } - failures += !expect(std::string("indirect volume ") + mode + " " - + metric + (background ? " image" : " constant"), - image, - expected); - failures += !sameAuxiliary(baseline, image, "transport"); - if (std::string(mode) == "none" && image.color != baseline.color) - ++failures; + const auto paired = scene.pairedBaseline(failures); + for (const auto &[name, mode, metric, background] : COMPLETE_FOG) { + fprintf(stderr, "[transport-setting] indirect-volume/%s\n", name); + scene.fog(mode, metric, background); + const auto image = scene.render(); + auto expected = paired.color; + for (unsigned p = 0; p < PIXELS; ++p) { + const double distance = + std::string(metric) == "rayDistance" ? (5. - 2 * (p % 2)) * 1.25 : 6.; + const double t = visibility(mode, distance); + const auto target = background ? scene.backdrop(p) : FOG; + for (unsigned c = 0; c < 3; ++c) { + const double miss = (1. - paired.color[p][3]) * scene.backdrop(p)[c]; + expected[p][c] = + t * (paired.color[p][c] - miss) + miss + (1. - t) * target[c]; } } + failures += !expect(std::string("indirect volume ") + mode + " " + metric + + (background ? " image" : " constant"), + image, + expected, + false, + scene.samples); + failures += !sameAuxiliary(paired, image, "transport"); + if (std::string(mode) == "none" && image.color != paired.color) + ++failures; } return failures; } @@ -539,17 +664,8 @@ int main() auto device = makeVisRTXDevice(exitOnErrorStatus); const ObjectOwner deviceOwner(device, device); int failures = requireRendererFogSupport(device); - for (float emitterZ : {-3.f, -19.f}) - failures += testTransport(device, false, emitterZ, 0.f, 1); - for (float emitterZ : {13.f, 29.f}) - failures += testTransport(device, true, emitterZ, 0.f, 1); - failures += testTransport(device, false, -19.f, 0.25f, 1); - failures += testTransport(device, true, 29.f, 0.25f, 1); - failures += testTransport(device, true, 29.f, 0.f, 4); - for (float z : {-3.f, -19.f}) - failures += testTransport(device, false, z, 0.f, 1, true); - for (float z : {13.f, 29.f}) - failures += testTransport(device, true, z, 0.f, 1, true); + for (const auto &test : TRANSPORT_CASES) + failures += testTransport(device, test); failures += testIndirectVolume(device); failures += testHdrRadiance(device); if (failures) diff --git a/devices/rtx/device/gpu/renderer/fog.h b/devices/rtx/device/gpu/renderer/fog.h index fa92706cd..0af5dffa0 100644 --- a/devices/rtx/device/gpu/renderer/fog.h +++ b/devices/rtx/device/gpu/renderer/fog.h @@ -46,8 +46,10 @@ VISRTX_DEVICE FogAppearance fogAppearance( // overflow intermediate differences. No world-unit epsilon on intervals. const bool rayDistance = fog.distanceMetric == FogDistanceMetric::RAY_DISTANCE; - const glm::dvec3 delta = glm::dvec3(position) - - glm::dvec3(rayDistance ? cameraOrigin : fd.camera.pos); + // Select values, not references into camera-local and frame-data storage. + const glm::dvec3 origin = + rayDistance ? glm::dvec3(cameraOrigin) : glm::dvec3(fd.camera.pos); + const glm::dvec3 delta = glm::dvec3(position) - origin; const double distance = rayDistance ? glm::length(delta) : fmax(0.0, glm::dot(delta, glm::dvec3(fd.camera.dir)));