An implementation of Ray Tracing in One Weekend using Taichi

Overview

又一个Taichi语言的Ray Tracer

背景简介

这个Ray Tracer基本上是照搬了Peter Shirley的第一本小书Ray Tracing in One Weekend,在我写的时候参考的是Version 3.2.3这个版本。应该比其他中文博客删改了不少内容。果然Peter Shirley不是标题党,我在国庆期间用了2号、3号两天就写完了。期间还参考了moranzcw大佬一年前的左右 (主要是抄了几个物体的定义)及其帖子下其他人的代码,在此表示感谢。

Taichi语言依附于Python,而我自己本身对Python不是那么的熟悉,更不用提Taichi了。Taichi语言的开发者带简化很多快速数值计算及并行开发的操作,但同时也增添了很多限制(比如我不知道class如何复制导致hit_record无法实现)。再加上python对OOP编程的不完全支持,我写的程序很不优雅,同时也没做足优化。

开发环境:Surface Book 2(15inch)上,使用Python 3.7.8+Taichi v0.8.1

这次写的ray tracer算是运用了太极图形课前两节除了元编程的其他所有内容,把该封装的都封装起来了。

原来以为是个小程序,所以写在了一个文件里,后来也懒得改了

与原书不同的是优化了random_in_unit_sphere()这个用来生成在单位球内随机一点的函数,在我的电脑上跑时(18fps+)与moranzcw大佬的程序(9fps+)相比大概能快一倍。(估计拥有更高配置显卡的大佬们能跑到实时吧)为此特地写了另一个程序来不同随机函数的可视化分布,顺便尝鲜了一下GGUI。

之后加入了一些键鼠操作和录制功能

除此之外还生成了一张书的封面图。不知道为什么原书中22*22个小球不能在我的电脑上生成,经过漫长的等待后,等我的只有被占用了11/15.9GB的内存,和因为使用虚拟内存而跑的飞快的硬盘,当然最后还是闪退了。

成功效果展示

封面图(有小球卡在大球里了 😂 )

Cover

Cornell Box的效果

Cornell Box 1 Cornell Box 2

来个动图
Cornell Box Gif

这是使用错误的随机函数导致的效果

Wrong Cornell Box Gif

使用方法

点击窗口来切换视点
j,k键调整水平视角
s键截图
r键开启/终止录制

整体结构

-LICENSE
-|ouput             如果开始录制的话,视频和动图会储存在这儿
-|img               示例图片
-README.MD
-raytracing.py      本体,生成一个Cornell Box
-dots_on_sphere.py  对随机化程序的可视化

运行方式

应该都安装好taichi了吧

python3 raytracing.py

还存在的问题

  • 如何优雅的ODOP编程,解决类的复制与传递
  • ti.random() 如何设置随机种子
  • 如何声明@ti.kernel中最外层循环串行
  • 如何手动释放内存

TODO(就写写,不一定会码)

  • 渲染一张封面图
  • 增加显式光源,渲染一个Cornell Box
  • 添加其他一些模型
  • 添加材质,贴图
  • 加入BVH
  • 加入三维模型.obj的读取与渲染,渲染一只Standford Rabbit
  • 增加键鼠交互
  • 跟进下一本书的内容
  • 在学习了之后的课程后,使用更多Taichi的特性
Owner
张皓
张皓
Very Simple 2 Message Spammer!

Very Simple 2 Message Spammer!

Syntax. 4 Dec 06, 2022
Student Enrollment Analysis System

SEAS Student Enrollment Analysis System Steps to start working: create a user name "seas", host name: local, password: seas, mark all checkbox - go C

Md. Zakaria Kabir 3 Jul 12, 2022
Learn the basics of Python. These tutorials are for Python beginners. so even if you have no prior knowledge of Python, you won’t face any difficulty understanding these tutorials.

01_Python_Introduction Introduction 👋 Python is a modern, robust, high level programming language. It is very easy to pick up even if you are complet

