SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
3DBasics
                 @tmokita




12年11月17日土曜日
自己紹介
               • 沖田知彦 @tmokita
               • 以前はゲームとか組み込みとか
               • 今はフリーランスでiPhoneアプリ
                           その他いろいろ



12年11月17日土曜日
ざっくり内容
               •   小難しい計算の説明はしません

               •   3Dのとっかかりに必要な用語を説明する
                   ので興味をもったら調べてください

               •   計算とか用語などにつまずかないで
                   頭のなかでイメージできるかが大事

               •   なので3D概論入門みたいな内容です


12年11月17日土曜日
目次

               • 用語とかの基礎知識
               • サンプルデモ、説明
               • プログラムするときのポイント 的な
               • Appendix

12年11月17日土曜日
なんで3Dに見えるのか?

               • 2D:奥行きが無い
               • 3D:奥行きがある
               • 一点透視
               • つまりは 比 の計算

12年11月17日土曜日
ベクトル
               こんなのとか   こんなの




12年11月17日土曜日
ベクトル
               •   3次元ベクトルまでイメージできればOK

                   •   x,y,z 成分で構成されるベクトル

                   •   数学的にはn次元ベクトルというものがある
                       が、まあ別に知らなくてもOK

               •   ベクトルの計算は、加算、減算、
                   長さ、内積、外積、ノーマライズ、位わかって
                   ればOK


12年11月17日土曜日
行列




12年11月17日土曜日
あたまいたいぉ



12年11月17日土曜日
行列
               •   4x4行列までわかっていればOK

               •   横が行、縦が列

               •   単位行列、逆行列、転置行列

               •   行列の計算は
                   加算、減算、乗算、が分かっていればOK

               •   乗算するには条件がある


12年11月17日土曜日
行列
               •   単位行列:数字の1と同じ:e

                   •   どんな行列に掛けても元と同じ

               •   逆行列:A-1

                   •   かけたら単位行列になる行列

               •   転置行列:A    t


                   •   x成分とy成分を交換した行列


12年11月17日土曜日
ベクトルと行列の関係
               • 行列はベクトルを並べたもの
               • ベクトルは行列の一種
               • ベクトルと行列は計算できる
               • 1 3 行列と 3 3 行列は計算できる
               • 結果は 1 3 行列になる
12年11月17日土曜日
ちょっとだけ
               • (1,1)を45度回転させる




12年11月17日土曜日
2次元での回転




12年11月17日土曜日
頂点
               •   3D空間における座標(位置)を
                   表したベクトル

               •   x,y,z、または x,y,z,w で表す

               •   とりあえず最初のうちはwは
                   オマケ程度に考えておけばOK

               •   「wってなにそれwwww」くらいで


12年11月17日土曜日
法線




12年11月17日土曜日
法線
               • ある線や面に対して垂直なベクトル
               • 線に垂直:傾きを掛けると-1になる
               • 面に垂直:2辺の外積を求める
               • 主に光源ベクトルとの内積を求めて
                明るさの計算につかう


12年11月17日土曜日
光源




12年11月17日土曜日
光源
               •   環境光(Ambient)
                   距離や向きに関係なく当たる光

               •   点光源(Point)
                   距離は関係なく一点から球状に放出される光

               •   平行光(Directional)
                   距離は関係なく平行して放出される当たる光

               •   スポット光(Spot)
                   距離は関係なく円錐状に放出される光(スポットライト)



12年11月17日土曜日
陰と影




12年11月17日土曜日
陰と影


               • 陰:シェード(Shade)
               • 影:シャドウ(Shadow)


12年11月17日土曜日
シェーディング
                    左:フラット
                    右:グーロー



                    左:フラット
                    右:フォン


12年11月17日土曜日
シェーディング
               •   フラットシェーディング:面単位

                   •   法線情報は面ごと

               •   グーローシェーディング:頂点単位

                   •   法線情報は頂点ごと

               •   フォンシェーディング:ピクセル単位

                   •   法線情報はピクセルごと


