inline Spectrum Le(const Vector &direction) const { /* Compute sky light radiance for direction */ Vector d = normalize(m_worldToLuminaire(direction)); if (m_clipBelowHorizon) { /* if sun is below horizon, return black */ if (d.z < 0.0f) return Spectrum(0.0f); } /* make all "zero values" the same */ if (d.z < 0.001f) d = normalize(Vector(d.x, d.y, 0.001f)); const Point2 dSpherical = toSphericalCoordinates(d); const Float theta = dSpherical.x; #ifndef ENFORCE_SINGLE_ZENITH_ANGLE const Float phi = dSpherical.y; #else Float phi; if (fabs(theta) < 1e-5) phi = 0.0f; else phi = dSpherical.y; #endif Spectrum L; getSkySpectralRadiance(theta, phi, L); L *= m_skyScale; return L; }
void test04_sphere() { Properties props("sphere"); Float radius = 2.0f; props.setFloat("radius", radius); props.setPoint("center", Point(0.0f)); ref<Shape> sphere = static_cast<Shape *>(PluginManager::getInstance()->createObject(props)); sphere->configure(); ref<ShapeKDTree> kdtree = new ShapeKDTree(); kdtree->addShape(sphere); kdtree->build(); Ray ray(Point(3, 3, 3), normalize(Vector(-1, -1, -1)), 123.0f); Intersection its; assertTrue(kdtree->rayIntersect(ray, its)); assertEquals(its.time, 123.0f); assertEqualsEpsilon(its.p, Point(ray.d*-2.0f), Epsilon); assertEqualsEpsilon(its.wi, Vector(0, 0, 1), Epsilon); assertEqualsEpsilon(its.shFrame.n, -ray.d, Epsilon); assertTrue(its.shFrame == its.geoFrame); Point2 sc = toSphericalCoordinates(Vector(its.p)); std::swap(sc.x, sc.y); sc.x *= INV_TWOPI; sc.y *= INV_PI; assertEqualsEpsilon(its.uv, sc, Epsilon); // from mathematica assertEqualsEpsilon(its.dpdu, Vector(-3.6276f, 3.6276f, 0.0f)*radius, 1e-4f); assertEqualsEpsilon(its.dpdv, Vector(1.28255f, 1.28255f, -2.5651f)*radius, 1e-4f); Vector dndu, dndv; its.shape->getNormalDerivative(its, dndu, dndv, false); assertEqualsEpsilon(dndu, Vector(-3.6276f, 3.6276f, 0.0f), 1e-4f); assertEqualsEpsilon(dndv, Vector(1.28255f, 1.28255f, -2.5651f), 1e-4f); Float H, K; its.shape->getCurvature(its, H, K); assertEquals(K, 1.0f / (radius*radius)); assertEquals(H, -1.0f / radius); }
/** * Configures the position of the sun by using a vector that points * to the sun. It is expected, that +x = south, +y = east, +z = up. */ void configureSunPosition(const Vector& sunDir) { Vector wh = normalize(sunDir); Point2 sunPos = toSphericalCoordinates(wh); m_thetaS = sunPos.x; m_phiS = sunPos.y; }