Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GLSLでパストレーシングしてコーネルボックスを出す
Search
yumcyawiz
November 28, 2020
Programming
0
510
GLSLでパストレーシングしてコーネルボックスを出す
OSK11月LT会のスライド
Github:
https://github.com/yumcyaWiz/glsl-cornellbox
yumcyawiz
November 28, 2020
Tweet
Share
More Decks by yumcyawiz
See All by yumcyawiz
rtcamp 10 (vk-illuminati)
yumcyawiz
1
340
ReSTIRの数理と実装 (rtcamp10)
yumcyawiz
1
940
fredholm(rtcamp9)
yumcyawiz
0
110
フォトンマッピングをパス空間から考える
yumcyawiz
0
410
fredholm
yumcyawiz
0
270
Introduction to volume rendering
yumcyawiz
0
2.2k
OSK#p-ray2020年度講義: 古典的レイトレーサーの実装
yumcyawiz
0
260
Ray Tracing: Overview
yumcyawiz
7
1.2k
Pybind11でC++とPythonのいいとこ取りをする
yumcyawiz
0
960
Other Decks in Programming
See All in Programming
プロフェッショナルとしての成長「問題の深掘り」が導く真のスキルアップ / issue-analysis-and-skill-up
minodriven
7
1.5k
「影響が少ない」を自分の目でみてみる
o0h
PRO
2
1.1k
RuboCop: Modularity and AST Insights
koic
2
1.4k
On-the-fly Suggestions of Rewriting Method Deprecations
ohbarye
1
2.8k
生成AIを使ったQAアプリケーションの作成 - ハンズオン補足資料
oracle4engineer
PRO
3
240
Empowering Developers with HTML-Aware ERB Tooling @ RubyKaigi 2025, Matsuyama, Ehime
marcoroth
2
740
Kamal 2 – Get Out of the Cloud
aleksandrov
1
190
PHPで書いたAPIをGoに書き換えてみた 〜パフォーマンス改善の可能性を探る実験レポート〜
koguuum
0
170
gen_statem - OTP's Unsung Hero
whatyouhide
1
210
AIコーディングの理想と現実
tomohisa
24
31k
Sharing features among Android applications: experience feedback
jbvincey
0
110
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
140
Featured
See All Featured
Code Review Best Practice
trishagee
67
18k
Making the Leap to Tech Lead
cromwellryan
133
9.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
A Tale of Four Properties
chriscoyier
158
23k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.6k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building an army of robots
kneath
304
45k
Site-Speed That Sticks
csswizardry
5
500
Java REST API Framework Comparison - PWX 2021
mraible
30
8.5k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
13
1.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Transcript
GLSLでパストレーシングしてコーネルボックスを 出す OSK11月LT会 @yumcyawiz
GLSLとは?
GLSLとは? • OpenGLで使用されるシェーダー • ユーザー定義のグラフィクス処理を記述できる • 計算はGPUで行われる • 文法はCと似ている
シェーダーの種類 • Vertex Shader • Fragment Shader • Geometry Shader
• Tessellation Shader • Compute Shader
シェーダーで処理する流れ Vertex Shader ポリゴン データ Fragment Shader 出力 頂点座標 テクスチャ座標など
頂点座標をスクリー ン上の座標に変換 各画素の色を計算
Vertex Shaderの例 vPosに頂点情報が入っている gl_Positionに座標変換した頂点情報が格納される
GLSLでパストレ?
GLSLでパストレ? • Vertex Shader -> Fragment Shaderの流れで自然にパストレを 組み込むのは不可能
GLSLでパストレ • Vertex Shader -> Fragment Shaderの流れで自然にパストレを 組み込むのは不可能 画面一杯に四角形を表示して, Fragment
Shaderでパストレする (レイマーチングと同じ方法)
四角形 + Fragment Shader Vertex Shader 画面を覆う四角形 Fragment Shader 各画素の色をパストレ
で計算 3次元空間上に置かれた 四角形
GPUレイトレ • 現在はOptiX, DirectX RayTracing, Vulkan RayTracingがあるの でGLSL縛りでレイトレする必要性はない 今回の主題: GLSLだけでどこまで実装できるのか?
パストレの実装 in GLSL
レイの表現 • vec3は最初から用意されている • classはないがCライクな構造体が利用できる
カメラ • normalizeなどvec3の組み込み関数が使える • C++の場合と全く同じように実装できる
物体 • 物体情報を全部Structに押し込む • type=0(球), type=1(平面)
物体とのintersect • typeに応じてintersectの演算を切り替える
シーンの表現 • Primitiveの配列をハードコーディング(本当はCPU側から渡し たほうが良い)
シーンとのintersect • 線形探索(頑張ればBVHも組み込めるみたい)
乱数 • xorshift32を利用
シード • 画素の位置, 現在のサンプル数をhash関数に通したものをシー ドに設定(アドホックだが見た目は悪くない)
パストレ • これもCPUの場合と同様に実装できる • BRDFはDiffuse only
サンプルの蓄積 • Framebufferを用意し, サンプル蓄積用のテクスチャにレンダリ ングする
結果の表示 • サンプル蓄積用のテクスチャをサンプル数で割ったものを画面 に表示
結果 実際に動いているところをお見せします
Future Works • コードをもっと綺麗に書きたい • GUIを付ける • インタラクティブな操作を可能にする • BVHを組み込んでsponzaとかレンダリングしてみたい
• Disney BRDF • NEE, MIS, BDPTなども実装してみる
Thank you for listening!