A simple GPU-accelerated ray tracing renderer for OBJ mesh models, built with CUDA and C++.
This project is centered in the RayTracer folder and loads .obj geometry with optional .mtl materials and textures. It compiles main.cu with nvcc, renders a scene on an NVIDIA GPU, and outputs the final image as image.ppm.
RayTracer/render_obj.bat- helper script to compile and run the tracer.models/- mesh assets and materials.src/- ray tracer source files, includingmain.cuand supporting headers.
- Windows 10 or 11
- NVIDIA GPU with CUDA support
- CUDA Toolkit installed (includes
nvcc) - Microsoft Visual Studio Build Tools or full Visual Studio with C++ workload
nvccand the Visual Studio x64 build environment available to the script
Note:
render_obj.batcurrently calls Visual Studio 2022 Build Tools at:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.batUpdate this path if your Visual Studio installation differs.
- Open a PowerShell terminal.
- Change directory to the ray tracer folder:
cd "C:\Users\lukej\OneDrive\Documentos\Senior_Capstone\Capstone\RayTracer"- Confirm that
nvccis available and the CUDA Toolkit is installed. - Make sure the Visual Studio x64 environment path in
render_obj.batmatches your installed toolchain.
.
render_obj.bat "models\car\" 1920 1080 50 0 0 100This will:
- compile
RayTracer\src\main.cuintomain.exe - run the ray tracer on the first
.objinsidemodels\car\ - create
image.ppminRayTracer\src
If you prefer to compile manually:
cd "RayTracer\src"
nvcc main.cu -o main.exe
main.exe "..\models\car\Car.obj" 1280 720 25 0 0 80The executable accepts the OBJ path followed by optional rendering and camera parameters.
main.exe <obj_path_or_directory> [width height samples] [azimuth elevation] [radius]
<obj_path_or_directory>- path to a.objfile or a directory containing a.objwidth- output image width in pixels (default:480)height- output image height in pixels (default:360)samples- samples per pixel for anti-aliasing (default:1)azimuth/elevation- camera rotation angles in degrees (0–360)radius- optional camera distance override from the mesh
Render using a directory containing an OBJ file:
.
render_obj.bat "models\car\"Render with custom resolution and samples:
.
render_obj.bat "models\car\" 1280 720 32Render with explicit spherical camera angles:
.
render_obj.bat "models\car\" 1920 1080 50 180 30 130- Output file:
RayTracer\src\image.ppm - Format: plain PPM (
P3)
- Rendering high resolutions or many samples can be slow.
- If the script fails to locate
vcvarsall.bat, update the path inrender_obj.bat. - If
render_obj.batcannot find a.obj, ensure the provided input path exists and contains at least one.objfile.
nvccnot found: verify CUDA Toolkit installation and add it to your PATH.vcvarsall.batpath invalid: update the hard-coded Visual Studio path inrender_obj.bat.- No output image: confirm the program completed successfully and that
image.ppmwas saved inRayTracer\src.
- For those interested, in
Math_Capstone\you can find my math capstone research of the rendering equation and Monte Carlo integration - There you can find the PDF of my final paper
Capstone_paper.pdf, as well as the latex source code inMath_Capstone/src