ã¹ã ãŒãžã³ã°
3次å ã¬ã³ããªã³ã°ã®ç 究ã§ã¯ãããããã¬ã³ããªã³ã°ãããã¢ãã«ã®ãšããžã«æ²¿ã£ãŠãã¯ã»ã«åããããããã®å€èŠ³ã«åºããããŸããã ãããã®ããŒã¯ã¯ãOpenGLãã€ãã©ã€ã³ã®æ·±ãã®ã©ããã«ããã©ã¹ã¿ã©ã€ã¶ãŒã«ãã£ãŠé ç¹ããŒã¿ãã¹ã¯ãªãŒã³ãã©ã°ã¡ã³ãã«å€æããåçã«ãããå¿ ç¶çã«è¡šç€ºãããŸãã ããšãã°ãç«æ¹äœã®ãããªåçŽãªå³ã§ãã£ãŠãããããã®ã¢ãŒãã£ãã¡ã¯ãã¯ãã§ã«é¡èã§ãã
ãã£ãšèŠãã ãã§ã¯äœãæ°ã¥ããªããããããŸããããããèŠã䟡å€ããããããŒã¯ããããããããã¥ãŒãã®ç«¯ã«è¡šç€ºãããŸãã ç»åãæ¡å€§ããŠã¿ãŸãããïŒ
ããããããã¯ãã¡ã§ãã ã¢ããªã±ãŒã·ã§ã³ã®ãªãªãŒã¹ããŒãžã§ã³ã§ãã®ãããªç»è³ªãæ¬åœã«èŠããã§ããïŒ
å
容
ããŒã1.ã¯ããã«
ããŒã2.åºæ¬çãªç §æ
ããŒã3. 3Dã¢ãã«ãããŠã³ããŒããã
ããŒã4.é«åºŠãªOpenGLæ©èœ
ããŒã5.é«åºŠãªç §æ
ããŒã6. PBR
- Opengl
- ãŠã£ã³ããŠäœæ
- ããã«ã¡ã¯ãŠã£ã³ããŠ
- ããã«ã¡ã¯ãã©ã€ã¢ã³ã°ã«
- ã·ã§ãŒããŒ
- ãã¯ã¹ãã£ãŒ
- å€æ
- 座æšç³»
- ã«ã¡ã©
ããŒã2.åºæ¬çãªç §æ
ããŒã3. 3Dã¢ãã«ãããŠã³ããŒããã
ããŒã4.é«åºŠãªOpenGLæ©èœ
- 深床ãã¹ã
- ã¹ãã³ã·ã«ãã¹ã
- è²æ··å
- é¡ã®ã¯ãªããã³ã°
- ãã¬ãŒã ãããã¡
- ãã¥ãŒããã¯ã«ãŒã
- é«åºŠãªããŒã¿åŠç
- é«åºŠãªGLSL
- 幟äœåŠã·ã§ãŒããŒ
- ã€ã³ã¹ã¿ã³ã¹å
- ã¹ã ãŒãžã³ã°
ããŒã5.é«åºŠãªç §æ
- é«åºŠãªç §æã Blinn-Fongã¢ãã«ã
- ã¬ã³ãè£æ£
- ã·ã£ããŠã«ãŒã
- å šæ¹åã·ã£ããŠããã
- æ³ç·ãããã³ã°
- èŠå·®ãããã³ã°
- HDR
- ãã«ãŒã
- é 延ã¬ã³ããªã³ã°
- SSAO
ããŒã6. PBR
ãªããžã§ã¯ãã®ç«¯ã§ã®ãã¯ã»ã«ããšã®ç»åæ§é ã®èŠããã®å¯èŠæ§ã®å¹æã¯ããšã€ãªã¢ã·ã³ã°ãšåŒã°ããŸãã ã³ã³ãã¥ãŒã¿ãŒã°ã©ãã£ãã¯ã¹æ¥çã§ã¯ãã¢ã³ããšã€ãªã¢ã·ã³ã°ãŸãã¯ã¢ã³ããšã€ãªã¢ã·ã³ã°ãã¯ããã¯ãšåŒã°ããå€ãã®ãã¯ããã¯ããã§ã«èç©ããŠããããããã®ãã¯ããã¯ã¯ãªããžã§ã¯ãã®å¢çã§ã®ã¹ã ãŒãºãªãã©ã³ãžã·ã§ã³ãå¯èœã«ãããã®å¹æã«èŠåŽããŠããŸãã
ãã®ãããããšãã°ãæåã®1ã€ã¯ã¹ãŒããŒãµã³ããªã³ã°ïŒ ã¹ãŒããŒãµã³ããªã³ã°ã¢ã³ããšã€ãªã¢ã·ã³ã° ã SSAA ïŒã®ææ³ã§ãã ã å®è£ ã¯2ã€ã®ãã¹ã§å®è¡ãããŸããæåã«ãã¬ã³ããªã³ã°ã¯ç»é¢ãããæããã«é«ã解å床ã§ãªãã¹ã¯ãªãŒã³ãã¬ãŒã ãããã¡ãŒã«éãããŸãã ãã®åŸãç»åã¯ç»é¢ãã¬ãŒã ãããã¡ã«çž®å°ããŠè»¢éãããŸããã 解å床ã®éãã«ãããã®ããŒã¿ã®åé·æ§ã¯ãšã€ãªã¢ã·ã³ã°å¹æãäœæžããããã«äœ¿çšãããã¡ãœããã¯å®å šã«æ©èœããŸãããã1ã€ã®ãããããããã©ãŒãã³ã¹ããããŸããã é«è§£å床ã§ã®ã·ãŒã³ã®çµè«ã¯ãGPUãé©åã«äœ¿çšãããã®ãã¯ãããžãŒã®æ å ã®æ代ã¯çåœã§ããã
ããããå€ãæè¡ã®ç°ãããããé«åºŠãªæ°ãããã®ãçãŸããŸããã ãã«ããµã³ããªã³ã°ã¢ã³ããšã€ãªã¢ã·ã³ã° ïŒ MSAA ïŒã§ãã SSAAã®ã¢ã€ãã¢ã«åºã¥ããŠããŸãããããå¹æçãªæ¹æ³ã§ããããå®è£ ããŸãã ãã®ã¬ãã¹ã³ã§ã¯ãOpenGLã§ãã€ãã£ãã«å©çšå¯èœãªMSAAã¢ãããŒãã詳ããèŠãŠãããŸãã
ãã«ããµã³ããªã³ã°
ãã«ããµã³ããªã³ã°ã®æ¬è³ªãšãã®ä»çµã¿ãç解ããã«ã¯ããŸãOpenGLã®æ¬è³ªãæ·±ãæãäžããŠãã©ã¹ã¿ã©ã€ã¶ã®æ©èœã調ã¹ãå¿ èŠããããŸãã
ã©ã¹ã¿ã©ã€ã¶ã¯ãæçµçã«åŠçãããé ç¹ããŒã¿ãšãã©ã°ã¡ã³ãã·ã§ãŒãã®éã«äœçœ®ããè€éãªã¢ã«ãŽãªãºã ãšæé ã§ãã ã©ã¹ã¿ã©ã€ã¶ã¯ãå ¥åã«ããªããã£ãã«é¢é£ãããã¹ãŠã®é ç¹ãåãåãããã®ããŒã¿ãäžé£ã®ãã©ã°ã¡ã³ãã«å€æããŸãã çè«çã«ã¯ãé ç¹åº§æšã¯çµ¶å¯Ÿã«ä»»æã§ããããã©ã°ã¡ã³ãã®åº§æšã§ã¯ãããŸãã-åºåããã€ã¹ã®è§£å床ãšãŠã£ã³ããŠãµã€ãºã«ãã£ãŠå³å¯ã«å¶éãããŸãã ããªããã£ãã®é ç¹ã®åº§æšããã©ã°ã¡ã³ãäžã§1ã€ãã€éãªãããšã¯ã»ãšãã©ãããŸããïŒäœããã®æ¹æ³ã§ãã©ã¹ã¿ã©ã€ã¶ãŒã¯ãåãã©ã°ã¡ã³ããã©ã®ãã©ã°ã¡ã³ãã§ã©ã®åº§æšã«ããããäœããã®æ¹æ³ã§æ±ºå®ããå¿ èŠããããŸãã
ãã®ç»åã¯ãç»é¢ã®ãã¯ã»ã«ãè¡šãã°ãªããã瀺ããŠããŸãã ãããã®ããããã®äžå¿ã«ã¯ãç¹å®ã®ãã¯ã»ã«ãäžè§åœ¢ãã«ããŒãããã©ããã決å®ããããã«äœ¿çšããããµã³ããªã³ã°/ãµã³ããªã³ã°ãã€ã³ãããããŸãã äžè§åœ¢ã§èŠããããµã³ãã«ãã€ã³ãã¯èµ€ã§ããŒã¯ãããŸã-ãããã®å Žåãã©ã¹ã¿ã©ã€ã¶ãŒã¯å¯Ÿå¿ãããã©ã°ã¡ã³ããçæããŸãã äžè§åœ¢ã®ãšããžã¯ããã€ãã®ãã¯ã»ã«ãšéè€ããŠããŸããããµã³ããªã³ã°ãã€ã³ããšã¯éè€ããŠããŸãããããã§ã¯ããã®ãã¯ã»ã«ã«å¯ŸããŠãã©ã°ã¡ã³ãã¯äœæãããããã©ã°ã¡ã³ãã·ã§ãŒããŒã¯å®è¡ãããŸããã
ããªãã¯ãã§ã«ãšã€ãªã¢ã·ã³ã°ã®çç±ãæšæž¬ããŠãããšæããŸãã ç»é¢äžã®ãã®äžè§åœ¢ã®ã¬ã³ããªã³ã°ã¯æ¬¡ã®ããã«ãªããŸãã
ç»é¢äžã®ãã¯ã»ã«æ°ã«ã¯éãããããããäžè§åœ¢ã®ãšããžã«æ²¿ã£ãäžéšã¯å¡ãã€ã¶ãããäžéšã¯å¡ãã€ã¶ãããŸããã ãã®çµæãããªããã£ãã¯æ»ãããªãšããžã§ãŸã£ããã¬ã³ããªã³ã°ãããããããã®åœ¢ã§çŸããŸãã
ãã«ããµã³ããªã³ã°ã䜿çšããå Žåãäžè§åœ¢ã«ãããã¯ã»ã«ã®ãªãŒããŒã©ããã決å®ããããã«1ã€ã®ãã€ã³ãã䜿çšãããã®ã§ã¯ãªããè€æ°ã®ãã€ã³ãã䜿çšãããŸãïŒãã®ããååãä»ããããŸãïŒã ãã¯ã»ã«ã®äžå¿ã«ãã1ã€ã®ãµã³ããªã³ã°ãã€ã³ãã®ä»£ããã«ãç¹å®ã®ãã¿ãŒã³ã«ãã4ã€ã®ãµããµã³ããªã³ã°ãã€ã³ãã䜿çšããŠããªãŒããŒã©ããã決å®ãããŸãã ãã®çµæãã«ã©ãŒãããã¡ãŒã®ãµã€ãºã4åã«ãªããŸãïŒäœ¿çšãããµã³ãã«ãã€ã³ãã®æ°ã«é¢ããŠïŒã
å·ŠåŽã¯ããªãŒããŒã©ããã決å®ããããã®æšæºçãªã¢ãããŒãã§ãã ãã©ã°ã¡ã³ãã·ã§ãŒããŒã¯ãéžæãããã¯ã»ã«ã«å¯ŸããŠå®è¡ãããããªãŒããŒã©ãããç»é²ãããªãã£ãããããã€ã³ããããªããŸãŸã«ãªããŸãã å³åŽã¯ãã«ããµã³ããªã³ã°ã®å Žåã§ãåãã¯ã»ã«ã«ã¯4ã€ã®ãµããµã³ãã«ãã€ã³ããå«ãŸããŠããŸãã ããã§ã¯ãäžè§åœ¢ã2ã€ã®ãµããµã³ãã«ãã€ã³ãã®ã¿ã«éãªã£ãŠããããšãããããŸãã
ãµããµã³ãã«ãã€ã³ãã®æ°ã¯ãç¹å®ã®å¶éå ã§å€æŽã§ããŸãã ããå€ãã®ããã-ããè¯ãã¹ã ãŒãžã³ã°å質ããã®ç¬éãããèµ·ãããã¹ãŠãããèå³æ·±ããã®ã«ãªããŸãã 2ã€ã®ãã¯ã»ã«ã®ãµããµã³ããªã³ã°ãã€ã³ããäžè§åœ¢ã§èŠãããŠãããšå€æãããããã®ãã¯ã»ã«ã®æçµè²ã衚瀺ããå¿ èŠããããŸãã æåã®æšæž¬ã¯ãäžè§åœ¢ã§ãªãŒããŒã©ããããåãµããµã³ããªã³ã°ãã€ã³ãã«å¯ŸããŠãã©ã°ã¡ã³ãã·ã§ãŒããŒãå®è¡ãããã¯ã»ã«å ã®ãµããµã³ãã«ãã€ã³ãå šäœã®è²ãå¹³åããããšã§ãã ãã®å Žåãé ç¹ããŒã¿ããµããµã³ãã«ã®åãªãŒããŒã©ãããã€ã³ãã®åº§æšïŒãã®äŸã§ã¯2åïŒã«è£éããŠãã©ã°ã¡ã³ãã·ã§ãŒããŒãæ°åå®è¡ãããããã®ãã€ã³ãã§çµæã®è²ãä¿åããå¿ èŠããããŸãã 幞ããªããšã«ãå®éã«ã¯ããã«ããµã³ããªã³ã°ããã»ã¹ã¯ãã®ããã«ã¯æ©èœããŸãããããããªããšããã©ã°ã¡ã³ãã·ã§ãŒããŒã«å¯ŸããŠããªãã®æ°ã®è¿œå åŒã³åºããè¡ãå¿ èŠããããããã©ãŒãã³ã¹ã«å€§ããªåœ±é¿ãäžããŸãã
å®éãMSAAã䜿çšããå Žåãããªããã£ãã«ãã£ãŠéãããããµã³ãã«ãã€ã³ãã®æ°ã«é¢ä¿ãªãããã©ã°ã¡ã³ãã·ã§ãŒããŒã¯1åã ãå®è¡ãããŸãã ãã©ã°ã¡ã³ãã·ã§ãŒããŒã¯ããã¯ã»ã«ã®äžå¿ã«è£éãããé ç¹ããŒã¿ã䜿çšããŠå®è¡ããããã®å®è¡äžã«ååŸãããè²ã¯ãããªããã£ãã«ãã£ãŠæç»ãããåãµã³ãã«ãã€ã³ãã«æ ŒçŽãããŸãã ãã¬ãŒã ãããã¡ãµããµã³ãã«ã®ãã¹ãŠã®ãã€ã³ãããæç»ããããªããã£ãã®è²ã§å¡ãã€ã¶ããããšããã¯ã»ã«ããšã®åäžå€ãžã®è²ã®ãã¯ã»ã«ããšã®å¹³ååãè¡ãããŸãã ãã®äŸã§ã¯ã2ã€ã®ãµããµã³ãã«ãã€ã³ãã®ã¿ããªãŒããŒã©ãããããããã£ãŠãäžè§åœ¢ã®è²ã§å¡ãã€ã¶ãããŠããŸãã æ®ãã®2ã€ã¯éæãªèæ¯è²ã§å¡ãã€ã¶ãããŸããã ãããã®ãµããµã³ãã«ã®è²ãæ··åãããšãæããéè²ãåŸãããŸãã
çµæãšããŠã®ãã¬ãŒã ãããã¡ã«ã¯ãããæ»ãããªãšããžãæã€ããªããã£ãã®ç»åãå«ãŸããŠããŸãã ãã§ã«éŠŽæã¿ã®ããäžè§åœ¢ã®ãµããµã³ãã«ã®ã«ãã¬ããžã®å®çŸ©ãã©ã®ããã«ãªããã確èªããŠãã ããã
åãã¯ã»ã«ã«ã¯4ã€ã®ãµããµã³ãã«ãã€ã³ããå«ãŸããŠããããšãããããŸãïŒãã®äŸã§ã¯éèŠã§ã¯ãªããã¯ã»ã«ã¯ç©ºçœã®ãŸãŸã§ãïŒãäžè§åœ¢ã®ãµããµã³ãã«ãã€ã³ãã§èŠãããéãšãèŠãããŠããªãç°è²ã ãã¹ãŠã®ãã¯ã»ã«ã®äžè§åœ¢ã®åšå²ã§ããã©ã°ã¡ã³ãã·ã§ãŒããŒã1ååŒã³åºããããã®çµæã4ã€ã®ãµããµã³ãã«ãã¹ãŠã«ä¿åãããŸãã é¢ã§ã¯ããã¹ãŠã®ãµããµã³ãã«ãã«ããŒãããããã§ã¯ãªãããããã©ã°ã¡ã³ãã·ã§ãŒããŒã®çµæã¯ãã®äžéšã«ã®ã¿ä¿åãããŸãã äžè§åœ¢ã§èŠãããŠãããµããµã³ãã«ãã€ã³ãã®æ°ã«å¿ããŠããã¯ã»ã«ã®æçµçãªè²ã¯ãäžè§åœ¢èªäœã®è²ãšãµããµã³ãã«ãã€ã³ãã«ä¿åãããŠããä»ã®è²ã«åºã¥ããŠæ±ºå®ãããŸãã
ç°¡åã«èšãã°ãäžè§åœ¢ã§èŠããããµããµã³ãã«ãå€ãã»ã©ããã¯ã»ã«ã®è²ã¯äžè§åœ¢ã®è²ãšäžèŽããŸãã ãã«ããµã³ããªã³ã°ã䜿çšããã«äžè§åœ¢ã®äŸãšåãæ¹æ³ã§ãã¯ã»ã«ã®è²ãå¡ãã€ã¶ããšã次ã®å³ã衚瀺ãããŸãã
ã芧ã®ãšãããäžè§åœ¢ã«å±ãããã¯ã»ã«ãµããµã³ãã«ãå°ãªãã»ã©ããã®è²ã¯äžè§åœ¢ã®è²ã«å¯Ÿå¿ããªããªããŸãã äžè§åœ¢ã®éãå¢çã¯ããããã«æãã圱ã®ãã¯ã»ã«ã§å²ãŸããŠãããããé ãããèŠããšæ»ããã«ãªããŸãã
ãã ããè²å€ã ãããã«ããµã³ããªã³ã°ã¢ã«ãŽãªãºã ã®åäœã®å¯Ÿè±¡ã§ã¯ãããŸããã深床ãããã¡ãšã¹ãã³ã·ã«ãããã¡ã¯ããã¯ã»ã«ã«è€æ°ã®ãµããµã³ãã«ã䜿çšãå§ããŸãã 深床ãã¹ããå®è¡ããåã«ããµããµã³ãã«ãã€ã³ãããšã«é ç¹æ·±åºŠå€ãè£éãããŸãã ã¹ãã³ã·ã«å€ã¯ãã¯ã»ã«å šäœã§ã¯ãªãããµããµã³ãã«ãã€ã³ãããšã«ä¿åãããŸãã ç§ãã¡ã«ãšã£ãŠãããã¯ã䜿çšããããµããµã³ãã«ã®æ°ã«å¿ããŠããããã®ãããã¡ãå æããã¡ã¢ãªãå¢å ããããšãæå³ããŸãã
ããã§ã¯ããã«ããµã³ããªã³ã°ã®ä»çµã¿ã®åºæ¬ã«ã€ããŠèª¬æããŸããã ã©ã¹ã¿ã©ã€ã¶ã®çã®å éšããžãã¯ã¯ãããã§èª¬æããã¬ãã¥ãŒãããè€éã«ãªããŸãã ãã ãããã«ããµã³ããªã³ã°ã®åçãšåäœãäžè¬çã«ç解ããããã«ã¯ãããã§ååã§ãã
OpenGLã§ã®ãã«ããµã³ããªã³ã°
OpenGLã§ãã«ããµã³ããªã³ã°ã䜿çšããã«ã¯ããã¯ã»ã«ããšã«è€æ°ã®ã«ã©ãŒå€ãä¿åã§ããã«ã©ãŒãããã¡ãŒã䜿çšããå¿ èŠããããŸãïŒMSAAã¯ãµããµã³ãã«ãã€ã³ãã«ã«ã©ãŒå€ãä¿åããããšãæå³ããŸãïŒã ãããã£ãŠãæå®ãããæ°ã®ãµããµã³ãã«ãä¿åã§ããç¹å¥ãªã¿ã€ãã®ãããã¡ãŒãã€ãŸããã«ããµã³ãã«ãããã¡ãŒãå¿ èŠã§ãã
ã»ãšãã©ã®ãŠã£ã³ããŠã·ã¹ãã ã§ã¯ãæšæºã®ã«ã©ãŒãããã¡ãŒã®ä»£ããã«ãã«ããµã³ãã«ãããã¡ãŒã䜿çšã§ããŸãã GLFWã«ããã®æ©èœããããŸããå¿ èŠãªã®ã¯ãæšæºã®ä»£ããã«Nåã®ãµããµã³ãã«ãã€ã³ããæã€ãããã¡ãŒã䜿çšããããšãåžæããããšã瀺ãç¹å¥ãªãã©ã°ãèšå®ããããšã ãã§ãã
glfwWindowHint(GLFW_SAMPLES, 4);
ããã§glfwCreateWindowãåŒã³åºããšãç»é¢åº§æšããšã«4ã€ã®ãµããµã³ãã«ãæ ŒçŽããã«ã©ãŒãããã¡ãŒãåããåºåãŠã£ã³ããŠãäœæãããŸãã GLFWã¯ããã¯ã»ã«ããšã«åã4ã€ã®ãµããµã³ãã«ãã€ã³ãã䜿çšããŠã深床ãããã¡ãŒãšã¹ãã³ã·ã«ãããã¡ãŒãèªåçã«äœæããŸãã ãŸããäžèšã®åãããã¡ãŒã®ãµã€ãºã¯4åã«ãªããŸãã
GLWLã«ãã£ãŠãã«ããµã³ãã«ãããã¡ãŒãäœæããåŸãOpenGLã§æ¢ã«ãã«ããµã³ããªã³ã°ã¢ãŒããæå¹ã«ããããã«æ®ããŸãã
glEnable(GL_MULTISAMPLE);
ã»ãšãã©ã®OpenGLãã©ã€ããŒã§ã¯ãããã©ã«ãã§ãã«ããµã³ããªã³ã°ãã¢ã¯ãã£ãã«ãªã£ãŠããããããã®åŒã³åºãã¯åé·ã«ãªããŸãããå¿ èŠãªæ©èœãæ瀺çã«å«ããããšã¯è¯ãããŒã³ã§ãããããã«ããããã©ã«ãã®å®è£ ã«é¢ä¿ãªãã¢ãŒããæå¹ã«ãªããŸãã
å®éããã«ããµã³ãã«ãããã¡ãŒã泚æããŠã¢ãŒãããªã³ã«ãããšããã¹ãŠã®äœæ¥ãå®äºããŸããæ®ãã¯ãã¹ãŠOpenGLã©ã¹ã¿ã©ã€ã¶ãŒã®ã¡ã«ããºã ã«åœãŠã¯ãŸããåå ããªããŠãçºçããããã§ãã ã¬ãã¹ã³ã®æåããããªãã¿ã®ç·ã®ç«æ¹äœãåŒãåºãããšãããšããã®é¢ãããæ»ããã«ãªã£ãŠããããšãããããŸãã
å®éããã®ç«æ¹äœã®ç«¯ã¯ã¯ããã«é åçã«èŠããŸãã ãŸããåãå¹æãã·ãŒã³å ã®ãªããžã§ã¯ãã«åœ±é¿ããŸãã
äŸã®ãœãŒã¹ã³ãŒãã¯ãã¡ãã§ãã
ãªãã¹ã¯ãªãŒã³ãã«ããµã³ããªã³ã°
GLFWã®ãããã§ãMSAAãæå¹ã«ããŠåºæ¬çãªãã¬ãŒã ãããã¡ãŒãäœæããã®ã¯ç°¡åãªäœæ¥ã§ãã ããšãã°ããªãã¹ã¯ãªãŒã³ã¬ã³ããªã³ã°çšã«ç¬èªã®ãããã¡ãäœæããå Žåã¯ããã®ããã»ã¹ãèªåã®æã§è¡ãå¿ èŠããããŸãã
ãã¬ãŒã ãããã¡ã«ããã«ã¢ã¿ããããããã®ãã«ããµã³ããªã³ã°ã§ãããã¡ãäœæããã«ã¯ã察å¿ããã¬ãã¹ã³ããæ¢ã«è§£æããããã®ãšåæ§ã«ããã¯ã¹ãã£ã¢ã¿ããã¡ã³ããšã¬ã³ããŒã¿ã€ãã¢ã¿ããã¡ã³ãã®2ã€ã®äž»ãªæ¹æ³ããããŸãã
ãã«ããµã³ããªã³ã°ãã¯ã¹ãã£ã¢ã¿ããã¡ã³ã
è€æ°ã®ãµããµã³ãã«ããµããŒããããã¯ã¹ãã£ãäœæããã«ã¯ãéåžžã®glTexImage2Dã®ä»£ããã«ããã¯ã¹ãã£ã¿ãŒã²ããã¿ã€ãGL_TEXTURE_2D_MULTISAPLEãšé¢æ°glTexImage2DMultisampleã䜿çšããŸãã
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex); glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGB, width, height, GL_TRUE); glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
2çªç®ã®åŒæ°ã¯ãäœæããããã¯ã¹ãã£å ã®ãµããµã³ãã«ã®æ°ã瀺ããŸãã æåŸã®åŒæ°ãGL_TRUEã«èšå®ãããŠããå Žåããã¯ã¹ãã£ã¯åãã¯ã»ã«ã«å¯ŸããŠåãæ°ãšãµããµã³ãã«ãã€ã³ãã®äœçœ®ã䜿çšããŸãã
ãã®ãããªãã¯ã¹ãã£ããã¬ãŒã ãããã¡ãªããžã§ã¯ãã«ã¢ã¿ããããã«ã¯ãåãglFramebufferTexture2DåŒã³åºãã䜿çšãããŸãããä»åã¯æå®ããããã¯ã¹ãã£ã¿ã€ãGL_TEXTURE_2D_MULTISAMPLEã䜿çšããŸãã
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0);
ãã®çµæãçŸåšã®ãã¬ãŒã ãããã¡ãŒã«ã¯ããã«ããµã³ããªã³ã°ããµããŒããããã¯ã¹ãã£ããŒã¹ã®ã«ã©ãŒãããã¡ãŒãæäŸãããŸãã
ãã«ããµã³ããªã³ã°ã¬ã³ãã©ãŒ
è€æ°ã®ãµããµã³ãã«ãã€ã³ãã§ã¬ã³ããŒãããã¡ãŒãäœæããããšã¯ããã®ãããªãã¯ã¹ãã£ãäœæããããšãšåããããé£ãããããŸããã ããã«ãããã«ç°¡åã§ããçŸåšãã€ã³ããããŠããã¬ã³ããŒãªããžã§ã¯ãã®ã¡ã¢ãªãæºåãããšãã«ã glRenderbufferStorageã®åŒã³åºããglRenderbufferStorageMultisampleã«å€æŽããã ãã§ãã
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH24_STENCIL8, width, height);
ããã§ã®æ°ãããã®ããããµã³ãã«ãã€ã³ãã®æ°ã瀺ããã¬ã³ããŒãããã¡ãŒã®ã¬ã³ããŒã¿ãŒã²ããã®ã¿ã€ãã®åŸã«æ¥ãè¿œå ãã©ã¡ãŒã¿ãŒã1ã€ã ããããŸãã ããã§ã¯ããã®ãããª4ã€ã®ãã€ã³ãã瀺ããŸããã
ãã«ããµã³ããªã³ã°ã§ãã¬ãŒã ãããã¡ãŒã«ã¬ã³ããªã³ã°ãã
ãã«ããµã³ãã«ãã¬ãŒã ãããã¡ãŒãžã®ã¬ã³ããªã³ã°ã¯èªåçã«è¡ãããå¿ èŠãªã¢ã¯ã·ã§ã³ã¯å¿ èŠãããŸããã ã¢ã¿ããããããã¬ãŒã ãããã¡ãŒã«ã¬ã³ããªã³ã°ãããã³ã«ãã©ã¹ã¿ã©ã€ã¶ãŒèªäœãå¿ èŠãªæäœãå®è¡ããŸãã ãããŠãåºåã«å€ãã®ãµããµã³ãã«ãã€ã³ããæã€ã«ã©ãŒãããã¡ãŒïŒæ·±ããã¹ãã³ã·ã«ïŒãååŸããŸãã å€ãã®ãµããµã³ããªã³ã°ãã€ã³ããæã€ãã¬ãŒã ãããã¡ãŒã¯éåžžã®ãã®ãšå€å°ç°ãªããããã·ã§ãŒããŒã§ã®ãã¯ã¹ãã£ãµã³ããªã³ã°ãªã©ã®ããŸããŸãªæäœã«åå¥ã®ãããã¡ãŒãçŽæ¥äœ¿çšããããšã¯ã§ããŸããã
ãã«ããµã³ããªã³ã°ããµããŒãããç»åã«ã¯éåžžãããå€ãã®æ å ±ãå«ãŸããŠããããããã®ç»åã解決ããããã€ãŸã解å床ãããå°ããªãã®ã«å€æããå¿ èŠããããŸã ã ãã®æäœã¯ãéåžžã©ããglBlitFramebufferãåŒã³åºãããšã§å®è¡ãããŸããããã«ãããå€ãã®ãµã³ãã«ãã€ã³ããæã€çŸåšã®ãããã¡ãŒã«é¢é£ä»ãããã解å床ã§ã1ã€ã®ãã¬ãŒã ãããã¡ãŒã®é åãå¥ã®ãã¬ãŒã ãããã¡ãŒã«ã³ããŒã§ããŸãã
ãã®é¢æ°ã¯ãç»é¢ç©ºéã®4ã€ã®åº§æšã§æå®ããããœãŒã¹é åãã4ã€ã®ç»é¢åº§æšã§æå®ãããã¬ã·ãŒããŒé åã«è»¢éããŸãã ãã¬ãŒã ãããã¡ã®ã¬ãã¹ã³ãæãåºãããŠãã ããããã¬ãŒã ãããã¡ãªããžã§ã¯ããGL_FRAMEBUFFERã¿ãŒã²ããã«ãã€ã³ããããšããã¬ãŒã ãããã¡ããã®èªã¿åãã®ã¿ãŒã²ãããšãã¬ãŒã ãããã¡ãžã®æžã蟌ã¿ã®ã¿ãŒã²ããã®äž¡æ¹ã«ãã€ã³ããæé»çã«å®è¡ãããŸãã ãããã®ç®æšã«åå¥ã«ãã€ã³ãããã«ã¯ãç¹å¥ãªã¿ãŒã²ããID GL_READ_FRAMEBUFFERãšGL_DRAW_FRAMEBUFFERããããã䜿çšããŸãã
æäœäžã glBlitFramebufferé¢æ°ã¯ãããã®ã¢ã³ã«ãŒãã€ã³ãã䜿çšããŠãã©ã®ãã¬ãŒã ãããã¡ãŒãç»åã®ãœãŒã¹ã§ãã©ã®ãã¬ãŒã ãããã¡ãŒãã¬ã·ãŒããŒã§ããããå€æããŸãã ãã®çµæãããªããã䜿çšããŠããã«ããµã³ãã«ãã¬ãŒã ãããã¡ãŒããæšæºã«ç»åãç°¡åã«è»¢éã§ããŸãã
glBindFramebuffer(GL_READ_FRAMEBUFFER, multisampledFBO); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ã¢ããªã±ãŒã·ã§ã³ãã¢ã»ã³ãã«ããŠå®è¡ãããšããã¬ãŒã ãããã¡ã䜿çšããŠããªãåã®äŸãšåãç»åãåŸãããŸããMSAAã䜿çšããŠæãããã¢ã·ããã°ãªãŒã³ãã¥ãŒãã¯ããã®é¡ãèŠãããšã§èŠãããšãã§ããŸãã
ãµã³ãã«ã®ãœãŒã¹ã¯ãã¡ãã§ãã
ããããå€ãã®ãµããµã³ãã«ãã€ã³ããæã€ãã¬ãŒã ãããã¡ãŒã®ç»åãåŸåŠçã®ããŒã¿ãœãŒã¹ãšããŠäœ¿çšããå Žåã¯ã©ãããã°ããã§ããããïŒ ã·ã§ãŒããŒã§ãã«ããµã³ãã«ãã¯ã¹ãã£ãçŽæ¥äœ¿çšããããšã¯ã§ããŸããã ãã ãããã«ããµã³ãã«ã§ã¯ãªããéåžžã®ãããã¡ãŒã䜿çšããŠãããªããã䜿çšããŠãã«ããµã³ãã«ãã¬ãŒã ãããã¡ãŒããç»åã転éããããšãã§ããŸãã ãããŠãéåžžã®ç»åãåŸåŠçã®ãªãœãŒã¹ãšããŠäœ¿çšããåºæ¬çã«MSAAã®ãã¹ãŠã®å©ç¹ãåŸãŠããã®äžã«åŸåŠçãè¿œå ã§ããŸãã ã¯ãããã®ããã»ã¹å šäœã§ãMSAAãã¯ã¹ãã£ãã·ã§ãŒããŒã§äœ¿çšã§ããéåžžã®ãã¯ã¹ãã£ã«è§£æ±ºããããã®è£å©ãªããžã§ã¯ããšããŠã®ã¿æ©èœãããå¥åã®ãã¬ãŒã ãããã¡ãŒãäœæããå¿ èŠããããŸãã æ¬äŒŒã³ãŒãã®åœ¢åŒã§ã¯ãããã»ã¹ã¯æ¬¡ã®ããã«ãªããŸãã
unsigned int msFBO = CreateFBOWithMultiSampledAttachments(); // FBO ... glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, screenTexture, 0); ... while(!glfwWindowShouldClose(window)) { ... glBindFramebuffer(msFBO); ClearFrameBuffer(); DrawScene(); // glBindFramebuffer(GL_READ_FRAMEBUFFER, msFBO); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, intermediateFBO); glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_COLOR_BUFFER_BIT, GL_NEAREST); // , glBindFramebuffer(GL_FRAMEBUFFER, 0); ClearFramebuffer(); glBindTexture(GL_TEXTURE_2D, screenTexture); DrawPostProcessingQuad(); ... }
ãã®ã³ãŒãããã¬ãŒã ãããã¡ãŒã®ã¬ãã¹ã³ã®ãã¹ãåŠçã®äŸã«è¿œå ãããšããšããžãã®ã¶ã®ã¶ã«ãªããã«ãããããã¹ãŠã®å¹æãã·ãŒã³ã€ã¡ãŒãžã«é©çšã§ããŸãã ããšãã°ããŒããå¹æã䜿çšãããšã次ã®ããã«ãªããŸãã
1ã€ã®ãµããµã³ãã«ãã€ã³ããæã€æšæºãã¯ã¹ãã£ãåŸåŠçã«äœ¿çšããããããäžéšã®åŠçæ¹æ³ïŒããšãã°ãå¢çç·ã®æ€çŽ¢ïŒã¯ãã·ãŒã³ã«åã³ç®ç«ã€éããšããžãšããããããããå¯èœæ§ããããŸãã ãã®ã¢ãŒãã£ãã¡ã¯ããåé¿ããã«ã¯ãçµæããŒããããã¹ã ãŒãžã³ã°ã¢ã«ãŽãªãºã ãå®è£ ããå¿ èŠããããŸããã芧ã®ãšãããMSAAãšãªãã¹ã¯ãªãŒã³ã¬ã³ããªã³ã°æè¡ã®çµã¿åããã«ã€ããŠã¯ãããã€ãã®è©³çŽ°ãèæ ®ããå¿ èŠããããŸãã ããããäœåãªåŽåã¯ãã¹ãŠãçµæãšããŠåŸãããç»åã®å質ãå€§å¹ ã«åäžããŸãã ãã ãããã«ããµã³ããªã³ã°ãæå¹ã«ãããšãç¹ã«å€æ°ã®ãµããµã³ãã«ãã€ã³ããèšå®ãããŠããå Žåã«ãæçµçãªããã©ãŒãã³ã¹ã«å€§ããªåœ±é¿ãäžããããšã«æ³šæããŠãã ããã
ãã€ãã£ãã¹ã ãŒãžã³ã°æ¹æ³
å®éããã«ããµã³ãã«ãã·ã§ãŒããŒã«çŽæ¥è»¢éããŠãéåžžã®è£å©çãªãã®ã«ããªããããããšã¯ã§ããŸããã ãã®å ŽåãGLSLæ©èœã¯ãã¯ã¹ãã£å ã®åã ã®ãµããµã³ããªã³ã°ãã€ã³ããžã®ã¢ã¯ã»ã¹ãæäŸããç¬èªã®ã¹ã ãŒãžã³ã°ã¢ã«ãŽãªãºã ãäœæããããã«äœ¿çšã§ããŸãïŒå€§èŠæš¡ãªã°ã©ãã£ãã¯ã¢ããªã±ãŒã·ã§ã³ã®å Žåãå€ãïŒã
ãŸããéåžžã®sampler2Dã§ã¯ãªãã sampler2DMSã®ãããªç¹å¥ãªãµã³ãã©ãŒãäœæããå¿ èŠããããŸãã
uniform sampler2DMS screenTextureMS;
ãŸãããµããµã³ãã«ãã€ã³ãã§è²ã®å€ãååŸããã«ã¯ã次ã®é¢æ°ã䜿çšããŸãã
vec4 colorSample = texelFetch(screenTextureMS, TexCoords, 3); // 4
ããã§ãè¿œå ã®åŒæ°-ã¢ã¯ã»ã¹ãããŠãããµããµã³ãã«ãã€ã³ãã®æ°ïŒãŒãããã«ãŠã³ãïŒã確èªã§ããŸãã
ããã§ã¯ãç¹å¥ãªå¹³æ»åã¢ã«ãŽãªãºã ã®äœæã®è©³çŽ°ã«ã€ããŠã¯æ€èšããŸãããããã¯ããã®ãããã¯ã«é¢ããç¬èªã®ç 究ã®åºçºç¹ã«éããŸããã
PS ïŒè»¢éã調æŽããããã®é»å ±confããããŸãã 翻蚳ãæäŒããããšããçå£ãªé¡æãããã°ã倧æè¿ã§ãïŒ