Esempio n. 1
0
def test05_specular_reflection(variant_scalar_rgb):
    from mitsuba.core import Matrix4f
    from mitsuba.render.mueller import specular_reflection
    import numpy as np

    # Identity matrix (and no phase shift) at perpendicular incidence
    assert ek.allclose(specular_reflection(1, 1.5),   Matrix4f.identity()*0.04)
    assert ek.allclose(specular_reflection(1, 1/1.5), Matrix4f.identity()*0.04)

    # 180 deg phase shift at grazing incidence
    assert ek.allclose(specular_reflection(0, 1.5),   [[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,-1]], atol=1e-6)
    assert ek.allclose(specular_reflection(0, 1/1.5), [[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,-1]], atol=1e-6)

    # Perfect linear polarization at Brewster's angle
    M = np.zeros((4, 4))
    M[0:2, 0:2] = 0.0739645
    assert ek.allclose(specular_reflection(ek.cos(ek.atan(1/1.5)), 1/1.5), M, atol=1e-6)
    assert ek.allclose(specular_reflection(ek.cos(ek.atan(1.5)), 1.5), M, atol=1e-6)

    # 180 deg phase shift just below Brewster's angle (air -> glass)
    M = specular_reflection(ek.cos(ek.atan(1.5)+1e-4), 1.5)
    assert M[0, 0] > 0 and M[1, 1] > 0 and M[2, 2] < 0 and M[3, 3] < 0
    M = specular_reflection(ek.cos(ek.atan(1/1.5)+1e-4), 1/1.5)
    assert M[0, 0] > 0 and M[1, 1] > 0 and M[2, 2] < 0 and M[3, 3] < 0

    # Complex phase shift in the total internal reflection case
    eta = 1/1.5
    cos_theta_min = ek.sqrt((1 - eta**2) / (1 + eta**2))
    M = specular_reflection(cos_theta_min, eta).numpy()
    assert np.all(M[0:2, 2:4] == 0) and np.all(M[2:4, 0:2] == 0) and ek.allclose(M[0:2, 0:2], np.eye(2), atol=1e-6)
    phi_delta = 4*ek.atan(eta)
    assert ek.allclose(M[2:4, 2:4], [[ek.cos(phi_delta), ek.sin(phi_delta)], [-ek.sin(phi_delta), ek.cos(phi_delta)]])
Esempio n. 2
0
def test31_atan(m):
    x = ek.linspace(m.Float, -.8, .8, 10)
    ek.enable_grad(x)
    y = ek.atan(x * x)
    ek.backward(y)
    atan_x = ek.atan(ek.sqr(ek.detach(x)))
    assert ek.allclose(y, atan_x)
    assert ek.allclose(
        ek.grad(x),
        m.Float(-1.13507, -1.08223, -0.855508, -0.53065, -0.177767, 0.177767,
                0.53065, 0.855508, 1.08223, 1.13507))
