public void TestPathTracer() { PCG pcg = new PCG(); for (int i = 0; i < 5; i++) { World world = new World(); float emittedRadiance = pcg.randomFloat(); float reflectance = pcg.randomFloat(); Material enclosureMaterial = new Material( Brdf: new DiffuseBRDF(pig: new UniformPigment(new Color(1f, 1f, 1f) * reflectance)), EmittedRadiance: new UniformPigment(new Color(1f, 1f, 1f) * emittedRadiance) ); world.addShape(new Sphere(material: enclosureMaterial)); PathTracer pathTracer = new PathTracer( world: world, pcg: pcg, numOfRays: 1, maxDepth: 100, russianRouletteLimit: 101 ); Ray ray = new Ray(origin: new Point(0f, 0f, 0f), dir: new Vec(1f, 0f, 0f)); Color color = pathTracer.computeRadiance(ray); float expected = emittedRadiance / (1.0f - reflectance); Assert.True(Utility.areClose(expected, color.r, 1e-3f), $"TestPathTracer failed - Assert i={i}, 1/3"); Assert.True(Utility.areClose(expected, color.g, 1e-3f), $"TestPathTracer failed - Assert i={i}, 2/3"); Assert.True(Utility.areClose(expected, color.b, 1e-3f), $"TestPathTracer failed - Assert i={i}, 3/3"); } }
public void ONBRandomTestingVec() { PCG pcg = new PCG(); for (int i = 0; i < 1E5; i++) { Vec n = new Vec(pcg.randomFloat(), pcg.randomFloat(), pcg.randomFloat()).Normalize(); List<Vec> onb = n.createONBfromZ(); Assert.True(onb[2].isClose(n), "ONBRandomTesting Failed! Assert 1"); Assert.True(Utility.areClose(onb[0] * onb[1], 0f), $"{onb[0] * onb[1]} is not close to {0f}!!"); Assert.True(Utility.areClose(onb[1] * onb[2], 0f), $"{onb[1] * onb[2]} is not close to {0f}!!"); Assert.True(Utility.areClose(onb[0] * onb[2], 0f), $"{onb[0] * onb[2]} is not close to {0f}!!"); Assert.True(Utility.areClose(onb[0].getSquaredNorm(),1f), "ONBRandomTesting Failed! Assert 5"); Assert.True(Utility.areClose(onb[1].getSquaredNorm(),1f), "ONBRandomTesting Failed! Assert 6"); Assert.True(Utility.areClose(onb[2].getSquaredNorm(),1f), "ONBRandomTesting Failed! Assert 7"); } }