package eu.jonahbauer.raytracing.scene;

import eu.jonahbauer.raytracing.math.Ray;
import eu.jonahbauer.raytracing.render.Color;
import org.jetbrains.annotations.NotNull;

@FunctionalInterface
public interface SkyBox {
    @NotNull Color getColor(@NotNull Ray ray);

    static @NotNull SkyBox gradient(@NotNull Color top, @NotNull Color bottom) {
        return ray -> {
            // altitude from -pi/2 to pi/2
            var alt = Math.copySign(
                    Math.acos(ray.direction().withY(0).unit().times(ray.direction().unit())),
                    ray.direction().y()
            );
            return Color.lerp(bottom, top, alt / Math.PI + 0.5);
        };
    }

    static @NotNull SkyBox solid(@NotNull Color color) {
        return _ -> color;
    }
}