Esempio n. 3
0
def test09_trig():
    for i in range(-5, 5):
        for j in range(-5, 5):
            a = ek.sin(C(i, j))
            b = C(cmath.sin(complex(i, j)))
            assert ek.allclose(a, b)

            a = ek.cos(C(i, j))
            b = C(cmath.cos(complex(i, j)))
            assert ek.allclose(a, b)

            sa, ca = ek.sincos(C(i, j))
            sb = C(cmath.sin(complex(i, j)))
            cb = C(cmath.cos(complex(i, j)))
            assert ek.allclose(sa, sb)
            assert ek.allclose(ca, cb)

            # Python appears to handle the branch cuts
            # differently from Enoki, C, and Mathematica..
            a = ek.asin(C(i, j + 0.1))
            b = C(cmath.asin(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            a = ek.acos(C(i, j + 0.1))
            b = C(cmath.acos(complex(i, j + 0.1)))
            assert ek.allclose(a, b)

            if abs(j) != 1 or i != 0:
                a = ek.atan(C(i, j))
                b = C(cmath.atan(complex(i, j)))
                assert ek.allclose(a, b, atol=1e-7)
Esempio n. 4
0
def atan_(a0):
    if not a0.IsFloat:
        raise Exception("atan(): requires floating point operands!")
    ar, sr = _check1(a0)
    if not a0.IsSpecial:
        for i in range(sr):
            ar[i] = _ek.atan(a0[i])
    elif a0.IsSpecial:
        im = type(a0)(0, 1)
        tmp = _ek.log((im - a0) / (im + a0))
        return type(a0)(tmp.imag * .5, -tmp.real * 0.5)
    else:
        raise Exception("atan(): unsupported array type!")
    return ar
Esempio n. 5
0
def test06_specular_transmission(variant_scalar_rgb):
    from mitsuba.core import Matrix4f
    from mitsuba.render.mueller import specular_transmission

    assert ek.allclose(specular_transmission(1, 1.5), Matrix4f.identity() * 0.96, atol=1e-5)
    assert ek.allclose(specular_transmission(1, 1/1.5), Matrix4f.identity() * 0.96, atol=1e-5)
    assert ek.allclose(specular_transmission(1e-7, 1.5), Matrix4f.zero(), atol=1e-5)
    assert ek.allclose(specular_transmission(1e-7, 1/1.5), Matrix4f.zero(), atol=1e-5)
    assert ek.allclose(specular_transmission(0, 1.5), Matrix4f.zero(), atol=1e-5)
    assert ek.allclose(specular_transmission(0, 1/1.5), Matrix4f.zero(), atol=1e-5)

    ref = ek.scalar.Matrix4f([[ 0.9260355 , -0.07396451,  0.        ,  0.        ],
                              [-0.07396451,  0.9260355 ,  0.        ,  0.        ],
                              [ 0.        ,  0.        ,  0.92307705,  0.        ],
                              [ 0.        ,  0.        ,  0.        ,  0.92307705]])
    assert ek.allclose(specular_transmission(ek.cos(ek.atan(1/1.5)), 1/1.5), ref)
def test05_phase(variant_scalar_rgb):
    from mitsuba.render import fresnel_polarized

    # 180 deg phase shift for perpendicularly arriving light (air -> glass)
    a_s, a_p, _, _, _ = fresnel_polarized(1, 1.5)
    assert ek.real(a_s) < 0 and ek.real(a_p) < 0 and ek.imag(
        a_s) == 0 and ek.imag(a_p) == 0

    # 180 deg phase shift only for s-polarized light below brewster's angle (air -> glass)
    a_s, a_p, _, _, _ = fresnel_polarized(.1, 1.5)
    assert ek.real(a_s) < 0 and ek.real(a_p) > 0 and ek.imag(
        a_s) == 0 and ek.imag(a_p) == 0

    # No phase shift for perpendicularly arriving light (glass -> air)
    a_s, a_p, _, _, _ = fresnel_polarized(1, 1 / 1.5)
    assert ek.real(a_s) > 0 and ek.real(a_p) > 0 and ek.imag(
        a_s) == 0 and ek.imag(a_p) == 0

    # 180 deg phase shift only for s-polarized light below brewster's angle (glass -> air)
    b = ek.atan(1 / 1.5)
    a_s, a_p, _, _, _ = fresnel_polarized(ek.cos(b + 0.01), 1 / 1.5)
    assert ek.real(a_s) > 0 and ek.real(a_p) < 0 and ek.imag(
        a_s) == 0 and ek.imag(a_p) == 0
def test06_phase_tir(variant_scalar_rgb):
    import numpy as np
    from mitsuba.render import fresnel_polarized

    eta = 1 / 1.5
    # Check phase shift at critical angle (total internal reflection case)
    crit = ek.asin(eta)
    a_s, a_p, _, _, _ = fresnel_polarized(ek.cos(crit), eta)

    assert ek.allclose(ek.arg(a_s), 0.0)
    assert ek.allclose(ek.arg(a_p), ek.pi) or ek.allclose(ek.arg(a_p), -ek.pi)

    # Check phase shift at grazing angle (total internal reflection case)
    a_s, a_p, _, _, _ = fresnel_polarized(0.0, eta)

    assert ek.allclose(ek.arg(a_s), ek.pi) or ek.allclose(ek.arg(a_s), -ek.pi)
    assert ek.allclose(ek.arg(a_p), 0.0)

    # Location of minimum phase difference
    cos_theta_min = ek.sqrt((1 - eta**2) / (1 + eta**2))
    phi_delta = 4 * ek.atan(eta)
    a_s, a_p, _, _, _ = fresnel_polarized(cos_theta_min, eta)
    assert ek.allclose(ek.arg(a_s) - ek.arg(a_p), phi_delta)