Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,13 @@ gen_scene:
@$(CC) -Wall -Wextra -Werror -o gen_scene tools/gen_scene.c -lm
@echo "Built gen_scene tool"

render-cathedral: $(NAME) gen_scene
@scripts/render_cathedral.sh $(ARGS)

testclean:
$(RM) run_test_math run_test_camera run_test_intersections run_test_lighting run_test_parsing run_test_pbr run_benchmark
$(RM) cov_test_math cov_test_intersections cov_test_lighting cov_test_parsing cov_test_all
$(RM) -r coverage
$(RM) *.gcno *.gcda src/*.gcno src/*.gcda tests/*.gcno tests/*.gcda

.PHONY: re all clean fclean sanitize debug release test testclean coverage regression regression-generate lint benchmark gen_scene
.PHONY: re all clean fclean sanitize debug release test testclean coverage regression regression-generate lint benchmark gen_scene render-cathedral
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# miniRT

![Cathedral Ruins](./saves/cathedral_ruins.bmp?raw=true)
![Cathedral Ruins](./renders_preview/cathedral_ruins.png?raw=true)

**A basic RayTracer using minilibX**
project of 42 Paris's common-core
Expand Down
Binary file modified renders_preview/cathedral_ruins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified saves/cathedral_ruins.bmp
Binary file not shown.
Binary file added saves/cathedral_ruins.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion scenes/cathedral_ruins.rt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ R 2560 1440
A 0.08 200,190,170
E

c 0.0,6.0,12.0 0.03,0,0 70
c 0.0,12.0,25.0 0.055,0,0 70
c -4.0,7.0,18.0 0.04,-0.03,0 70
c 8.0,6.0,-15.0 0.03,0.3,0 70
c 0.0,2.0,16.0 0.0,0,0 70

l -3.0,25.0,-5.0 0.9 255,240,200
l 5.0,20.0,5.0 0.6 255,235,190
Expand Down
17 changes: 17 additions & 0 deletions scripts/bmp2png.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python3
"""Convert BMP files to PNG format."""
import sys
from PIL import Image

def convert(src, dst=None):
if dst is None:
dst = src.rsplit('.', 1)[0] + '.png'
img = Image.open(src)
img.save(dst, 'PNG')
print(f"{src} -> {dst} ({img.width}x{img.height})")

if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: bmp2png.py <input.bmp> [output.png]")
sys.exit(1)
convert(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else None)
129 changes: 129 additions & 0 deletions scripts/render_cathedral.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/bin/bash
# Render the cathedral ruins scene
# Generates the .rt file via gen_scene and renders it with miniRT
#
# Usage: scripts/render_cathedral.sh [OPTIONS]
# --preview Quick render at 640x360
# --full Full resolution render (2560x1440)
# --generate-only Create .rt file without rendering
# --png Convert output BMP to PNG (requires Pillow)
# --width N Custom width (default: 1280)
# --height N Custom height (default: 720)
# --threads N Thread count (default: auto)
# --seed N RNG seed for debris placement (default: 42)
# --output PATH Output BMP path (default: saves/cathedral_ruins.bmp)
# --scene PATH Use existing .rt file instead of generating

set -euo pipefail

PROJECT_DIR="$(cd "$(dirname "$0")/.." && pwd)"

WIDTH=1280
HEIGHT=720
THREADS="auto"
SEED=42
OUTPUT="$PROJECT_DIR/saves/cathedral_ruins.bmp"
SCENE_FILE=""
GENERATE_ONLY=0
USE_EXISTING=0
CONVERT_PNG=0

while [ $# -gt 0 ]; do
case "$1" in
--preview)
WIDTH=640; HEIGHT=360 ;;
--full)
WIDTH=2560; HEIGHT=1440 ;;
--generate-only)
GENERATE_ONLY=1 ;;
--png)
CONVERT_PNG=1 ;;
--width)
WIDTH="$2"; shift ;;
--height)
HEIGHT="$2"; shift ;;
--threads)
THREADS="$2"; shift ;;
--seed)
SEED="$2"; shift ;;
--output)
OUTPUT="$2"; shift ;;
--scene)
SCENE_FILE="$2"; USE_EXISTING=1; shift ;;
--help|-h)
head -16 "$0" | tail -14
exit 0 ;;
*)
echo "Unknown option: $1" >&2
exit 1 ;;
esac
shift
done

# Build miniRT if missing
if [ ! -f "$PROJECT_DIR/miniRT" ]; then
echo "Building miniRT..."
make -C "$PROJECT_DIR" -j"$(nproc)" 2>&1 | tail -1
fi

# Build gen_scene if missing
if [ ! -f "$PROJECT_DIR/gen_scene" ]; then
echo "Building gen_scene..."
make -C "$PROJECT_DIR" gen_scene 2>&1
fi

# Generate scene file
if [ "$USE_EXISTING" -eq 0 ]; then
SCENE_FILE="$PROJECT_DIR/scenes/cathedral_ruins_gen.rt"
echo "Generating cathedral scene (${WIDTH}x${HEIGHT}, seed=${SEED})..."
"$PROJECT_DIR/gen_scene" --preset cathedral \
--width "$WIDTH" --height "$HEIGHT" \
--seed "$SEED" \
--output "$SCENE_FILE"
echo "Scene file: $SCENE_FILE"
SHAPE_COUNT=$(grep -c "^[a-z]" "$SCENE_FILE" || true)
echo "Shape/element count: $SHAPE_COUNT"
fi

if [ "$GENERATE_ONLY" -eq 1 ]; then
echo "Done (generate-only mode)."
exit 0
fi

# Render
mkdir -p "$(dirname "$OUTPUT")"
echo ""
echo "Rendering ${WIDTH}x${HEIGHT} with --threads=${THREADS}..."
echo "Output: $OUTPUT"
echo "This may take a while for large resolutions."
echo ""

START=$(date +%s)

cd "$PROJECT_DIR"
xvfb-run -a "$PROJECT_DIR/miniRT" "$SCENE_FILE" -save \
--output "$OUTPUT" --threads="$THREADS" || {
echo "Retrying with default output path..."
xvfb-run -a "$PROJECT_DIR/miniRT" "$SCENE_FILE" -save \
--threads="$THREADS"
mv -f "$PROJECT_DIR/miniRT.bmp" "$OUTPUT"
}

END=$(date +%s)
ELAPSED=$((END - START))
MINUTES=$((ELAPSED / 60))
SECONDS=$((ELAPSED % 60))

echo ""
echo "=== Render Complete ==="
echo "Time: ${MINUTES}m ${SECONDS}s"
ls -lh "$OUTPUT" | awk '{print "Size:", $5}'
file "$OUTPUT" | sed 's/.*: /Format: /'

# Convert to PNG if requested
if [ "$CONVERT_PNG" -eq 1 ]; then
PNG_OUTPUT="${OUTPUT%.bmp}.png"
echo ""
echo "Converting to PNG..."
python3 "$PROJECT_DIR/scripts/bmp2png.py" "$OUTPUT" "$PNG_OUTPUT"
fi
Loading
Loading