Post by vorpal on Dec 9, 2018 0:28:49 GMT
Has anyone had any luck with UV mapping for checkerboard patterns? I have the following:
And then, later on:
But all I'm getting are alternating lines of longitude and no latitudinal differences. Anyone manage to make UV mapping work? If so, could you share your pseudocode?
Camera camera{400, 400, math_constants::pi<> / 10,
view_transform(make_point(0, 0, 0), make_point(0, 0, 1), predefined_tuples::y1)};
PointLight light{make_point(0, 10, -10), predefined_colours::white};
// Ball 1 material
auto ball1_pattern = std::make_shared<CheckerPattern>(make_colour(0.3, 1.0, 0.3),
make_colour(1.0, 1.0, 0.3));
ball1_pattern->setTransformation(scale(0.2, 0.2, 0.2));
auto ball1_material = std::make_shared<Material>(ball1_pattern);
auto ball1 = Sphere::createSphere();
ball1->setMaterial(ball1_material);
ball1->setTransformation(translation(0, 0, 10));
And then, later on:
const Colour CheckerPattern::colourAtObject(const std::shared_ptr<const shapes::Shape> &shape,
const Tuple &world_point) const noexcept {
const auto sphere = std::dynamic_pointer_cast<const shapes::Sphere>(shape);
const auto object_point = shape->getTransformationInverse() * world_point;
if (sphere != nullptr) {
// TECHNIQUE 1: Point in object space.
// Find d, vector to origin. This should be normal.
const auto d = (object_point - predefined_tuples::zero_point).normalize();
// Calculate u and v in range [0,1] each.
double u = 0.5 + std::atan2(d[tuple_constants::z], d[tuple_constants::x]) / (2 * math_constants::pi<>);
double v = 0.5 - std::asin(tuple_constants::y) / math_constants::pi<>;
// Now migrate to [0,2] x [0,2] and multiply by pattern inverse.
// Ignore the last parameter as it shouldn't matter.
// Problem: there is no latitude: only longitude.
return colourAt(transformationInverse * make_vector(2 * u, 2 * v, 0));
} else {
...
}
But all I'm getting are alternating lines of longitude and no latitudinal differences. Anyone manage to make UV mapping work? If so, could you share your pseudocode?