12年11月17日土曜日
フレームバッファ
          Zバッファ(デプスバッファ)

               • フレームバッファ:
                ピクセルを描画するバッファ

               • Zバッファ、デプスバッファ:
                奥行き情報を描画するバッファ
                →奥行きを考慮して描画する為に必要



12年11月17日土曜日
マテリアル
               • マテリアル(material):質感
                 描画するときのパラメータ

               • 色、テクスチャ情報、
                 光源計算に関するパラメータ など

               • Diffuse,Specular,Emmisive とかとか

12年11月17日土曜日
座標系

               • 右手座標系:Zが手前
                OpenGL など

               • 左手座標系:Zが奥
                Direct3D など



12年11月17日土曜日
カメラ(視点)

               • 「見える」時の情報
               • 視点の位置
               • アスペクト比、画角 などなど


12年11月17日土曜日
ニアクリップ
               ファークリップ




12年11月17日土曜日
ニアクリップ
                   ファークリップ

               • ニア(near)クリップ:
                これ以上手前のものは描画しない

               • ファー(far)クリップ
                これ以上奥のものは描画しない



12年11月17日土曜日
以上をふまえて



12年11月17日土曜日
ぽいんと1
               • ぱくる(INSPIRE、RESPECT)
               • 表示させないと楽しくないのでとりあ
                えずなんか表示できるようなコードを
                参考にして自分のモデルとかを表示さ
                せて回転させたり拡縮させたりしてみ
                る


12年11月17日土曜日
ぽいんと2
               •   OpenGLとかDirectXとか使えば大抵勝手に計算して
                   くれるので小難しい計算(透視変換とか回転行列の
                   計算など)を自前でやる必要はないです

               •   むしろハードのスペックを活かしたい場合は下手な
                   コード書くよりはライブラリをフルに使う方がいい
                   結果がでます

               •   iPhoneならiOSHacksなどに載っているARMのコード
                   使えば速くなるかも


12年11月17日土曜日
あらためて



12年11月17日土曜日
3Dプログラムの流れ
               • レンダリング・Zバッファの作成
               • カメラ(視点)の設定
               • ライティングするなら:光源の設定
               • 頂点や法線の設定
               • 描画
12年11月17日土曜日
Demo




12年11月17日土曜日
ポイント1
          PG

               • 可能なものは先に全部計算しておく
               • というかデータを最適化しておく
                • OpenGLに対応した頂点配列
                • 法線情報 などなど

12年11月17日土曜日
ポイント2
          PG

               • マテリアル毎に描画する
               • テクスチャの切り替えなどは負荷が大
                きいため同じテクスチャのものは一気
                に描画する



12年11月17日土曜日
ポイント3
                     ここからはやってないですゴメンなさい
          PG
               • TRIANGLESよりSTRIPをつかう
                頂点情報を減らすため

               • ダミーの頂点をはさんでSTRIPで一気に
                描画する

               • 一般的に描画命令が一番処理が重いの
                でその呼出し回数を出来る限り減らす


12年11月17日土曜日
ポイント4
       Designer
               •
            頂点、面 などのデータを減らす

               • ライティングもテクスチャで代用
               • 透明度のあるものを減らす
                 • 半透明のモノを描画する時は順番を
                 考える


12年11月17日土曜日
ポイント5
   PG/Designer

               • そもそも見えないものは描画しない
                • 完全に透明なもの
                • 明らかに画面からはみ出している
                 だろうと思われるもの



12年11月17日土曜日
Appendix
               •   アニメーションさせたい場合
                   →クウォータニオン(四元数、複素数)っていうものがあるよ
                   →ボーン、ウェイトの計算をする必要があるよ

               •   影(本気)をつけたい場合
                   →ステンシルバッファっていうものがあるよ

               •   影(擬似)をつけたい場合
                   →射影行列っていうものがあるよ

               •   まじめに数学勉強したければ
                   ベクトル・行列→代数学、幾何学
                   アフィン変換→幾何学
                   微分積分→解析学 らへん




