Unityã·ã§ã¼ãå ¥é #004ãReplaced Shader
ãé常ã¦ã¼ã¶ãç·¨éããSurface Shaderã¯ãç»é¢ä¸ã«è¦ããé¨åã®è²ãå½¢ãå¤ãããã¨ãåºæ¥ã¾ããããããã·ã§ã¼ãã使ãããã®ã¯ç´æ¥ç»é¢ã«è¦ããé¨åã ãã§ã¯ããã¾ããã
1.ã·ã£ãã¦ãããã¬ã³ããªã³ã°ç¨ã·ã§ã¼ãï¼å½±ãè½ã¨ãããã®ã·ã§ã¼ãï¼
2.å½±ãã©ããå¤æããããã®ã·ã§ã¼ãï¼å½±ãåããããã®ã·ã§ã¼ãï¼
3.ãã£ãã¡ã¼ãã¬ã³ããªã³ã°ãã¤ã¡ã¼ã¸ã¨ãã§ã¯ãã§ä½¿ããã深度ãæ³ç·ãæç»ããããã®ã·ã§ã¼ã
ãªã©ã§ãã
ãªãããããã®ã·ã§ã¼ãã¯æ·±åº¦ãæ³ç·ãªã©ãåºåãåºå®çã§ãã
ï¼è²ã«æ¯ã¹ã深度ãæ³ç·ãã«ã¹ã¿ãã¤ãºãããã¨ã¯ç¨ã ããã§ãï¼
ãã®ãããã·ã§ã¼ãã®ã¸ã£ã³ã«ãã¨ã«ä¸ã¤ã«ã¾ã¨ãããã¦ãã¾ãã
ãä¸è¨1ã®ã·ã§ã¼ãã§ã¯ã·ã£ãã¦ãããã«æãããããã®æ·±åº¦ãåºåãã¾ãããä¾ãã°
Diffuseã·ã§ã¼ãã®ãªãã¸ã§ã¯ãã¨ãBumpedDiffuseã·ã§ã¼ãã®ãªãã¸ã§ã¯ãã¯è²ãéãã ãã§å½¢ã¯åããªã®ã§ãåã深度ãåºåããã¹ãã§ãããããCutoutã·ã§ã¼ãã®å ´åããã¯ã¹ãã£ã®Î±å¤ã«ãã£ã¦ã¢ãã«ã«ç©´ãéãã®ã§ãå½±ã®å½¢ãããã«ãªãã£ã¦ç©´ãéãã¹ãã§ãã
ãå¾ã£ã¦Diffuse,BumpedDiffuseãªã©åç´ãªä¸éæãªãã¸ã§ã¯ããå½±ãè½ã¨ãããã®ã·ã§ã¼ããCutoutã«ããå½¢ãå¤ãããªãã¸ã§ã¯ããå½±ãè½ã¨ãããã®ã·ã§ã¼ããã®äºç¨®é¡ãåå¨ãããã¨ã«ãªãã¾ãã
ãããããããªã·ã§ã¼ãã¯SurfaceShaderã®ä¸ã«ã¯ããã¾ãããå®è¡ã§ããã·ã§ã¼ããè¦ã¤ãããªãå ´åãUnityã¯Fallbackã«æ¸ããã¦ããã·ã§ã¼ããæ¢ãã«è¡ããããã§ã¾ãå¿
è¦ãªã·ã§ã¼ãï¼ãã¹ï¼ãæ¢ãã¾ãã
ãbuitin-shaderã®Normal-Diffuse.shaderãè¦ã¦ã¿ãã¨ãFallback "VertexLit"ã¨ããè¨è¿°ãããã¾ããUnityã¯ãããè¦ã¦ãVertexLit(Normal-VertexLit.shader)ãæ¢ãã«è¡ãã¾ããããã¨ã"ShadowCaster"ã"ShadowCollector"ã¨ããååãä»ãããã¹ãè¦ã¤ããã¾ãããããUnityãå½±ãè½ã¨ãããå½±ãåãããããã®ã«æ¢ãã¦ããã·ã§ã¼ãï¼ãã¹ï¼ã§ãã
ãDiffuseã·ã§ã¼ãããã¼ã¹ã«ãã¯ã¹ãã£ã®Î±å¤ã使ã£ã¦ã¢ãã«ã«ç©´ãéããå ´åãFallbackãVertexLitã®ã¾ã¾ã«ãã¦ããã¨ãç©´ã®éããªãå½±ãè½ã¨ããã¨ã«ãªãã¾ããç©´ãéããå½±ãè½ã¨ãããå ´åã¯ãFallbckã®å
ã"Transparent/Cutout/VertexLit"ã«ãã¾ãããã®ã·ã§ã¼ããã¡ã¤ã«ã®ä¸ã«ãå½ç¶"ShadowCaster"ã"ShadowCollector"ããããClipã使ã£ã¦ç©´ãéãã¦ãã¾ãã
ãé ç¹ã¢ãã£ãã¡ã¤ã¢ã§ã¢ãã«ã®å½¢ç¶ãå¤ããå ´åï¼æ¨¹æ¨ã®èã£ã±ã®æºãããã«ãã¼ããªã©ï¼ã¯ãã«ã¹ã¿ã ããã"ShadowCaster"ãã¹ã¨"ShadowCollector"ãã¹ãä½ãå¿
è¦ãããã¾ãã
ãæå¾ã«ä¸è¨3ã®ã·ã§ã¼ãã¯ãDefaultResourcesã®ä¸ã«ãããCamera-DepthNormalTexture,Camera-DepthTextureã§è¦ããã¨ãã§ãã¾ãã
ããããã®ã·ã§ã¼ãã¯Unityã«åãè¾¼ã¾ãã¦ãã¾ããããã®ããã«å¥éæã«å
¥ããã·ã§ã¼ãã"Resources"ã¨ããååãä»ãããã©ã«ãä¸ã«ç½®ããããã§å¤æ´ãããã¨ã§ãã«ã¹ã¿ãã¤ãºãããã¨ãåºæ¥ã¾ãã
ã
ããã®ã·ã§ã¼ãã¯ã«ã¡ã©ããè¦ã深度ãæ³ç·ãæç»ããããã«ä½¿ããã¾ãã
ã深度ãæ³ç·ãæç»ãããã³ã«ãã¹ã¦ã®ãªãã¸ã§ã¯ãã®ãããªã¢ã«ãå¤æ´ããã®ã¯é¢åã§ãã®ã§ãReplaced Shaderã¨ããä»çµã¿ãç¨æããã¦ãã¾ããReplace Shaderã¯ç»é¢ã«æ ããã¹ã¦ã®ãªãã¸ã§ã¯ãã®ãããªã¢ã«ã®ã·ã§ã¼ãããæå®ããã·ã§ã¼ãã«ç½®ãæãã¾ãã
ã
ãReplaced Shaderã®è©³ç´°ã¯ã
Unity - Unity Manualã«ããã¾ãã
ãä¸è¨ãã¼ã¸ã«ããããã«ãRenderTypeã¿ã°ãåºæºã«ãã¦ç½®ãæããã·ã§ã¼ãã決ã¾ãã¾ãã
æ°ããå½¢ç¶ãå¤æ´ããã·ã§ã¼ããä½ãå ´åãæ°ããRenderTypeãå®ç¾©ãããã®ãã¡ã¤ã«ã«åãRenderTypeã¿ã°ãæã¤ãµãã·ã§ã¼ããä½ãå¿
è¦ãããã¾ããï¼ããããªãã¨SSAOãªã©ã®ã¤ã¡ã¼ã¸ã¨ãã§ã¯ãã§çµæããããããªãã¾ãï¼
ãReplaced Shaderã¯ä¸è¨ãã¼ã¸ã«ãããéãèªåã§ã«ã¹ã¿ãã¤ãºãã¦å¥½ããªçµæ(深度ãæ³ç·ãã¯ã¼ã«ã座æ¨ããã¬ãã«ä¿æ°ãªã©ï¼ãã¬ã³ããªã³ã°ã§ãã¾ãã
追è¨(2013/12/28)
ãå®éã«ReplacedShaderã使ãã¨ããããã¥ã¢ã«ãã¤ãã¤ãã¨ãããå ¨ç¶ãããã«ããã£ãã®ã§å°ãä¾ãããã¾ãã
ãCamera.RenderWithShader(Camera.SetReplacementShaderãåæ§ï¼ã«ã¯å¼æ°ã2ã¤ããã¾ããæåã®1ã¤ã¯ç½®ãæããã·ã§ã¼ãã§ãããã¯åé¡ãªãã§ãããã
2ã¤ç®ã¯ã¿ã°æååã§ãããããã¯ã¿ã°ã®"å¤"ã§ã¯ãªãã¿ã°ãã®ãã®ã®æååã§ãã
(ä¾."RenderType"="Opaque"ã®å ´åã¯"RenderType"ã§ãã"MyTag"="hogehoge"ã®å ´åã¯"MyTag"ã§ããï¼
ã
ãæ¬æ¥ã®ã·ã§ã¼ãã«"MyTag"="Value1"ã¨ããã¿ã°ãä»ãã¦ããã¨ãã¾ãã
ç½®ãæããã·ã§ã¼ãå´ã«ã¯"MyTag"="Value1","MyTag"="Value2"â¦ã¨å¤ã ããå¤ãã£ãã¿ã°ãä»ãããµãã·ã§ã¼ããè¤æ°å
¥ã£ã¦ããã¨ãã¾ãã
ããã§RenderWithShader(ç½®ãæããã·ã§ã¼ã,"MyTag")ã¨ããã¨ãæ¬æ¥ã®ã·ã§ã¼ãã«ä»ãã¦ããMyTagã®å¤Value1ãè¦ã¦ãç½®ãæãã·ã§ã¼ãã®ãµãã·ã§ã¼ããã
MyTagã«åãå¤ãå
¥ã£ã¦ããç©ãæ¢ãåºããç½®ãæãã¾ãã"MyTag"="Value1"ã®ãµãã·ã§ã¼ããç¡ãã£ããã"MyTag"ããããããªãå ´åã¯ã¬ã³ããªã³ã°ãããªãããã§ãã
ãããã¥ã¢ã«ã«æ¸ãã¦ããä¾ã¯ã
ãç½®ãæããã·ã§ã¼ãã«ã"RenderType"="Opaque","RenderType"="Transparent"...ã¨ããã¿ã°ã®å
¥ã£ããµãã·ã§ã¼ããããå ´åã
Unityã®æ¨æºã·ã§ã¼ãã«ã¯å¿
ã"RenderType"ã¿ã°ãä»ãã¦ãããããç½®ãæããã·ã§ã¼ãã®é©åãªãµãã·ã§ã¼ãã«ç½®ãæãããããã¨ãããã¨ãè¨ã£ã¦ãã¾ãã