Exemplo n.º 1
0
        public void SampleCornerCases_ShouldBeFinite()
        {
            float ax   = 0.5f;
            float ay   = 0.3f;
            var   dist = new TrowbridgeReitzDistribution()
            {
                AlphaX = ax, AlphaY = ay
            };

            var dir1 = dist.Sample(Vector3.UnitZ, new(0, 1));
            var dir2 = dist.Sample(new(MathF.Sqrt(2), 0, MathF.Sqrt(2)), new(1, 0));
            var dir3 = dist.Sample(Vector3.UnitZ, new(1, 0));

            Assert.True(float.IsFinite(dir1.X));
            Assert.True(float.IsFinite(dir1.Y));
            Assert.True(float.IsFinite(dir1.Z));

            Assert.True(float.IsFinite(dir2.X));
            Assert.True(float.IsFinite(dir2.Y));
            Assert.True(float.IsFinite(dir2.Z));

            Assert.True(float.IsFinite(dir3.X));
            Assert.True(float.IsFinite(dir3.Y));
            Assert.True(float.IsFinite(dir3.Z));
        }
Exemplo n.º 2
0
        public Vector3?Sample(Vector3 outDir, bool isOnLightSubpath, Vector2 primarySample)
        {
            if (outDir.Z == 0)
            {
                return(null);
            }

            Vector3 wh = distribution.Sample(outDir, primarySample);

            if (Vector3.Dot(outDir, wh) < 0)
            {
                return(null);
            }

            float eta   = ShadingSpace.CosTheta(outDir) > 0 ? (outsideIOR / insideIOR) : (insideIOR / outsideIOR);
            var   inDir = ShadingSpace.Refract(outDir, wh, eta);

            return(inDir);
        }
Exemplo n.º 3
0
        public Vector3?Sample(Vector3 outDir, bool isOnLightSubpath, Vector2 primarySample)
        {
            if (outDir.Z == 0)
            {
                return(null);
            }

            var halfVector = distribution.Sample(outDir, primarySample);

            if (Vector3.Dot(halfVector, outDir) < 0)
            {
                return(null);
            }

            var inDir = ShadingSpace.Reflect(outDir, halfVector);

            if (!ShadingSpace.SameHemisphere(outDir, inDir))
            {
                return(null);
            }

            return(inDir);
        }