Milaan Parmar / Милан пармар / _米兰 帕尔马 245 Dec 30, 2022
Fly DCS without a joystick

Intro Usage Delete all mouse view axis Install DCSEasyControlExports to your "Saved Games/DCS/" Path python DCSEasyControl/main.py Set DCS to F12 view

XuHao 36 Dec 27, 2022
Reference python implementation of Chia pool operations for pool operators

This repository provides a sample server written in python, which is meant to server as a basis for a Chia Pool. While this is a fully functional implementation, it requires some work in scalability

Chia Network 451 Dec 13, 2022
Wrappers around the most common maya.cmds and maya.api use cases

Maya FunctionSet (maya_fn) A package that decompose core maya.cmds and maya.api features to a set of simple functions. Tests The recommended approach

Ryan Porter 9 Mar 12, 2022
Socorro is the Mozilla crash ingestion pipeline. It accepts and processes Breakpad-style crash reports. It provides analysis tools.

Socorro Socorro is a Mozilla-centric ingestion pipeline and analysis tools for crash reports using the Breakpad libraries. Support This is a Mozilla-s

Mozilla Services 552 Dec 19, 2022
Learn Python Regular Expressions step by step from beginner to advanced levels

Python re(gex)? Learn Python Regular Expressions step by step from beginner to advanced levels with hundreds of examples and exercises The book also i

Sundeep Agarwal 1.3k Dec 28, 2022
Wordle Solver

Wordle Solver Installation Install the following onto your computer: Python 3.10.x Download Page Run pip install -r requirements.txt Instructions To r

John Bucknam 1 Feb 15, 2022
Example applications, dashboards, scripts, notebooks, and other utilities built using Polygon.io

Polygon.io Examples Example applications, dashboards, scripts, notebooks, and other utilities built using Polygon.io. Examples Preview Name Type Langu

Tim Paine 4 Jun 01, 2022
A collection of full-stack resources for programmers.

A collection of full-stack resources for programmers.

Charles-Axel Dein 22.3k Dec 30, 2022
Python library for ODE integration via Taylor's method and LLVM

heyoka.py Modern Taylor's method via just-in-time compilation Explore the docs » Report bug · Request feature · Discuss The heyókȟa [...] is a kind of

Francesco Biscani 45 Dec 21, 2022
Versión preliminar análisis general de Covid-19 en Colombia

Covid_Colombia_v09 Versión: Python 3.8.8 1/ La base de datos del Ministerio de Salud (Minsalud Colombia) está en https://www.datos.gov.co/Salud-y-Prot

Julián Gómez 1 Jan 30, 2022
Final Fantasy XIV Auto House Clicker

Final Fantasy XIV Auto House Clicker

KanameS 0 Mar 31, 2022
Subcert is an subdomain enumeration tool, that finds all the subdomains from certificate transparency logs.

Subcert Subcert is a subdomain enumeration tool, that finds all the valid subdomains from certificate transparency logs. Table of contents Setup Demo

A3h1nt 59 Dec 16, 2022
A domonic-like wrapper around selectolax

A domonic-like wrapper around selectolax

byteface 3 Jun 23, 2022
EFB Docker image with efb-telegram-master and efb-wechat-slave

efb-wechat-docker EFB Docker image with efb-telegram-master and efb-wechat-slave Features Container run by non-root user. Support add environment vari

Haukeng 1 Nov 10, 2022
☘️ Projet Voltaire Solver in Python3

☘️ Projet Voltaire Solver in Python3

Bidouffe 8 Dec 02, 2022
This is the repo for Uncertainty Quantification 360 Toolkit.

UQ360 The Uncertainty Quantification 360 (UQ360) toolkit is an open-source Python package that provides a diverse set of algorithms to quantify uncert

International Business Machines 207 Dec 30, 2022
Openfe - Alchemical free energy calculations for the masses

The Open Free Energy library Alchemical free energy calculations for the masses.

33 Dec 22, 2022