站内导读
中文 这是计算机图形学课程的配套代码,用256行纯C++实现光线追踪,不依赖第三方库,便于看清渲染流程的每一步。它不追求物理真实或成品级渲染,而是以简洁结构讲解原理,并配有wiki逐章说明。适合想从零理解光线追踪的学生和自学者,也可作为教学示例。
日本語 256行のC++だけで書かれたレイトレーシングの教材用コードです。外部ライブラリを使わず、描画の各処理を追いやすい構成にしており、物理的な正確さや実用品質より理解しやすさを優先しています。付属のwikiで章ごとに解説され、グラフィックスを基礎から学ぶ学生や自習者に向いています。
한국어 256줄의 순수 C++로 작성된 레이 트레이싱 교육용 코드입니다. 외부 라이브러리 없이 렌더링 과정을 단계별로 살펴볼 수 있게 구성했으며, 물리적 사실성이나 실사용 품질보다 이해하기 쉬운 구조를 우선합니다. 위키로 장별 설명을 제공해 컴퓨터 그래픽스를 기초부터 배우려는 학생과 독학자에게 적합합니다.
English A teaching-oriented ray tracer written in 256 lines of plain C++, with no third-party libraries, so each rendering step stays visible. It favors simplicity over physical accuracy or production quality, and the accompanying wiki explains the code chapter by chapter. It suits students and self-learners who want to understand ray tracing from the ground up.
README · 详细文档
来源 · 查看原文
Understandable RayTracing in 256 lines of bare C++
This repository is a support code for my computer graphics lectures. It is not meant to be the ultimate rendering code or even physically realistic. It is meant to be simple. This project is distributed under the DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE.
Check the wiki that accompanies the source code. The second raytracing chapter is available in the tinykaboom repository. If you are looking for a software rasterizer, check the other part of the lectures.
In my lectures I tend to avoid third party libraries as long as it is reasonable, because it forces to understand what is happening under the hood. So, the raytracing 256 lines of plain C++ give us this result: 
compilation
git clone https://github.com/ssloy/tinyraytracer.git
cd tinyraytracer
mkdir build
cd build
cmake ..
make
You can open the project in Gitpod, a free online dev evironment for GitHub:
On open, the editor will compile & run the program as well as open the resulting image in the editor's preview. Just change the code in the editor and rerun the script (use the terminal's history) to see updated images.