12年11月17日土曜日
これでOK!!



12年11月17日土曜日
ありがとうございました
               •   大雑把な内容過ぎてごめんなさい

               •   tmokita at gmail.com
               •   @tmokita



12年11月17日土曜日

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Wtidev0227 tmokita

  • 1. 3DBasics @tmokita 12年11月17日土曜日
  • 2. 自己紹介 • 沖田知彦 @tmokita • 以前はゲームとか組み込みとか • 今はフリーランスでiPhoneアプリ その他いろいろ 12年11月17日土曜日
  • 3. ざっくり内容 • 小難しい計算の説明はしません • 3Dのとっかかりに必要な用語を説明する ので興味をもったら調べてください • 計算とか用語などにつまずかないで 頭のなかでイメージできるかが大事 • なので3D概論入門みたいな内容です 12年11月17日土曜日
  • 4. 目次 • 用語とかの基礎知識 • サンプルデモ、説明 • プログラムするときのポイント 的な • Appendix 12年11月17日土曜日
  • 5. なんで3Dに見えるのか? • 2D:奥行きが無い • 3D:奥行きがある • 一点透視 • つまりは 比 の計算 12年11月17日土曜日
  • 6. ベクトル こんなのとか こんなの 12年11月17日土曜日
  • 7. ベクトル • 3次元ベクトルまでイメージできればOK • x,y,z 成分で構成されるベクトル • 数学的にはn次元ベクトルというものがある が、まあ別に知らなくてもOK • ベクトルの計算は、加算、減算、 長さ、内積、外積、ノーマライズ、位わかって ればOK 12年11月17日土曜日
  • 10. 行列 • 4x4行列までわかっていればOK • 横が行、縦が列 • 単位行列、逆行列、転置行列 • 行列の計算は 加算、減算、乗算、が分かっていればOK • 乗算するには条件がある 12年11月17日土曜日
  • 11. 行列 • 単位行列:数字の1と同じ:e • どんな行列に掛けても元と同じ • 逆行列:A-1 • かけたら単位行列になる行列 • 転置行列:A t • x成分とy成分を交換した行列 12年11月17日土曜日
  • 12. ベクトルと行列の関係 • 行列はベクトルを並べたもの • ベクトルは行列の一種 • ベクトルと行列は計算できる • 1 3 行列と 3 3 行列は計算できる • 結果は 1 3 行列になる 12年11月17日土曜日
  • 13. ちょっとだけ • (1,1)を45度回転させる 12年11月17日土曜日
  • 15. 頂点 • 3D空間における座標(位置)を 表したベクトル • x,y,z、または x,y,z,w で表す • とりあえず最初のうちはwは オマケ程度に考えておけばOK • 「wってなにそれwwww」くらいで 12年11月17日土曜日
  • 17. 法線 • ある線や面に対して垂直なベクトル • 線に垂直:傾きを掛けると-1になる • 面に垂直:2辺の外積を求める • 主に光源ベクトルとの内積を求めて 明るさの計算につかう 12年11月17日土曜日
  • 19. 光源 • 環境光(Ambient) 距離や向きに関係なく当たる光 • 点光源(Point) 距離は関係なく一点から球状に放出される光 • 平行光(Directional) 距離は関係なく平行して放出される当たる光 • スポット光(Spot) 距離は関係なく円錐状に放出される光(スポットライト) 12年11月17日土曜日
  • 21. 陰と影 • 陰:シェード(Shade) • 影:シャドウ(Shadow) 12年11月17日土曜日
  • 22. シェーディング 左:フラット 右:グーロー 左:フラット 右:フォン 12年11月17日土曜日
  • 23. シェーディング • フラットシェーディング:面単位 • 法線情報は面ごと • グーローシェーディング:頂点単位 • 法線情報は頂点ごと • フォンシェーディング:ピクセル単位 • 法線情報はピクセルごと 12年11月17日土曜日
  • 24. フレームバッファ Zバッファ(デプスバッファ) • フレームバッファ: ピクセルを描画するバッファ • Zバッファ、デプスバッファ: 奥行き情報を描画するバッファ →奥行きを考慮して描画する為に必要 12年11月17日土曜日
  • 25. マテリアル • マテリアル(material):質感 描画するときのパラメータ • 色、テクスチャ情報、 光源計算に関するパラメータ など • Diffuse,Specular,Emmisive とかとか 12年11月17日土曜日
  • 26. 座標系 • 右手座標系:Zが手前 OpenGL など • 左手座標系:Zが奥 Direct3D など 12年11月17日土曜日
  • 27. カメラ(視点) • 「見える」時の情報 • 視点の位置 • アスペクト比、画角 などなど 12年11月17日土曜日
  • 28. ニアクリップ ファークリップ 12年11月17日土曜日
  • 29. ニアクリップ ファークリップ • ニア(near)クリップ: これ以上手前のものは描画しない • ファー(far)クリップ これ以上奥のものは描画しない 12年11月17日土曜日
  • 31. ぽいんと1 • ぱくる(INSPIRE、RESPECT) • 表示させないと楽しくないのでとりあ えずなんか表示できるようなコードを 参考にして自分のモデルとかを表示さ せて回転させたり拡縮させたりしてみ る 12年11月17日土曜日
  • 32. ぽいんと2 • OpenGLとかDirectXとか使えば大抵勝手に計算して くれるので小難しい計算(透視変換とか回転行列の 計算など)を自前でやる必要はないです • むしろハードのスペックを活かしたい場合は下手な コード書くよりはライブラリをフルに使う方がいい 結果がでます • iPhoneならiOSHacksなどに載っているARMのコード 使えば速くなるかも 12年11月17日土曜日
  • 34. 3Dプログラムの流れ • レンダリング・Zバッファの作成 • カメラ(視点)の設定 • ライティングするなら:光源の設定 • 頂点や法線の設定 • 描画 12年11月17日土曜日
  • 36. ポイント1 PG • 可能なものは先に全部計算しておく • というかデータを最適化しておく • OpenGLに対応した頂点配列 • 法線情報 などなど 12年11月17日土曜日
  • 37. ポイント2 PG • マテリアル毎に描画する • テクスチャの切り替えなどは負荷が大 きいため同じテクスチャのものは一気 に描画する 12年11月17日土曜日
  • 38. ポイント3 ここからはやってないですゴメンなさい PG • TRIANGLESよりSTRIPをつかう 頂点情報を減らすため • ダミーの頂点をはさんでSTRIPで一気に 描画する • 一般的に描画命令が一番処理が重いの でその呼出し回数を出来る限り減らす 12年11月17日土曜日
  • 39. ポイント4 Designer • 頂点、面 などのデータを減らす • ライティングもテクスチャで代用 • 透明度のあるものを減らす • 半透明のモノを描画する時は順番を 考える 12年11月17日土曜日
  • 40. ポイント5 PG/Designer • そもそも見えないものは描画しない • 完全に透明なもの • 明らかに画面からはみ出している だろうと思われるもの 12年11月17日土曜日
  • 41. Appendix • アニメーションさせたい場合 →クウォータニオン(四元数、複素数)っていうものがあるよ →ボーン、ウェイトの計算をする必要があるよ • 影(本気)をつけたい場合 →ステンシルバッファっていうものがあるよ • 影(擬似)をつけたい場合 →射影行列っていうものがあるよ • まじめに数学勉強したければ ベクトル・行列→代数学、幾何学 アフィン変換→幾何学 微分積分→解析学 らへん 12年11月17日土曜日
  • 43. ありがとうございました • 大雑把な内容過ぎてごめんなさい • tmokita at gmail.com • @tmokita 12年11月17日土曜日