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
450 changes: 450 additions & 0 deletions docs/stories/3.1.pure-cook-torrance-brdf-implementation.md

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions simple_test.cpp

This file was deleted.

62 changes: 42 additions & 20 deletions src/core/point_light.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ struct PointLight {
// Calculate direction vector from surface point to light source
// Geometric interpretation: normalized vector pointing from surface toward light
// Usage: needed for BRDF evaluation and n·l calculations
Vector3 sample_direction(const Point3& surface_point) const {
std::cout << "\n=== Point Light Direction Calculation ===" << std::endl;
std::cout << "Light position: (" << position.x << ", " << position.y << ", " << position.z << ")" << std::endl;
std::cout << "Surface point: (" << surface_point.x << ", " << surface_point.y << ", " << surface_point.z << ")" << std::endl;
Vector3 sample_direction(const Point3& surface_point, bool verbose = true) const {
if (verbose) {
std::cout << "\n=== Point Light Direction Calculation ===" << std::endl;
std::cout << "Light position: (" << position.x << ", " << position.y << ", " << position.z << ")" << std::endl;
std::cout << "Surface point: (" << surface_point.x << ", " << surface_point.y << ", " << surface_point.z << ")" << std::endl;
}

// Calculate displacement vector from surface to light
Vector3 displacement = position - surface_point;
std::cout << "Displacement vector: (" << displacement.x << ", " << displacement.y << ", " << displacement.z << ")" << std::endl;
if (verbose) {
std::cout << "Displacement vector: (" << displacement.x << ", " << displacement.y << ", " << displacement.z << ")" << std::endl;
}

// Calculate distance for verification
float distance = displacement.length();
std::cout << "Distance to light: " << distance << std::endl;
if (verbose) {
std::cout << "Distance to light: " << distance << std::endl;
}

// Normalize to get unit direction vector
Vector3 direction = displacement.normalize();
std::cout << "Normalized direction: (" << direction.x << ", " << direction.y << ", " << direction.z << ")" << std::endl;
std::cout << "Direction length verification: " << direction.length() << " (should be ≈ 1.0)" << std::endl;
std::cout << "=== Direction calculation complete ===" << std::endl;
if (verbose) {
std::cout << "Normalized direction: (" << direction.x << ", " << direction.y << ", " << direction.z << ")" << std::endl;
std::cout << "Direction length verification: " << direction.length() << " (should be ≈ 1.0)" << std::endl;
std::cout << "=== Direction calculation complete ===" << std::endl;
}

return direction;
}
Expand All @@ -47,39 +55,53 @@ struct PointLight {
// Physical law: inverse square law - irradiance ∝ 1/distance²
// Mathematical formula: E = (I * color) / (4π * distance²)
// Result: incident radiance for use in rendering equation
Vector3 calculate_irradiance(const Point3& surface_point) const {
std::cout << "\n=== Point Light Irradiance Calculation ===" << std::endl;
std::cout << "Light intensity: " << intensity << std::endl;
std::cout << "Light color: (" << color.x << ", " << color.y << ", " << color.z << ")" << std::endl;
Vector3 calculate_irradiance(const Point3& surface_point, bool verbose = true) const {
if (verbose) {
std::cout << "\n=== Point Light Irradiance Calculation ===" << std::endl;
std::cout << "Light intensity: " << intensity << std::endl;
std::cout << "Light color: (" << color.x << ", " << color.y << ", " << color.z << ")" << std::endl;
}

// Calculate distance from light to surface point
Vector3 displacement = position - surface_point;
float distance = displacement.length();
std::cout << "Distance to surface: " << distance << std::endl;
if (verbose) {
std::cout << "Distance to surface: " << distance << std::endl;
}

// Handle degenerate case: light at surface point
if (distance < 1e-6f) {
std::cout << "WARNING: Light and surface point are coincident - returning zero irradiance" << std::endl;
if (verbose) {
std::cout << "WARNING: Light and surface point are coincident - returning zero irradiance" << std::endl;
}
return Vector3(0, 0, 0);
}

// Apply inverse square law: irradiance ∝ 1/distance²
// Factor of 4π comes from solid angle of complete sphere
float distance_squared = distance * distance;
float falloff_factor = 1.0f / (4.0f * M_PI * distance_squared);
std::cout << "Distance squared: " << distance_squared << std::endl;
std::cout << "Falloff factor (1/4πd²): " << falloff_factor << std::endl;
if (verbose) {
std::cout << "Distance squared: " << distance_squared << std::endl;
std::cout << "Falloff factor (1/4πd²): " << falloff_factor << std::endl;
}

// Calculate final irradiance: intensity * color * falloff
Vector3 irradiance = color * (intensity * falloff_factor);
std::cout << "Final irradiance: (" << irradiance.x << ", " << irradiance.y << ", " << irradiance.z << ")" << std::endl;
if (verbose) {
std::cout << "Final irradiance: (" << irradiance.x << ", " << irradiance.y << ", " << irradiance.z << ")" << std::endl;
}

// Verify irradiance is non-negative
if (irradiance.x < 0 || irradiance.y < 0 || irradiance.z < 0) {
std::cout << "WARNING: Negative irradiance detected - this violates physical laws" << std::endl;
if (verbose) {
std::cout << "WARNING: Negative irradiance detected - this violates physical laws" << std::endl;
}
}

std::cout << "=== Irradiance calculation complete ===" << std::endl;
if (verbose) {
std::cout << "=== Irradiance calculation complete ===" << std::endl;
}
return irradiance;
}

Expand Down
35 changes: 27 additions & 8 deletions src/core/progress_reporter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ProgressReporter {
std::chrono::steady_clock::time_point start_time;
std::chrono::steady_clock::time_point last_update_time;
PerformanceTimer* timer;
bool quiet_mode;

// Progress reporting configuration
int reporting_granularity_percent = 5; // Report every 5%
Expand All @@ -51,18 +52,25 @@ class ProgressReporter {
size_t current_memory_usage = 0;

public:
ProgressReporter(int total_pixels, PerformanceTimer* performance_timer)
ProgressReporter(int total_pixels, PerformanceTimer* performance_timer, bool quiet_mode = false)
: total_pixels(total_pixels), completed_pixels(0), last_reported_percentage(-1),
timer(performance_timer) {
timer(performance_timer), quiet_mode(quiet_mode) {
start_time = std::chrono::steady_clock::now();
last_update_time = start_time;

std::cout << "\n=== Progress Reporting Initialized ===" << std::endl;
std::cout << "Total pixels to render: " << total_pixels << std::endl;
std::cout << "Progress reporting granularity: every " << reporting_granularity_percent << "%" << std::endl;
std::cout << "Minimum reporting interval: " << minimum_reporting_interval_seconds << " seconds" << std::endl;
std::cout << "Educational insights: Performance scaling and ETA calculation enabled" << std::endl;
std::cout << "=== Begin Rendering Progress ===" << std::endl;
// Adjust reporting granularity for quiet mode
if (quiet_mode) {
reporting_granularity_percent = 10; // Report every 10% in quiet mode
}

if (!quiet_mode) {
std::cout << "\n=== Progress Reporting Initialized ===" << std::endl;
std::cout << "Total pixels to render: " << total_pixels << std::endl;
std::cout << "Progress reporting granularity: every " << reporting_granularity_percent << "%" << std::endl;
std::cout << "Minimum reporting interval: " << minimum_reporting_interval_seconds << " seconds" << std::endl;
std::cout << "Educational insights: Performance scaling and ETA calculation enabled" << std::endl;
std::cout << "=== Begin Rendering Progress ===" << std::endl;
}
}

// Update progress with completed pixel count and optional memory usage
Expand Down Expand Up @@ -94,6 +102,17 @@ class ProgressReporter {

// Print detailed progress update with educational insights
void print_progress_update(float progress_percentage, float elapsed_seconds) const {
if (quiet_mode) {
// Simple progress display for quiet mode
std::cout << "Progress: " << static_cast<int>(progress_percentage) << "%";
if (completed_pixels == total_pixels) {
std::cout << " - Complete!" << std::endl;
} else {
std::cout << std::endl;
}
return;
}

std::cout << "\n--- Rendering Progress Update ---" << std::endl;
std::cout << std::fixed << std::setprecision(1);
std::cout << "Progress: " << progress_percentage << "% ("
Expand Down
Loading
Loading