Created
May 22, 2019 12:31
-
-
Save astellon/1617cc2ae00c7967825d352f1f7194c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Ray Tracing in One Weekend (in Julia)\n", | |
"\n", | |
"Ray Tracing in One WeekendをJuliaで実装します。\n", | |
"\n", | |
"This is an implementation of \"Ray Tracing in One Weekend\" using Julia\n", | |
"\n", | |
"Peter Shirley, Ray Tracing in One Weekend, Version 1.54, 2018" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"ソースコードについてはQiitaの記事\n", | |
"「[レイトレーシング入門1「光線の基本と反射](https://qiita.com/mebiusbox2/items/89e2db3b24e4c39502fe)」も参考にしています。" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# 環境" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Julia Version 1.1.0\n", | |
"Commit 80516ca202 (2019-01-21 21:24 UTC)\n", | |
"Platform Info:\n", | |
" OS: Linux (x86_64-pc-linux-gnu)\n", | |
" CPU: Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz\n", | |
" WORD_SIZE: 64\n", | |
" LIBM: libopenlibm\n", | |
" LLVM: libLLVM-6.0.1 (ORCJIT, skylake)\n", | |
"Environment:\n", | |
" JULIA_DEPOT_PATH = /opt/julia\n", | |
" JULIA_PKGDIR = /opt/julia\n", | |
" JULIA_VERSION = 1.1.0\n" | |
] | |
} | |
], | |
"source": [ | |
"versioninfo()" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"ベクトルを扱うために`LinearAlgebra.jl`を使います。画像に関する型を使いたいので`Image.jl`、出力用に`FileIO`を使います。また、画像表示等に`ImageMagick.jl`が使われるのでインストール(usingは必要ない)しておく必要があります。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"using LinearAlgebra, FileIO, Images" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 1: Output an image" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"画像は配列で表現できます。ただし、表示は縦横逆になるので転置する。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkAQAAAADr/UKmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAd2KE6QAAAAZSURBVEjH7cGBAAAAAMOg+VMf4ApVAQDAGwooAAFK+upgAAAAAElFTkSuQmCC", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.0,0.0,0.0) … RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) … RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) … RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) … RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) … RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)\n", | |
" RGB{Float32}(0.0,0.0,0.0) RGB{Float32}(0.0,0.0,0.0)" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"nx = 200\n", | |
"ny = 100\n", | |
"image = zeros(RGB{Float32}, nx, ny)\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" r = i / nx\n", | |
" g = j / ny\n", | |
" b = 0.2\n", | |
" image[i, ny - j + 1] = RGB{Float32}(r, g, b)\n", | |
" end\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAABSUlEQVR42u3VOwrCUBRF0fskM3L+Q/NT2aUQdJMoa2EhIiHFYd+1HtfLzHp9dr+//+MZ/vBbjz3ti3342G1uA1+3zf3oV+AfKRYJxSKhWCQUi4RikVAsEopFQrFIKBYJwyLhFJJQLBKKRUKxSCgWCcUioVgkFIuEYZFwCkkoFgnFIqFYJBSLhGKRUCwSikXCsEg4hSQUi4RikVAsEopFQrFIKBYJxSKhWCQUi4RhkXAKSSgWCcUioVgkFIuEYpFQLBKKRUKxSCgWCcMi4RSSUCwSikVCsUgoFgnFIqFYJBSLhGGRcApJKBYJxSKhWCQUi4RikVAsEopFwrBIOIUkFIuEYpFQLBKKRUKxSCgWCcUioVgkFIuEYZFwCkkoFgnFIqFYJBSLhGKRUCwSikVCsUgoFgnDIuEUklAsEopFQrFIKBYJxSKhWCSe4Jllw4JQBKkAAAAASUVORK5CYII=", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.005,1.0,0.2) … RGB{Float32}(1.0,1.0,0.2) \n", | |
" RGB{Float32}(0.005,0.99,0.2) RGB{Float32}(1.0,0.99,0.2)\n", | |
" RGB{Float32}(0.005,0.98,0.2) RGB{Float32}(1.0,0.98,0.2)\n", | |
" RGB{Float32}(0.005,0.97,0.2) RGB{Float32}(1.0,0.97,0.2)\n", | |
" RGB{Float32}(0.005,0.96,0.2) RGB{Float32}(1.0,0.96,0.2)\n", | |
" RGB{Float32}(0.005,0.95,0.2) … RGB{Float32}(1.0,0.95,0.2)\n", | |
" RGB{Float32}(0.005,0.94,0.2) RGB{Float32}(1.0,0.94,0.2)\n", | |
" RGB{Float32}(0.005,0.93,0.2) RGB{Float32}(1.0,0.93,0.2)\n", | |
" RGB{Float32}(0.005,0.92,0.2) RGB{Float32}(1.0,0.92,0.2)\n", | |
" RGB{Float32}(0.005,0.91,0.2) RGB{Float32}(1.0,0.91,0.2)\n", | |
" RGB{Float32}(0.005,0.9,0.2) … RGB{Float32}(1.0,0.9,0.2) \n", | |
" RGB{Float32}(0.005,0.89,0.2) RGB{Float32}(1.0,0.89,0.2)\n", | |
" RGB{Float32}(0.005,0.88,0.2) RGB{Float32}(1.0,0.88,0.2)\n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.005,0.12,0.2) RGB{Float32}(1.0,0.12,0.2)\n", | |
" RGB{Float32}(0.005,0.11,0.2) RGB{Float32}(1.0,0.11,0.2)\n", | |
" RGB{Float32}(0.005,0.1,0.2) … RGB{Float32}(1.0,0.1,0.2) \n", | |
" RGB{Float32}(0.005,0.09,0.2) RGB{Float32}(1.0,0.09,0.2)\n", | |
" RGB{Float32}(0.005,0.08,0.2) RGB{Float32}(1.0,0.08,0.2)\n", | |
" RGB{Float32}(0.005,0.07,0.2) RGB{Float32}(1.0,0.07,0.2)\n", | |
" RGB{Float32}(0.005,0.06,0.2) RGB{Float32}(1.0,0.06,0.2)\n", | |
" RGB{Float32}(0.005,0.05,0.2) … RGB{Float32}(1.0,0.05,0.2)\n", | |
" RGB{Float32}(0.005,0.04,0.2) RGB{Float32}(1.0,0.04,0.2)\n", | |
" RGB{Float32}(0.005,0.03,0.2) RGB{Float32}(1.0,0.03,0.2)\n", | |
" RGB{Float32}(0.005,0.02,0.2) RGB{Float32}(1.0,0.02,0.2)\n", | |
" RGB{Float32}(0.005,0.01,0.2) RGB{Float32}(1.0,0.01,0.2)" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"画像の保存には`FileIO`を使う。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"save(\"helloworld.png\", image)" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 2: The vec3 class\n", | |
"\n", | |
"配列で表現することとする。`LinearAlgebra.jl`に必要な関数は揃っている。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"3-element Array{Int64,1}:\n", | |
" 2\n", | |
" 3\n", | |
" 4" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"v = [1, 2, 3]\n", | |
"w = [2, 3, 4]" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 3: Rays, a simple camera, and background" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"`Ray`のクラスを作ります。`Ray`は始点と方向のベクトルを持ちます。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct Ray\n", | |
" origin\n", | |
" direction\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"長さに関するファクター`t`によって、ベクトルが決まります。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"at (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"at(ray::Ray, t) = ray.origin + ray.direction * t" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"color (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function color(ray::Ray)\n", | |
" d = normalize(ray.direction)\n", | |
" t = 0.5 * (d[2] .+ 1)\n", | |
" return (1-t)*[1, 1, 1] + t*[0.5, 0.7, 1.0]\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAMAAAD0WI85AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABhlBMVEWlyf+kyf+kyP+jyP+ix/+hx/+hxv+gxv+fxv+fxf+exf+dxP+cxP+cw/+bw/+aw/+awv+Zwv+Ywf+Xwf+XwP+WwP+VwP+Vv/+Uv/+Tvv+Svv+myf+myv+nyv+oy/+py/+pzP+qzP+rzP+rzf+szf+tzv+uzv+uz/+vz/+wz/+w0P+x0P+y0f+z0f+z0v+00v+10v+10/+20/+31P+41P+41f+51f+61f+61v+71v+81/+91/++2P+92P+/2P+/2f/A2f/A2v/B2v/C2v/C2//D2//E2//E3P/F3P/G3f/H3f/H3v/I3v/J3v/J3//K3//L4P/M4P/M4f/N4f/O4f/O4v/P4v/Q4//R4//R5P/S5P/T5P/T5f/U5f/V5v/W5v/W5//X5//Y5//Y6P/Z6P/a6f/b6f/U5v/b6v/c6v/d6v/d6//e6//f7P/g7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pjjgiYaGEjxi+VNQuQZ+0HxX15RzPwRDlFMsTaP8vJnIiJlo+wpbEt5FppLVBXNDYDKQLiMy0EQyx920ItwEeq68IXVwYeqagghs/LEA2yoBELq6X7QlmOGNSbUZ+pqBgyxed6mGU4FNqiTJjalvvAFR/wm/PaTA3zRFHEFzwUk2ds2DxhuS2FBdC/fyjNEGeKMJgi1P1vGqIpLEO68KsTxkfMWIA3Q3jIUJbGsGAghan7S56oQZZMGbYslmLh57YAbYY0U5khLQ2qCIgva8GYZNEXS3lTWTxSxrYAb0bxsKSt8KcyIyv+4/Nfm/AztXDK05Z1zybMWf4HVK/bY9nzhsYAAAAASUVORK5CYII=", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.647254,0.788352,1.0) … RGB{Float32}(0.647938,0.788763,1.0)\n", | |
" RGB{Float32}(0.648971,0.789382,1.0) RGB{Float32}(0.649647,0.789788,1.0)\n", | |
" RGB{Float32}(0.650704,0.790423,1.0) RGB{Float32}(0.651374,0.790824,1.0)\n", | |
" RGB{Float32}(0.652455,0.791473,1.0) RGB{Float32}(0.653117,0.79187,1.0) \n", | |
" RGB{Float32}(0.654223,0.792534,1.0) RGB{Float32}(0.654877,0.792926,1.0)\n", | |
" RGB{Float32}(0.656008,0.793605,1.0) … RGB{Float32}(0.656654,0.793993,1.0)\n", | |
" RGB{Float32}(0.65781,0.794686,1.0) RGB{Float32}(0.658448,0.795069,1.0)\n", | |
" RGB{Float32}(0.659629,0.795777,1.0) RGB{Float32}(0.660258,0.796155,1.0)\n", | |
" RGB{Float32}(0.661464,0.796878,1.0) RGB{Float32}(0.662084,0.79725,1.0) \n", | |
" RGB{Float32}(0.663316,0.79799,1.0) RGB{Float32}(0.663926,0.798356,1.0)\n", | |
" RGB{Float32}(0.665184,0.79911,1.0) … RGB{Float32}(0.665785,0.799471,1.0)\n", | |
" RGB{Float32}(0.667069,0.800241,1.0) RGB{Float32}(0.667659,0.800596,1.0)\n", | |
" RGB{Float32}(0.668969,0.801381,1.0) RGB{Float32}(0.669549,0.80173,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.831031,0.898619,1.0) RGB{Float32}(0.830451,0.89827,1.0) \n", | |
" RGB{Float32}(0.832931,0.899759,1.0) RGB{Float32}(0.832341,0.899404,1.0)\n", | |
" RGB{Float32}(0.834816,0.90089,1.0) … RGB{Float32}(0.834215,0.900529,1.0)\n", | |
" RGB{Float32}(0.836684,0.90201,1.0) RGB{Float32}(0.836074,0.901644,1.0)\n", | |
" RGB{Float32}(0.838536,0.903122,1.0) RGB{Float32}(0.837916,0.90275,1.0) \n", | |
" RGB{Float32}(0.840371,0.904223,1.0) RGB{Float32}(0.839742,0.903845,1.0)\n", | |
" RGB{Float32}(0.84219,0.905314,1.0) RGB{Float32}(0.841552,0.904931,1.0)\n", | |
" RGB{Float32}(0.843992,0.906395,1.0) … RGB{Float32}(0.843346,0.906007,1.0)\n", | |
" RGB{Float32}(0.845777,0.907466,1.0) RGB{Float32}(0.845123,0.907074,1.0)\n", | |
" RGB{Float32}(0.847545,0.908527,1.0) RGB{Float32}(0.846883,0.90813,1.0) \n", | |
" RGB{Float32}(0.849296,0.909577,1.0) RGB{Float32}(0.848626,0.909176,1.0)\n", | |
" RGB{Float32}(0.851029,0.910618,1.0) RGB{Float32}(0.850353,0.910212,1.0)" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# screen\n", | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" u = i / nx\n", | |
" v = j / ny\n", | |
" ray = Ray(origin, lowerleft + u*horizontal + v*vertical)\n", | |
" c = color(ray)\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 4: Adding a sphere" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"hitsphere (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function hitsphere(center, radius, ray::Ray)\n", | |
" oc = ray.origin - center\n", | |
" a = dot(ray.direction, ray.direction)\n", | |
" b = 2.0 * dot(oc, ray.direction)\n", | |
" c = dot(oc, oc) - radius^2\n", | |
" discriminant = b^2 - 4 * a * c\n", | |
" return discriminant > 0\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"color (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function color(ray::Ray)\n", | |
" if hitsphere([0, 0, -1], 0.5, ray)\n", | |
" return [1, 0, 0]\n", | |
" end\n", | |
" d = normalize(ray.direction)\n", | |
" t = 0.5*(d[2] + 1)\n", | |
" return (1-t)*[1, 1, 1] + t*[0.5, 0.7, 1.0]\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAMAAAD0WI85AAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABhlBMVEWlyf+kyf+kyP+jyP+ix/+hx/+hxv+gxv+fxv+fxf+exf+dxP+cxP+cw/+bw/+aw/+awv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aOWb4xGQxYBH72S7UiVOhWeAQWvHnz5m9hxGfYQzGuMckVgxvjlozFAEIwj06Mwg2UboUdJ48ggr/bEA/FqDFzjcFDlrCEjZEYoIjUTftZUuFbgQ2i8n9w8SKloY1hLc/St3+CgXQr2igQwhC+4WM4AaathWkMMK1Ai7ukCFqhEa7qf9IQjcHQxpQsT1iLwoBH1Cj22F54BC9gPQjD9WWv2qIbA5FiJ1TE16icwpb7L58e+plokpbEdcxZdmILeARRxLfuaKTcRPl5QoZer/c2jPgMafyUReuFHzF0HcMWjQHm3ahG8dopbC88giFQDsW4vkjL65YW1xioUNDbHh0prKCId+/e/ZtGfMJgrCUasfhWmbOAfdcOX5BqmoEnSimcwdb+rY/nWIy1fIMtlW0h90ppgbyishlIYRDfpkIwxNK2LdQC8UiVbnx2ZeCRsgpi+C4M0SALGjGzWso3ynDEIN+M/ExZRS9SfJdOZOn1mLYkJizZlicQK57HD+e5mer5iaKI/8ShGD9jveoJ820JLID+/SPRDHamCCNSmLr/S0M0gaVHF352wuIRExaIm8G8ZCSWRi9gIIWo+/s4VoMsntKrWSzBwvdtAdoMbqY8g1saVGEQ3+eCMc6SXizhQ2XwSmnbAnEzgpel1Ap/yzO84ged/8mYn6klprytWffRhCnL/wH2UBtGCJ87UAAAAABJRU5ErkJggg==", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.647254,0.788352,1.0) … RGB{Float32}(0.647938,0.788763,1.0)\n", | |
" RGB{Float32}(0.648971,0.789382,1.0) RGB{Float32}(0.649647,0.789788,1.0)\n", | |
" RGB{Float32}(0.650704,0.790423,1.0) RGB{Float32}(0.651374,0.790824,1.0)\n", | |
" RGB{Float32}(0.652455,0.791473,1.0) RGB{Float32}(0.653117,0.79187,1.0) \n", | |
" RGB{Float32}(0.654223,0.792534,1.0) RGB{Float32}(0.654877,0.792926,1.0)\n", | |
" RGB{Float32}(0.656008,0.793605,1.0) … RGB{Float32}(0.656654,0.793993,1.0)\n", | |
" RGB{Float32}(0.65781,0.794686,1.0) RGB{Float32}(0.658448,0.795069,1.0)\n", | |
" RGB{Float32}(0.659629,0.795777,1.0) RGB{Float32}(0.660258,0.796155,1.0)\n", | |
" RGB{Float32}(0.661464,0.796878,1.0) RGB{Float32}(0.662084,0.79725,1.0) \n", | |
" RGB{Float32}(0.663316,0.79799,1.0) RGB{Float32}(0.663926,0.798356,1.0)\n", | |
" RGB{Float32}(0.665184,0.79911,1.0) … RGB{Float32}(0.665785,0.799471,1.0)\n", | |
" RGB{Float32}(0.667069,0.800241,1.0) RGB{Float32}(0.667659,0.800596,1.0)\n", | |
" RGB{Float32}(0.668969,0.801381,1.0) RGB{Float32}(0.669549,0.80173,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.831031,0.898619,1.0) RGB{Float32}(0.830451,0.89827,1.0) \n", | |
" RGB{Float32}(0.832931,0.899759,1.0) RGB{Float32}(0.832341,0.899404,1.0)\n", | |
" RGB{Float32}(0.834816,0.90089,1.0) … RGB{Float32}(0.834215,0.900529,1.0)\n", | |
" RGB{Float32}(0.836684,0.90201,1.0) RGB{Float32}(0.836074,0.901644,1.0)\n", | |
" RGB{Float32}(0.838536,0.903122,1.0) RGB{Float32}(0.837916,0.90275,1.0) \n", | |
" RGB{Float32}(0.840371,0.904223,1.0) RGB{Float32}(0.839742,0.903845,1.0)\n", | |
" RGB{Float32}(0.84219,0.905314,1.0) RGB{Float32}(0.841552,0.904931,1.0)\n", | |
" RGB{Float32}(0.843992,0.906395,1.0) … RGB{Float32}(0.843346,0.906007,1.0)\n", | |
" RGB{Float32}(0.845777,0.907466,1.0) RGB{Float32}(0.845123,0.907074,1.0)\n", | |
" RGB{Float32}(0.847545,0.908527,1.0) RGB{Float32}(0.846883,0.90813,1.0) \n", | |
" RGB{Float32}(0.849296,0.909577,1.0) RGB{Float32}(0.848626,0.909176,1.0)\n", | |
" RGB{Float32}(0.851029,0.910618,1.0) RGB{Float32}(0.850353,0.910212,1.0)" | |
] | |
}, | |
"execution_count": 14, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# screen\n", | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" u = i / nx\n", | |
" v = j / ny\n", | |
" ray = Ray(origin, lowerleft + u*horizontal + v*vertical)\n", | |
" c = color(ray)\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 5: Surface normals and multiple objects." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"hitsphere (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function hitsphere(center, radius, ray::Ray)\n", | |
" oc = ray.origin - center\n", | |
" a = dot(ray.direction, ray.direction)\n", | |
" b = 2.0 * dot(oc, ray.direction)\n", | |
" c = dot(oc, oc) - radius^2\n", | |
" discriminant = b^2 - 4 * a * c\n", | |
" if discriminant < 0\n", | |
" return -1\n", | |
" else\n", | |
" return (-b - sqrt(discriminant)) / (2a)\n", | |
" end\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"color (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 16, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function color(ray::Ray)\n", | |
" center = [0, 0, -1]\n", | |
" t = hitsphere(center, 0.5, ray)\n", | |
" if t > 0 \n", | |
" N = normalize(at(ray, t) - center)\n", | |
" return 0.5*(N .+ 1)\n", | |
" end\n", | |
" d = normalize(ray.direction)\n", | |
" t = 0.5*(d[2] + 1)\n", | |
" return (1-t)*[1, 1, 1] + t*[0.5, 0.7, 1.0]\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAYdElEQVR42tWdXaht11XH/2OuufY5uUmaJkaqaIugKH4lKdyAV2Ke9MkHX3yQRiwIYu2TFITWB8EHzYsKPij6IKJQUSxIER/Etxi81hzTe3O1D1ZaE4tUhZQ29ebcc/aaw4f1Nb/G/Fgf59xMknP33mvOsebHb//HmGOtvTd9+nOMsfDwv/XUKuw+d5s5ldmtwYIR24LUXGqbaJ4dSGgqbra4UOIQJSuT35asGiSbIusfKmgeaSs1L+tAdiA6HNW0rjT869idlmQ+2vfP4mA4RBE7thHbAmHmw27umB37nm4uDSQcC2KEJSgpL1mewhOVMIGHDanYQPpXNJGvDVEskFzdqX7Ix7DA2+GVbQ7EOoAMYfagFhQSeCziCVeK1DKNrB2LdioVrEqJgIn6sQVe2eYIQbSM2GNB4PgkPmoLxZ4sQyojM1eMVMF7A4NiAZjmN7sqgoAl8IJNaj1e/Z8q8YMrn/DeKoi8W6ayVLBiDlR2E/aBfCAFn4kFRC7zerVyaz/U3nO2TRQLWCL6QRh+jUak+Mnno5hOsQPuWCLDGY+tFSxhtdJrAKQUQmJiodNEnkivA6jhaSo6KjkIViW+JEn/mA2/Sh1ctLlLJ9IChhxh1qOIaPn+0j+ewDG7Bjt5vcLmKGY6tBMd+GRNe88lwuJLkl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LmGNqfBL54rWtbvssDK5XBlKFGgkBptXxVbyHYZoHSTggx9c2N0g4uET4VZB/F/kOjKBMwKwvXquRKLgrihKkVsfmy9wugvcGZJ6KPGPsiiFHW8T24SWpIyl+Whh+xcQv0RxJ/1goYP8PueiPUdzDyqAAAAAASUVORK5CYII=", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.647254,0.788352,1.0) … RGB{Float32}(0.647938,0.788763,1.0)\n", | |
" RGB{Float32}(0.648971,0.789382,1.0) RGB{Float32}(0.649647,0.789788,1.0)\n", | |
" RGB{Float32}(0.650704,0.790423,1.0) RGB{Float32}(0.651374,0.790824,1.0)\n", | |
" RGB{Float32}(0.652455,0.791473,1.0) RGB{Float32}(0.653117,0.79187,1.0) \n", | |
" RGB{Float32}(0.654223,0.792534,1.0) RGB{Float32}(0.654877,0.792926,1.0)\n", | |
" RGB{Float32}(0.656008,0.793605,1.0) … RGB{Float32}(0.656654,0.793993,1.0)\n", | |
" RGB{Float32}(0.65781,0.794686,1.0) RGB{Float32}(0.658448,0.795069,1.0)\n", | |
" RGB{Float32}(0.659629,0.795777,1.0) RGB{Float32}(0.660258,0.796155,1.0)\n", | |
" RGB{Float32}(0.661464,0.796878,1.0) RGB{Float32}(0.662084,0.79725,1.0) \n", | |
" RGB{Float32}(0.663316,0.79799,1.0) RGB{Float32}(0.663926,0.798356,1.0)\n", | |
" RGB{Float32}(0.665184,0.79911,1.0) … RGB{Float32}(0.665785,0.799471,1.0)\n", | |
" RGB{Float32}(0.667069,0.800241,1.0) RGB{Float32}(0.667659,0.800596,1.0)\n", | |
" RGB{Float32}(0.668969,0.801381,1.0) RGB{Float32}(0.669549,0.80173,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.831031,0.898619,1.0) RGB{Float32}(0.830451,0.89827,1.0) \n", | |
" RGB{Float32}(0.832931,0.899759,1.0) RGB{Float32}(0.832341,0.899404,1.0)\n", | |
" RGB{Float32}(0.834816,0.90089,1.0) … RGB{Float32}(0.834215,0.900529,1.0)\n", | |
" RGB{Float32}(0.836684,0.90201,1.0) RGB{Float32}(0.836074,0.901644,1.0)\n", | |
" RGB{Float32}(0.838536,0.903122,1.0) RGB{Float32}(0.837916,0.90275,1.0) \n", | |
" RGB{Float32}(0.840371,0.904223,1.0) RGB{Float32}(0.839742,0.903845,1.0)\n", | |
" RGB{Float32}(0.84219,0.905314,1.0) RGB{Float32}(0.841552,0.904931,1.0)\n", | |
" RGB{Float32}(0.843992,0.906395,1.0) … RGB{Float32}(0.843346,0.906007,1.0)\n", | |
" RGB{Float32}(0.845777,0.907466,1.0) RGB{Float32}(0.845123,0.907074,1.0)\n", | |
" RGB{Float32}(0.847545,0.908527,1.0) RGB{Float32}(0.846883,0.90813,1.0) \n", | |
" RGB{Float32}(0.849296,0.909577,1.0) RGB{Float32}(0.848626,0.909176,1.0)\n", | |
" RGB{Float32}(0.851029,0.910618,1.0) RGB{Float32}(0.850353,0.910212,1.0)" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# screen\n", | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" u = i / nx\n", | |
" v = j / ny\n", | |
" ray = Ray(origin, lowerleft + u*horizontal + v*vertical)\n", | |
" c = color(ray)\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"原著では、非constの参照渡しをしていますが、結果を返すようにします。" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"abstract type HitRecord end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct Hit <: HitRecord\n", | |
" t\n", | |
" p\n", | |
" n\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct NotHit <: HitRecord end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"ishit (generic function with 2 methods)" | |
] | |
}, | |
"execution_count": 21, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"ishit(h::Hit) = true\n", | |
"ishit(h::NotHit) = false" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"hit (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 22, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"abstract type Hitable end\n", | |
"hit(obj::Hitable, ray::Ray, tmin, tmax) = 0" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 23, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct Sphere <: Hitable\n", | |
" center\n", | |
" radius\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 24, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"hit (generic function with 2 methods)" | |
] | |
}, | |
"execution_count": 24, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function hit(sphere::Sphere, ray::Ray, tmin, tmax)\n", | |
" oc = ray.origin - sphere.center\n", | |
" a = dot(ray.direction, ray.direction)\n", | |
" b = 2.0 * dot(oc, ray.direction)\n", | |
" c = dot(oc, oc) - sphere.radius^2\n", | |
" \n", | |
" discriminant = b^2 - 4 * a * c\n", | |
" \n", | |
" if discriminant > 0\n", | |
" t = (-b - sqrt(discriminant)) / (2a)\n", | |
" if tmin < t < tmax\n", | |
" p = at(ray, t)\n", | |
" n = (p - sphere.center) / sphere.radius\n", | |
" return Hit(t, p, n)\n", | |
" end\n", | |
" \n", | |
" t = (-b + sqrt(discriminant)) / (2a)\n", | |
" if tmin < t < tmax\n", | |
" p = at(ray, t)\n", | |
" n = (p - sphere.center) / sphere.radius\n", | |
" return Hit(t, p, n)\n", | |
" end\n", | |
" end\n", | |
" \n", | |
" return NotHit()\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct HitableList <: Hitable\n", | |
" list::Array{Hitable, 1}\n", | |
" HitableList() = new(Array{Hitable, 1}())\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"Base.push!(l::HitableList, h::Hitable) = push!(l.list, h)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 27, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"hit (generic function with 3 methods)" | |
] | |
}, | |
"execution_count": 27, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function hit(hits::HitableList, ray::Ray, tmin, tmax)\n", | |
" closesthit = NotHit()\n", | |
" closest = tmax\n", | |
" foreach(hits.list) do h\n", | |
" rec = hit(h, ray, tmin, closest)\n", | |
" if ishit(rec)\n", | |
" closesthit = rec\n", | |
" closest = rec.t\n", | |
" end\n", | |
" end\n", | |
"\n", | |
" return closesthit\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"color (generic function with 2 methods)" | |
] | |
}, | |
"execution_count": 28, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function color(ray::Ray, world::Hitable)\n", | |
" rec = hit(world, ray, 0, typemax(Float64))\n", | |
" if ishit(rec)\n", | |
" return 0.5*(rec.n .+ 1)\n", | |
" else\n", | |
" d = normalize(ray.direction)\n", | |
" t = 0.5*(d[2] + 1)\n", | |
" return (1-t)*[1, 1, 1] + t*[0.5, 0.7, 1.0]\n", | |
" end\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 29, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAV4klEQVR42u1dS8wlx1U+p6runX/G4xibQMQjCGWiZBFwLHCEgk0iECChBCkOElIQYofEkg3iYbNAImTDhgULhBAbHAsi7Ek8AwKPbHk0ZmR5EnnGCVIcjyVIiCBIjoijmX/u7arDoqqrq+vdr3vvRP/RnTt9u6tOvb7+zqlT1f3jky8TtELmn/PTEer/7mfrJaZ+CkoocTWksqfyZrIXGxKqiqutFsxcwmxi9POikwLTqtD5DyuyR/KmstdVoNgQEbbKjiua/3t67ZB0V3X9HByYSxjR4ypxNSB0+HCz99S2dc9nTzUkbAvEEJZBSb0U8RQWVIMJODRIxRqizwhEnxuisIDs6Nr0IT7MAM8Hr2J2gFgFoIAwt1EjBBN4rMIT7BRS4zhyaFtEL1HFqNQQWJI/5oBXMTuEQHSUuG2BwPCl8DFUMPZjHKQKNLNjSFXcG2AYCwBs/xZHJUFgGXiBi9Th8NJfg8gP+vQJ3q0CkbvFyljCihnQtJlwL5QdKfAxMQKR46zeULp1D4X3m1wV1QSW8X4gdL9aJSn/ycdHNTqTFei3JdKc9tpUwkqMV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3PEOOA3P4V3zYVofmTORKV5Jtb//WtF3bTA7u0jF65WgaVXvGI/T4as98K/HACKxJAAmwGaptR9kJdXumVFUgCa+94OqhqHJTsi7rcCmjJVGPSW5MXlcOpyQHKfqnLq0a0JjO90W9uObT6HKbsnbrcmmix9Tm492MdWn0OXA6Eurz6wNBtM0vL4XTQ3SWz772ZLjMv6YyWE0hNlEOjrv0D63D64ntADgdeezaFh9AF33tyCJZxb4x1AqlFZe/UtR/GOkHVbmSP1LVrxjqB1I5lX9S1U8Y6QdW+ZPfUtSPGOoHU3mXH1LULxjpB1eHIzqhrWcY6gdQBym6oaylgnUDqwGVpeC1iCk9QdbfIcpbxLn7860RmkYWoa07GOkHV3SuzU9fd+lzhicwu81LX/wPw//HmVfxhAQAAAABJRU5ErkJggg==", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.647254,0.788352,1.0) … RGB{Float32}(0.647938,0.788763,1.0) \n", | |
" RGB{Float32}(0.648971,0.789382,1.0) RGB{Float32}(0.649647,0.789788,1.0) \n", | |
" RGB{Float32}(0.650704,0.790423,1.0) RGB{Float32}(0.651374,0.790824,1.0) \n", | |
" RGB{Float32}(0.652455,0.791473,1.0) RGB{Float32}(0.653117,0.79187,1.0) \n", | |
" RGB{Float32}(0.654223,0.792534,1.0) RGB{Float32}(0.654877,0.792926,1.0) \n", | |
" RGB{Float32}(0.656008,0.793605,1.0) … RGB{Float32}(0.656654,0.793993,1.0) \n", | |
" RGB{Float32}(0.65781,0.794686,1.0) RGB{Float32}(0.658448,0.795069,1.0) \n", | |
" RGB{Float32}(0.659629,0.795777,1.0) RGB{Float32}(0.660258,0.796155,1.0) \n", | |
" RGB{Float32}(0.661464,0.796878,1.0) RGB{Float32}(0.662084,0.79725,1.0) \n", | |
" RGB{Float32}(0.663316,0.79799,1.0) RGB{Float32}(0.663926,0.798356,1.0) \n", | |
" RGB{Float32}(0.665184,0.79911,1.0) … RGB{Float32}(0.665785,0.799471,1.0) \n", | |
" RGB{Float32}(0.667069,0.800241,1.0) RGB{Float32}(0.667659,0.800596,1.0) \n", | |
" RGB{Float32}(0.668969,0.801381,1.0) RGB{Float32}(0.669549,0.80173,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.493365,0.999953,0.501649) RGB{Float32}(0.506704,0.999952,0.501648)\n", | |
" RGB{Float32}(0.49354,0.999955,0.501737) RGB{Float32}(0.506527,0.999954,0.501736)\n", | |
" RGB{Float32}(0.493706,0.999957,0.501821) … RGB{Float32}(0.506359,0.999956,0.50182) \n", | |
" RGB{Float32}(0.493864,0.999959,0.501901) RGB{Float32}(0.5062,0.999958,0.5019) \n", | |
" RGB{Float32}(0.494013,0.99996,0.501976) RGB{Float32}(0.506049,0.99996,0.501976) \n", | |
" RGB{Float32}(0.494156,0.999962,0.502048) RGB{Float32}(0.505905,0.999961,0.502048)\n", | |
" RGB{Float32}(0.494292,0.999963,0.502117) RGB{Float32}(0.505768,0.999962,0.502116)\n", | |
" RGB{Float32}(0.494421,0.999964,0.502182) … RGB{Float32}(0.505637,0.999963,0.502182)\n", | |
" RGB{Float32}(0.494545,0.999965,0.502245) RGB{Float32}(0.505512,0.999965,0.502244)\n", | |
" RGB{Float32}(0.494663,0.999966,0.502304) RGB{Float32}(0.505392,0.999966,0.502304)\n", | |
" RGB{Float32}(0.494776,0.999967,0.502362) RGB{Float32}(0.505278,0.999967,0.502361)\n", | |
" RGB{Float32}(0.494884,0.999968,0.502416) RGB{Float32}(0.505168,0.999967,0.502416)" | |
] | |
}, | |
"execution_count": 29, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"# screen\n", | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"world = HitableList()\n", | |
"push!(world, Sphere([0, 0, -1], 0.5))\n", | |
"push!(world, Sphere([0, -100.5, -1], 100))\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" u = i / nx\n", | |
" v = j / ny\n", | |
" ray = Ray(origin, lowerleft + u*horizontal + v*vertical)\n", | |
" c = color(ray, world)\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Chapter 6: Antialiasing" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct Camera\n", | |
" origin\n", | |
" lowerleft\n", | |
" horizontal\n", | |
" vertical\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 31, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"getray (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 31, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function getray(camera::Camera, u, v)\n", | |
" d = camera.lowerleft + u*camera.horizontal + v*vertical - camera.origin\n", | |
" return Ray(camera.origin, d)\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 32, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAZvUlEQVR42u1d64slx3U/p6ruvTM7Mzu7Wlsv5HjlyA/ZJkY4Jg5GEBwTcCA4kM8mJB9jyF8QB4e8PgUM+ZSvCUkgsQP5YgjBJiGxkYVjybFlS0JeW7ta7Uo778ed++iqkw/Vj+p6dXXfvnNnwxyGmb7d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5Es7QAAAABJRU5ErkJggg==", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.646074,0.787645,1.0) … RGB{Float32}(0.647489,0.788493,1.0) \n", | |
" RGB{Float32}(0.647804,0.788682,1.0) RGB{Float32}(0.649108,0.789465,1.0) \n", | |
" RGB{Float32}(0.649522,0.789713,1.0) RGB{Float32}(0.650906,0.790544,1.0) \n", | |
" RGB{Float32}(0.651284,0.79077,1.0) RGB{Float32}(0.652651,0.791591,1.0) \n", | |
" RGB{Float32}(0.653085,0.791851,1.0) RGB{Float32}(0.654356,0.792614,1.0) \n", | |
" RGB{Float32}(0.654747,0.792848,1.0) … RGB{Float32}(0.65616,0.793696,1.0) \n", | |
" RGB{Float32}(0.656698,0.794019,1.0) RGB{Float32}(0.657868,0.794721,1.0) \n", | |
" RGB{Float32}(0.658474,0.795085,1.0) RGB{Float32}(0.65963,0.795778,1.0) \n", | |
" RGB{Float32}(0.660175,0.796105,1.0) RGB{Float32}(0.661501,0.796901,1.0) \n", | |
" RGB{Float32}(0.662132,0.797279,1.0) RGB{Float32}(0.663302,0.797981,1.0) \n", | |
" RGB{Float32}(0.663864,0.798319,1.0) … RGB{Float32}(0.66514,0.799084,1.0) \n", | |
" RGB{Float32}(0.66578,0.799468,1.0) RGB{Float32}(0.666921,0.800153,1.0) \n", | |
" RGB{Float32}(0.667778,0.800667,1.0) RGB{Float32}(0.668893,0.801336,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.493302,0.999953,0.501602) RGB{Float32}(0.506838,0.999951,0.501599)\n", | |
" RGB{Float32}(0.493479,0.999955,0.501689) RGB{Float32}(0.506645,0.999953,0.501695)\n", | |
" RGB{Float32}(0.493653,0.999957,0.501778) … RGB{Float32}(0.506472,0.999955,0.501781)\n", | |
" RGB{Float32}(0.493819,0.999958,0.501862) RGB{Float32}(0.506311,0.999957,0.50186) \n", | |
" RGB{Float32}(0.493971,0.99996,0.50194) RGB{Float32}(0.506149,0.999958,0.50194) \n", | |
" RGB{Float32}(0.494121,0.999961,0.502016) RGB{Float32}(0.505999,0.99996,0.502014) \n", | |
" RGB{Float32}(0.494252,0.999963,0.502081) RGB{Float32}(0.505871,0.999961,0.50208) \n", | |
" RGB{Float32}(0.494384,0.999964,0.50215) … RGB{Float32}(0.505731,0.999963,0.50215) \n", | |
" RGB{Float32}(0.494521,0.999965,0.502217) RGB{Float32}(0.505598,0.999964,0.502214)\n", | |
" RGB{Float32}(0.494629,0.999966,0.502274) RGB{Float32}(0.505478,0.999965,0.502275)\n", | |
" RGB{Float32}(0.494752,0.999967,0.502335) RGB{Float32}(0.505355,0.999966,0.502335)\n", | |
" RGB{Float32}(0.494862,0.999968,0.502391) RGB{Float32}(0.50525,0.999967,0.50239) " | |
] | |
}, | |
"execution_count": 32, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"cam = Camera(origin, lowerleft, horizontal, vertical)\n", | |
"\n", | |
"ns = 100 # number of sampling\n", | |
"\n", | |
"world = HitableList()\n", | |
"push!(world, Sphere([0, 0, -1], 0.5))\n", | |
"push!(world, Sphere([0, -100.5, -1], 100))\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" \n", | |
" c = [0, 0, 0]\n", | |
" for _ in 1:ns\n", | |
" u = (i + rand(Float64)) / nx\n", | |
" v = (j + rand(Float64)) / ny\n", | |
" ray = getray(cam, u, v)\n", | |
" c += color(ray, world)\n", | |
" end\n", | |
" \n", | |
" c /= ns\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 33, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"randinsphere (generic function with 1 method)" | |
] | |
}, | |
"execution_count": 33, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function randinsphere()\n", | |
" while true\n", | |
" p = 2 * [rand(Float64), rand(Float64), rand(Float64)] .- 1\n", | |
" mapreduce(x->x^2, +, p) < 1 && return p\n", | |
" end\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 34, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"color (generic function with 2 methods)" | |
] | |
}, | |
"execution_count": 34, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"function color(ray::Ray, world::Hitable)\n", | |
" rec = hit(world, ray, 0.0000001, typemax(Float64))\n", | |
" if ishit(rec)\n", | |
" target = rec.p + rec.n + randinsphere()\n", | |
" return 0.5 * color(Ray(rec.p, target - rec.p), world)\n", | |
" else\n", | |
" d = normalize(ray.direction)\n", | |
" t = 0.5*(d[2] + 1)\n", | |
" return (1-t)*[1, 1, 1] + t*[0.5, 0.7, 1.0]\n", | |
" end\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 35, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAIAAABM5OhcAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAA9vUlEQVR42t2925IkSXIlpjcz94jMrEt3z2AwWOwKuAQo/BDu8olCvFJ2+Un8B/4GRfgFfOIbVhYCYICemb7VNTMj3M1MVfmg5h6R98iq6h4sXUq6I8PNPdzNjunlqJoa/r+/dzg+HG7+fevk/V/5ie0fbuyf2uzBB3u48SOXfMEDH/4KT7kEH7sVntbs8CU+cPkJjR9p30/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Y8RBo7E0fBgWmsiQswiCREBadxepJQdUFISkVCFDtG4xlRcMh0MAOd5j0RhlbJwBOWY2a3FPi5EpGYp5bB6LRYhBt1qfXe72NXMF3N+KbLSSYPIzQz90KWOOTgshX88oBa5PQvR3qND/x+TDdgexnDeBQAAAABJRU5ErkJggg==", | |
"text/plain": [ | |
"100×200 Adjoint{RGB{Float32},Array{RGB{Float32},2}}:\n", | |
" RGB{Float32}(0.819795,0.897115,1.0) … RGB{Float32}(0.820569,0.897532,1.0) \n", | |
" RGB{Float32}(0.820961,0.897743,1.0) RGB{Float32}(0.82164,0.898109,1.0) \n", | |
" RGB{Float32}(0.821827,0.89821,1.0) RGB{Float32}(0.822718,0.898691,1.0) \n", | |
" RGB{Float32}(0.822894,0.898786,1.0) RGB{Float32}(0.823635,0.899186,1.0) \n", | |
" RGB{Float32}(0.823887,0.899322,1.0) RGB{Float32}(0.824669,0.899744,1.0) \n", | |
" RGB{Float32}(0.82494,0.899891,1.0) … RGB{Float32}(0.825722,0.900314,1.0) \n", | |
" RGB{Float32}(0.826003,0.900466,1.0) RGB{Float32}(0.826636,0.900808,1.0) \n", | |
" RGB{Float32}(0.827077,0.901047,1.0) RGB{Float32}(0.827683,0.901375,1.0) \n", | |
" RGB{Float32}(0.828022,0.901558,1.0) RGB{Float32}(0.828636,0.901891,1.0) \n", | |
" RGB{Float32}(0.829004,0.902091,1.0) RGB{Float32}(0.829701,0.902469,1.0) \n", | |
" RGB{Float32}(0.830227,0.902754,1.0) … RGB{Float32}(0.830789,0.903059,1.0) \n", | |
" RGB{Float32}(0.831117,0.903238,1.0) RGB{Float32}(0.83197,0.9037,1.0) \n", | |
" RGB{Float32}(0.832257,0.903857,1.0) RGB{Float32}(0.832933,0.904224,1.0) \n", | |
" ⋮ ⋱ \n", | |
" RGB{Float32}(0.553466,0.630332,0.728079) RGB{Float32}(0.553749,0.631268,0.72974) \n", | |
" RGB{Float32}(0.553574,0.630388,0.728079) RGB{Float32}(0.557266,0.632287,0.728079)\n", | |
" RGB{Float32}(0.552624,0.627918,0.723907) … RGB{Float32}(0.555411,0.629751,0.724744)\n", | |
" RGB{Float32}(0.552937,0.628079,0.723907) RGB{Float32}(0.556939,0.630935,0.72558) \n", | |
" RGB{Float32}(0.552223,0.629298,0.727247) RGB{Float32}(0.556495,0.63189,0.728079) \n", | |
" RGB{Float32}(0.553374,0.629097,0.72558) RGB{Float32}(0.547374,0.623624,0.720549)\n", | |
" RGB{Float32}(0.545593,0.619492,0.713775) RGB{Float32}(0.554845,0.63025,0.726414) \n", | |
" RGB{Float32}(0.550582,0.62806,0.726414) … RGB{Float32}(0.547771,0.625027,0.723069)\n", | |
" RGB{Float32}(0.554514,0.63008,0.726414) RGB{Float32}(0.557676,0.63171,0.726414) \n", | |
" RGB{Float32}(0.551234,0.625609,0.720549) RGB{Float32}(0.554143,0.629097,0.724744)\n", | |
" RGB{Float32}(0.545323,0.62177,0.718863) RGB{Float32}(0.545846,0.622038,0.718863)\n", | |
" RGB{Float32}(0.551205,0.628479,0.726622) RGB{Float32}(0.553996,0.630604,0.728079)" | |
] | |
}, | |
"execution_count": 35, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"lowerleft = [-2, -1, -1]\n", | |
"horizontal = [4, 0, 0]\n", | |
"vertical = [0, 2, 0]\n", | |
"origin = [0, 0, 0]\n", | |
"\n", | |
"cam = Camera(origin, lowerleft, horizontal, vertical)\n", | |
"\n", | |
"ns = 100 # number of sampling\n", | |
"\n", | |
"world = HitableList()\n", | |
"push!(world, Sphere([0, 0, -1], 0.5))\n", | |
"push!(world, Sphere([0, -100.5, -1], 100))\n", | |
"\n", | |
"for j in ny:-1:1\n", | |
" for i in 1:nx\n", | |
" \n", | |
" c = [0, 0, 0]\n", | |
" for _ in 1:ns\n", | |
" u = (i + rand(0.0:1.0)) / nx\n", | |
" v = (j + rand(0.0:1.0)) / ny\n", | |
" ray = getray(cam, u, v)\n", | |
" c += color(ray, world)\n", | |
" end\n", | |
" \n", | |
" c /= ns\n", | |
" map!(x->x^(1/2.2), c, c) # linear to gamma\n", | |
" image[i, ny - j + 1] = RGB{Float32}(c[1], c[2], c[3])\n", | |
" end\n", | |
"end\n", | |
"\n", | |
"image'" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 36, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"abstract type Material end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"struct Lambertian <: Material\n", | |
" albedo\n", | |
"end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 38, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "UndefVarError", | |
"evalue": "UndefVarError: scatter not defined", | |
"output_type": "error", | |
"traceback": [ | |
"UndefVarError: scatter not defined", | |
"", | |
"Stacktrace:", | |
" [1] top-level scope at In[38]:1" | |
] | |
} | |
], | |
"source": [ | |
"function scatter(lmabert::Lambertian, rec::Hit, att)\n", | |
" target = rec.p + rec.n + randinsphere\n", | |
" ray(rec.p, target - rec.p), albedo\n", | |
"end" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Julia 1.1.0", | |
"language": "julia", | |
"name": "julia-1.1" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "1.1.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment