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
张皓
张皓
This repository containing cross-section cut and fill calculations using Python programming language.

cross-section This repository is containing cut and fill calculations for cross-section using Python programming language. This codes is made to calcu

3 Jun 15, 2022
A simple watcher for the XTZ/kUSD pool on Quipuswap

Kolibri Quipuswap Watcher This repo holds the source code for the QuipuBot bot deployed to the #quipuswap-updates channel in the Kolibri Discord Setup

Hover Labs 1 Nov 18, 2021
Online HackerRank problem solving challenges

LinkedListHackerRank Online HackerRank problem solving challenges This challenge is part of a tutorial track by MyCodeSchool You are given the pointer

Sefineh Tesfa 1 Nov 21, 2021
✔️ Create to-do lists to easily manage your ideas and work.

Todo List + Add task + Remove task + List completed task + List not completed task + Set clock task time + View task statistics by date Changelog v 1.

Abbas Ataei 30 Nov 28, 2022
A bot to view Dilbert comics directly from Discord and get updates of the comics automatically.

A bot to view Dilbert comics directly from Discord and get updates of the comics automatically

Raghav Sharma 3 Nov 30, 2022
NewsBlur is a personal news reader bringing people together to talk about the world.

NewsBlur NewsBlur is a personal news reader bringing people together to talk about the world.

Samuel Clay 6.2k Dec 29, 2022
Mixtaper - Web app to make mixtapes

Mixtaper A web app which allows you to input songs in the form of youtube links

suryansh 1 Feb 14, 2022
Open source stenotype engine

Plover Bringing stenography to everyone. Homepage Releases Wiki Blog Google Group Discord Chat About Installation Getting help Contributing Donations

Open Steno Project 2k Jan 09, 2023
A rough GSL work DynSAGE of my graduation project

DynSAGE Codes w.r.t DynSAGE-Diffuse can be found in function apply_dyn_model_v2 of src/utils.py. The training entrance is Line 144 - 155 of src/main.p

Yuhan Wang 3 Mar 22, 2022
A program that analyzes data from inertia measurement units installeed in aircraft and generates g-exceedance curves

A program that analyzes data from inertia measurement units installeed in aircraft and generates g-exceedance curves

Pooya 1 Nov 23, 2021
DOP-Tuning(Domain-Oriented Prefix-tuning model)

DOP-Tuning DOP-Tuning(Domain-Oriented Prefix-tuning model)代码基于Prefix-Tuning改进. Files ├── seq2seq # Code for encoder-decoder arch

Andrew Zeng 5 Nov 02, 2022
Code and yara rules to detect and analyze Cobalt Strike

Cobalt Strike Resources This repository contains: analyze.py: a script to analyze a Cobalt Strike beacon (python analyze.py BEACON) extract.py; extrac

Tek 224 Jan 04, 2023
BDD base project: Python + Behave

BDD base project: Python + Behave Basic example of using Python with Behave (BDD). This Gherkin example includes: Basic Scenario Scenario Outline Tagg

eccanto 1 Dec 08, 2021
CountdownTimer - Countdown Timer For Python

Countdown Timer This python script asks for the user time (input) in seconds, an

Arinzechukwu Okoye 1 Jan 01, 2022
NYCU(NCTU)-差勤-助教

NCTU-TA-fill 填寫 差勤-助教時數 有沒有覺得在差勤系統填助教時數有點浪費生命? 今天有個懶鬼浪費好多時間幫大家寫了code 只要填好的必要的資料,就可以讓電腦自動幫你完成差勤助教的時數填寫喔! https://pt-attendance.nctu.edu.tw/verify/userL

14 Dec 21, 2021
A script where you execute a script that generates a base project for your gdextension

GDExtension Project Creator this is a script (currently only for linux) where you execute a script that generates a base project for your gdextension,

Unknown 11 Nov 17, 2022
dragmap-meth: Fast and accurate aligner for bisulfite sequencing reads using dragmap

dragmap_meth (dragmap_meth.py) Alignment of BS-Seq reads using dragmap. Intro This works for single-end reads and for paired-end reads from the direct

Shaojun Xie 3 Jul 14, 2022
NGEBUG is a tool that sends viruses to victims

Ngebug NGEBUG adalah tools pengirim virus ke korban NGEBUG adalah tools virus terbaru yang berasal dari rusia Informasi lengkap ada didalam tools Run

Profesor Acc 3 Dec 13, 2021
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
OpenTracing API for Python

OpenTracing API for Python This library is a Python platform API for OpenTracing. Required Reading In order to understand the Python platform API, one

OpenTracing API 767 Dec 16, 2022