|
| 1 | +# Progressive SDL Rendering Feature |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This branch adds an interactive SDL2-based progressive rendering mode to the raytracer. This feature allows you to see your render in real-time as it progressively improves in quality through multiple sample stages. |
| 6 | + |
| 7 | +## What is Progressive Rendering? |
| 8 | + |
| 9 | +Progressive rendering displays the image while it's being rendered, starting with low quality (few samples per pixel) and gradually increasing quality. This allows you to: |
| 10 | + |
| 11 | +- **Preview quickly**: See your scene in seconds with low sample counts |
| 12 | +- **Stop early**: If the preview looks wrong, you can stop and adjust parameters |
| 13 | +- **Watch progress**: See the image quality improve in real-time |
| 14 | +- **Interactive experience**: Get visual feedback during the rendering process |
| 15 | + |
| 16 | +## Features |
| 17 | + |
| 18 | +### Sample Stages |
| 19 | + |
| 20 | +The progressive rendering goes through multiple quality stages: |
| 21 | +- **Stage 1**: 1 sample per pixel (very fast, noisy preview) |
| 22 | +- **Stage 2**: 4 samples per pixel (quick preview with less noise) |
| 23 | +- **Stage 3**: 16 samples per pixel (decent quality) |
| 24 | +- **Stage 4**: 64 samples per pixel (good quality) |
| 25 | +- **Stage 5**: 256 samples per pixel (high quality) |
| 26 | +- **Stage 6**: 1024 samples per pixel (final quality) |
| 27 | + |
| 28 | +Each stage is displayed immediately in the SDL window, so you can see the quality progression. |
| 29 | + |
| 30 | +### Interactive Controls |
| 31 | + |
| 32 | +- **ESC key**: Stop rendering at the current quality level |
| 33 | +- **Close window**: Stop rendering at the current quality level |
| 34 | +- **Wait**: Let it complete all stages for the highest quality |
| 35 | +- **After completion**: Press any key or close window to save and continue |
| 36 | + |
| 37 | +## How to Use |
| 38 | + |
| 39 | +### Prerequisites |
| 40 | + |
| 41 | +Make sure SDL2 is installed on your system: |
| 42 | + |
| 43 | +```bash |
| 44 | +# Ubuntu/Debian |
| 45 | +sudo apt-get install libsdl2-dev |
| 46 | + |
| 47 | +# macOS |
| 48 | +brew install sdl2 |
| 49 | + |
| 50 | +# Windows |
| 51 | +# Download from https://www.libsdl.org/download-2.0.php |
| 52 | +``` |
| 53 | + |
| 54 | +### Building |
| 55 | + |
| 56 | +The feature is automatically compiled if SDL2 is detected: |
| 57 | + |
| 58 | +```bash |
| 59 | +cd build |
| 60 | +cmake .. --fresh |
| 61 | +make -j12 |
| 62 | +``` |
| 63 | + |
| 64 | +If SDL2 is found, you'll see: |
| 65 | +``` |
| 66 | +-- SDL2 found and linked for real-time display |
| 67 | +``` |
| 68 | + |
| 69 | +### Running |
| 70 | + |
| 71 | +When you run the raytracer, you'll see a new rendering option: |
| 72 | + |
| 73 | +```bash |
| 74 | +./302_raytracer -r 1080 -s 1024 |
| 75 | +``` |
| 76 | + |
| 77 | +The menu will show: |
| 78 | +``` |
| 79 | +Choose rendering method: |
| 80 | + 0. CPU sequential |
| 81 | + 1. CPU parallel |
| 82 | + 2. CUDA GPU (default) |
| 83 | + 3. CUDA GPU with progressive SDL display |
| 84 | +Enter choice (0, 1, 2, or 3): |
| 85 | +``` |
| 86 | + |
| 87 | +Select option **3** for progressive SDL rendering. |
| 88 | + |
| 89 | +### Example Usage |
| 90 | + |
| 91 | +```bash |
| 92 | +# Progressive render at 1080p |
| 93 | +echo 3 | ./302_raytracer -r 1080 |
| 94 | + |
| 95 | +# Progressive render at 4K |
| 96 | +echo 3 | ./302_raytracer -r 2160 |
| 97 | + |
| 98 | +# Progressive render at 720p with custom samples |
| 99 | +echo 3 | ./302_raytracer -r 720 -s 512 |
| 100 | +``` |
| 101 | + |
| 102 | +## Technical Details |
| 103 | + |
| 104 | +### Implementation |
| 105 | + |
| 106 | +The progressive rendering feature is implemented in `camera.h`: |
| 107 | +- **Method**: `renderPixelsSDLProgressive()` |
| 108 | +- **Conditional compilation**: Only available when `SDL2_FOUND` is defined |
| 109 | +- **Backend**: Uses CUDA for each rendering stage (fast GPU rendering) |
| 110 | +- **Display**: Updates SDL texture after each stage completion |
| 111 | + |
| 112 | +### Rendering Flow |
| 113 | + |
| 114 | +1. Initialize SDL window, renderer, and texture |
| 115 | +2. For each sample stage: |
| 116 | + - Render with CUDA at current sample count |
| 117 | + - Update SDL texture with the new image data |
| 118 | + - Display in the window |
| 119 | + - Check for user interruption (ESC or window close) |
| 120 | +3. Wait for user to acknowledge completion |
| 121 | +4. Clean up SDL resources |
| 122 | +5. Return final image for saving |
| 123 | + |
| 124 | +### Customization |
| 125 | + |
| 126 | +You can customize the sample stages in `main.cc`: |
| 127 | + |
| 128 | +```cpp |
| 129 | +// Default stages |
| 130 | +c.renderPixelsSDLProgressive(localImage, {1, 4, 16, 64, 256, 1024}); |
| 131 | + |
| 132 | +// Custom stages - more granular |
| 133 | +c.renderPixelsSDLProgressive(localImage, {1, 2, 4, 8, 16, 32, 64, 128, 256}); |
| 134 | + |
| 135 | +// Quick preview stages |
| 136 | +c.renderPixelsSDLProgressive(localImage, {1, 4, 16}); |
| 137 | +``` |
| 138 | +
|
| 139 | +## Performance Considerations |
| 140 | +
|
| 141 | +- **GPU Required**: Uses CUDA for rendering each stage, so a CUDA-capable GPU is required |
| 142 | +- **Memory**: Keeps one full-resolution image buffer per stage |
| 143 | +- **Display overhead**: Minimal - SDL texture updates are fast |
| 144 | +- **Total time**: Roughly equivalent to rendering with the highest sample count directly |
| 145 | +
|
| 146 | +## Benefits Over Standard Rendering |
| 147 | +
|
| 148 | +1. **Immediate feedback**: See your scene within seconds |
| 149 | +2. **Error detection**: Catch scene setup mistakes early |
| 150 | +3. **Quality control**: Stop when quality is sufficient for your needs |
| 151 | +4. **Visual satisfaction**: Watch the rendering improve in real-time |
| 152 | +5. **Flexibility**: Adjust quality vs. speed tradeoff interactively |
| 153 | +
|
| 154 | +## Troubleshooting |
| 155 | +
|
| 156 | +### SDL2 Not Found |
| 157 | +
|
| 158 | +If option 3 doesn't appear: |
| 159 | +- SDL2 is not installed or not found by CMake |
| 160 | +- Reinstall SDL2 and run `cmake .. --fresh` in the build directory |
| 161 | +
|
| 162 | +### Window Doesn't Appear |
| 163 | +
|
| 164 | +- Check that you're not in a headless environment |
| 165 | +- Verify SDL2 is properly linked: `ldd ./302_raytracer | grep SDL` |
| 166 | +
|
| 167 | +### Slow Performance |
| 168 | +
|
| 169 | +- Progressive rendering uses CUDA, ensure your GPU drivers are up to date |
| 170 | +- Each stage requires a complete render at that sample count |
| 171 | +- For slower GPUs, consider using fewer or lower sample stages |
| 172 | +
|
| 173 | +## Future Enhancements |
| 174 | +
|
| 175 | +Potential improvements for this feature: |
| 176 | +- Adjustable sample stages via command-line arguments |
| 177 | +- Real-time statistics overlay (FPS, rays/sec, current stage) |
| 178 | +- Pause/resume functionality |
| 179 | +- Save intermediate stages |
| 180 | +- Tile-based progressive rendering for huge resolutions |
| 181 | +- Multi-GPU support for faster stage completion |
| 182 | +
|
| 183 | +## Code References |
| 184 | +
|
| 185 | +- **Main implementation**: `src/302_raytracer/camera.h` - `renderPixelsSDLProgressive()` |
| 186 | +- **Menu integration**: `src/302_raytracer/main.cc` - rendering method selection |
| 187 | +- **CMake configuration**: `CMakeLists.txt` - SDL2 detection and linking |
| 188 | +- **CUDA backend**: `src/302_raytracer/camera_cuda.cu` - `renderPixelsCUDA()` |
0 commit comments