Initial commit: business card raytracer with explanation

Preserves Andrew Kensler's original card.cc verbatim and adds:
- CMakeLists.txt building both the original and a de-obfuscated
  variant (card_explained.cc) that produces a visually identical render
- A heavily annotated rewrite explaining the vector ops, ray-sphere
  intersection, soft shadows, depth of field, and reflection recursion
- Rendered sample output (docs/aek.png) embedded in the README
- CLAUDE.md establishing the "never modify card.cc" rule for future work
This commit is contained in:
Ole-Morten Duesund 2026-05-28 13:47:50 +02:00
commit f8b7ff475c
7 changed files with 451 additions and 0 deletions

43
CMakeLists.txt Normal file
View file

@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.16)
project(card_raytracer CXX)
# The original card.cc is sacred and must NOT be modified. We compile it
# verbatim. Because the file is golfed C++ from the early 2010s, we relax
# a few things so a modern compiler accepts it untouched:
# - C++14 (default constructor v(){} is fine; pow(float,int) overload exists)
# - -w silences the unavoidable warnings (implicit float->int conversions
# in the final printf, narrowing, unused result of operator new, etc.)
# We can't fix them — we'd have to edit card.cc, which we won't.
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(card card.cc)
add_executable(card_explained card_explained.cc)
# Per-compiler flags. The original is golfed and triggers warnings we can't
# fix without editing it (forbidden). The de-obfuscated version keeps full
# warnings on so it stays honest.
if(MSVC)
target_compile_options(card PRIVATE /w /O2)
target_compile_options(card_explained PRIVATE /W4 /O2)
else()
target_compile_options(card PRIVATE -w -O3)
target_compile_options(card_explained PRIVATE -Wall -Wextra -O3)
endif()
# Convenience targets: render an image from each binary.
# Run with: cmake --build build --target image
add_custom_target(image
COMMAND card > aek.ppm
DEPENDS card
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Rendering aek.ppm from the original card (512x512 @ 64 spp)"
)
add_custom_target(image_explained
COMMAND card_explained > aek_explained.ppm
DEPENDS card_explained
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Rendering aek_explained.ppm from the de-obfuscated card"
)