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
张皓
张皓
A stupid obfuscation thing

StupidObfuscation A stupid obfuscation thing How it works The obfuscator takes a string, splits into pieces of one, then, using the table from letter.

Echo 2 May 03, 2022
pythonOS: An operating system kernel made in python and assembly

pythonOS An operating system kernel made in python and assembly Wait what? It uses a custom compiler called snek that implements a part of python3.9 (

Abbix 69 Dec 23, 2022
For when you really need to rank things

Comparisonator For when you really need to rank things. Do you know that feeling when there's this urge deep within you that tells you to compare thin

Maciej Wilczyński 1 Nov 01, 2021
Agora-token-helper - Some help tools for AgoraToken

Agora Token Helper Support AgoraToken version 001 - 006. But for security reason

NUM Alert - A work focus aid created for the Hack the Job hackathon

Contributors: Uladzislau Kaparykha, Amanda Hahn, Nicholas Waller Hackathon Team Name: N.U.M General Purpose: The general purpose of this program is to

Amanda Hahn 1 Jan 10, 2022
A PowSyBl and Python integration based on GraalVM native image

PyPowSyBl The PyPowSyBl project gives access PowSyBl Java framework to Python developers. This Python integration relies on GraalVM to compile Java co

powsybl 23 Dec 14, 2022
To check my COVID-19 vaccine appointment, I wrote an infinite loop that sends me a Whatsapp message hourly using Twilio and Selenium. It works on my Raspberry Pi computer.

COVID-19_vaccine_appointment To check my COVID-19 vaccine appointment, I wrote an infinite loop that sends me a Whatsapp message hourly using Twilio a

Ayyuce Demirbas 24 Dec 17, 2022
Apilytics for Python - Easy API analytics for Python backends

apilytics-python Installation Sign up and get your API key from https://apilytics.io - we offer a completely free trial with no credit card required!

Apilytics 6 Sep 29, 2022
Projeto de análise de dados com SQL

Project-Analizyng-International-Debt-Statistics- Projeto de análise de dados com SQL - Plataforma Data Camp Descrição do Projeto : Não é que nós human

Lorrayne Silva 1 Feb 01, 2022
Yet another Airflow plugin using CLI command as RESTful api, supports Airflow v2.X.

中文版文档 Airflow Extended API Plugin Airflow Extended API, which export airflow CLI command as REST-ful API to extend the ability of airflow official API

Eric Cao 106 Nov 09, 2022
A series of basic programs written in Python

Primeros programas en Python Una serie de programas básicos escritos en Python

Madirex 1 Feb 15, 2022
Generating rent availability info from Effort rent

Rent-info Generating rent availability info from Effort rent Pre-Installation Latest version of python Pip module json, os, requests, datetime, time i

Laixuan 1 Oct 20, 2021
An osu! cheat made in c++ rewritten in python and currently undetected.

megumi-python An osu! cheat made in c++ rewritten in python and currently undetected. Installation Guide Download python 3.9 from https://python.org C

Elaina 2 Nov 18, 2022
Download and process GOES-16 and GOES-17 data from NOAA's archive on AWS using Python.

Download and display GOES-East and GOES-West data GOES-East and GOES-West satellite data are made available on Amazon Web Services through NOAA's Big

Brian Blaylock 88 Dec 16, 2022
Convert Photoshop curves (acv) to xmp presets for Lightroom

acv2xmp Convert Photoshop curves (acv) to Lightroom preset (xmp) acv2xmp.py Basic command prompt that relies on standard library only and can be used

5 Feb 06, 2022
An awesome script to convert the University Of Oviedo web calendar to Google or Outlook calendars.

autoUniCalendar Un script en Python para convertir el calendario de la intranet de la Universidad de Oviedo en un calendario de Outlook o Google Calen

Bimo99B9 14 Sep 28, 2022
A website to collect vintage 4 tracks cassette recorders.

Vintage 4tk cassette recorders A website to collect vintage 4 tracks cassette recorders. Local development setup Copy and customize Django settings (e

1 May 01, 2022
the classic version Of torrentleechx #Unmaintained #Archived

TorrentleechX-Classic Old Modified Version Repo #Unmaintained #Archived for support join here working example group Leech Here For Any Issues/Imroveme

XcodersHub 18 Jan 30, 2022
PBN Obfuscator: A overpowered obfuscator for python, which will help you protect your source code

PBN Obfuscator PBN Obfuscator is a overpowered obfuscator for python, which will

Karim 6 Dec 22, 2022
An-7 tool for python

***An-7 tool - Anonime-X Team*** An-x Menu : SPAM Android web malware interpreter Spam Tools : scampages letters mailers smtpcrack wpbrute shell Andro

Hamza Anonime 8 Nov 18, 2021