Exemplo n.º 1
0
def microfacetNoExpFourierSeries(mu_o, mu_i, etaC, alpha, n, phiMax):
    # const
    nEvals = 200
    eps = 10e-4

    def foo(a):
        return microfacetNoExp(mu_o, mu_i, etaC, alpha, a)

    reflect = - mu_o * mu_i > 0.0
    sinMu2 = f.safe_sqrt((1.0 - mu_i * mu_i) * (1.0 - mu_o * mu_o))
    phiCritical = 0.0
    conductor = etaC.imag != 0.0

    if -mu_i > 0.0 or conductor:
        eta = etaC
    else:
        eta = complex(1.0, 0.0) / etaC

    if reflect:
        if not conductor:
            if sinMu2 == 0:
                temp = -1.0
            else:
                temp = (2.0 * eta.real * eta.real - mu_i * mu_o - 1.0) / sinMu2
            phiCritical = f.safe_acos(temp)
    elif not reflect:
        if eta.real > 1.0:
            etaDenser = eta.real
        else:
            etaDenser = 1.0 / eta.real
        if sinMu2 == 0:
            temp = -1.0
        else:
            temp = (1.0 - etaDenser * mu_i * mu_o) / (etaDenser * sinMu2)
        phiCritical = f.safe_acos(temp)

    if reflect:
        if phiCritical > eps and phiCritical < phiMax - eps:

            b1 = filonIntegrate(foo, n, nEvals, 0.0, phiCritical)
            b2 = filonIntegrate(foo, n, nEvals, phiCritical, phiMax)
            b = np.concatenate((b1, b2), axis=0)
        else:
            b = filonIntegrate(foo, n, nEvals, 0.0, phiMax)
    else:
        b = filonIntegrate(foo, n, nEvals, 0.0, min(phiCritical, phiMax))

    # ToDo: if (phiMax < math::Pi - math::Epsilon) SVD stuff
    return b
Exemplo n.º 2
0
y2  = np.zeros(n)
mu_i = -0.6
mu_o = 0.5
alpha = 0.05
eta = 1.5

for i in range(n):
    curPhi = phi[i]
    etaC = complex(eta, 0)
    y[i] = microfacetNoExp(mu_o, mu_i, etaC, alpha, curPhi)


def f(a):
    return microfacetNoExp(mu_o, mu_i, etaC, alpha, a)
# compute the fourier approx
b = filonIntegrate(f, nCoeff, nEvals, a, b)

for i in range(n):
    curPhi = phi[i]
    for l in range(nCoeff):
        y2[i] += b[l] * np.cos(float(l) * curPhi)

plt.figure()
plt.plot(phi, y, 'b')
plt.plot(phi, y2, 'r--')
err = np.sum(np.abs(y - y2)) / n
plt.title("Error " + str(err) + " with " + str(nCoeff) + " coefficients")
#plt.show()
plt.savefig("Microfacetgraph.pdf")