Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Unityのシェーダーについて自分なりにまとめてみた

 Unityのシェーダーについて自分なりにまとめてみた

Unityのシェーダーについて自分なりにまとめてみました。
まだまだ書ききれていない項目が多いです。
Cg/HLSL部分などはリファレンスに丸投げしてます。

Es_Program

March 06, 2016
Tweet

More Decks by Es_Program

Other Decks in Programming

Transcript

  1. UNITY
    γΣʔμʔʹΑΔදݱͷ֦ு

    View full-size slide


  2. ➤ UnityΤϯδχΞ
    ➤ C#Ͱ৭ʑ࡞ͬͯ·͢
    ➤ ࠷ۙγΣʔμʔͷษڧ͸͡
    Ί·ͨ͠ɻ
    Es
    About Me
    • http://esbrog.hatenablog.com/
    • https://github.com/EsProgram
    • https://twitter.com/Es_Program

    View full-size slide

  3. ͸͡Ίʹ
    ➤ ຊεϥΠυͷ໨త͸Unityʹ͓͚ΔγΣʔμʔͷֶशɻ
    ➤ γΣʔμʔͷػೳΛ࢖ͬͯͲͷΑ͏ͳޮՌ͕ಘΒΕΔ͔Λݟͯ
    ͍͘ɻ
    ➤ UnityͷάϥϑΟοΫεʹ͍ͭͯ΋Ұ௨Γɻ

    View full-size slide

  4. γΣʔμʔͷجຊ
    ➤ UnityͷγΣʔμʔʹ͓͚Δج
    ຊతͳ߲໨ʹ͍ͭͯݟ͍ͯ͘ɻ
    ➤ ͜͜Ͱ͸UnityͷϨϯμϦϯά
    ύΠϓϥΠϯ΍ΧϝϥɺuGUI
    ʹ͍ͭͯܰ͘৮ΕɺγΣʔμʔ
    ͷجຊߏจʹ͍ͭͯղઆ͢Δɻ
    • ʲUnityϚχϡΞϧʳShaderLab ϦϑΝϨϯε
    • ʲԜTipsʳUnity ͷγΣʔμͷجૅΛษڧͯ͠ΈͨͷͰ΍Δ
    ؾग़ͯ͠·ͱΊͯΈͨ
    • ʲΏʹͯ͘උ๨࿥ʳUnity Shader ·ͱΊ

    View full-size slide

  5. ShaderLabجຊߏ଄
    ShaderLabͷجຊߏ଄ʹ͍ͭͯ

    View full-size slide

  6. ShaderLabجຊߏจ
    Shader "name" { [Properties] Subshaders [Fallback] [CustomEditor] }
    ShaderLabγϯλοΫε
    Properties
    γΣʔμʔ͸ Properties ͷϦετΛ΋ͭ͜ͱ͕Ͱ͖ΔɻγΣʔμʔͰఆٛ͞ΕͨϓϩύςΟʔ͸ Unity ͷ ϚςϦ
    ΞϧΠϯεϖΫλʔ Ͱදࣔ͞ΕΔɻ௨ৗͷϓϩύςΟʔ͸ɺΦϒδΣΫτͷΧϥʔɺςΫενϟɺ͋Δ͍͸
    γΣʔμʔʹΑΓ࢖༻͞ΕΔ೚ҙͷ஋ɻ
    SubShadersͱFallback
    ֤γΣʔμʔ͸ SubShader ͷϦετ͔Βߏ੒͞ΕΔɻগͳ͘ͱ΋ͻͱ͕ͭඞਢɻγΣʔμʔΛϩʔυ͢Δͱ͖ɺ
    Unity ͸αϒγΣʔμʔͷϦετ͔ΒɺΤϯυϢʔβʔͷϚγϯͰαϙʔτ͞ΕΔ࠷ॳͷαϒγΣʔμʔΛબ୒͢
    Δɻ΋͠αϙʔτ͞ΕΔαϒγΣʔμʔ͕ͳ͍৔߹ɺUnity ͸ Fallback γΣʔμʔ ͷ࢖༻ΛࢼΈΔɻ
    γΣʔμʔͷ “level of detail” (LOD) ͱɺ“shader replacement” ͷೋͭ΋·ͨɺαϒγΣʔμʔͷ࡞੒ʹ࢖༻Ͱ͖
    ΔςΫχοΫɻ
    name
    γΣʔμʹ෇Ճ͢Δ໊લͰ͢ɻϚςϦΞϧΠϯεϖΫλʔʹදࣔ͞ΕΔ͔ name ҎԼͰϦετʹهड़͞ΕΔɻ
    ͨͱ͑͹
    Custom/MyShader
    ͱ͢Ε͹ΠϯεϖΫλʔ্ͰγΣʔμʔΛબ୒͢Δ࣌ɺCustomϦετʹMyShader͕දࣔ͞ΕΔΑ͏ʹͳΔɻ
    CustomEditor
    γΣʔμʔʹର͢Δ CustomEditor Λఆٛ͢Δ͜ͱ͕Ͱ͖ΔɻUnity ͸͜ͷ໊લͰ ShaderGUI Λ֦ுͨ͠Ϋϥε
    Λ୳͢ɻ΋͠ݟ͔ͭͬͨ৔߹ɺ͜ͷγΣʔμʔΛ࢖༻͢Δ͢΂ͯͷϚςϦΞϧͷΠϯεϖΫλʔ͕͜ͷ
    ShaderGUI Λ࢖༻͢Δɻ

    View full-size slide

  7. جຊߏจ࣮૷ྫ
    Shader "Structure Example" {
    Properties {
    // ΠϯεϖΫλʹදࣔ͞ΕΔϓϩύςΟʢ৭΍ςΫενϟ౳ʣ
    }
    SubShader {
    // ...௖఺/ϑϥάϝϯτϓϩάϥϜΛ࢖༻͢ΔαϒγΣʔμ...
    }
    SubShader {
    // ...ύε͝ͱʹ 4 ͭͷςΫενϟΛ࢖༻͢ΔαϒγΣʔμ...
    }
    SubShader {
    // ...ύε͝ͱʹ 2 ͭͷςΫενϟΛ࢖༻͢ΔαϒγΣʔμ...
    }
    SubShader {
    // …ݟͨ໨͸ѱ͍͕ɺ͍ͣΕͰ΋࣮ߦ͢ΔαϒγΣʔμ…
    }
    Fallback "Other Shader Name" // SubShader ͕͍ͣΕ΋μϝͩͬͨͱ͖ʹࢼ͢ผͷγΣʔμ
    }

    View full-size slide

  8. Category߲໨
    ΧςΰϦ͸࿦ཧతάϧʔϐϯάɻ͜
    Ε͸ଟ͘ͷ৔߹ɺϨϯμϦϯάঢ়ଶ
    Λܧঝ͢Δͷʹ࢖༻͞ΕΔɻྫ͑͹ɺ
    γΣʔμʔʹෳ਺ͷSubshader͕͋
    Δ৔߹ɺͦΕͧΕ͕Fog ΛΦϑʹ
    ͠ɺBlendingΛ௥Ճʹࢦఆ͢Δඞཁ
    ͕͋Δ৔߹ʹ͸ɺΧςΰϦΛ࢖ͬͯ
    ̍ͭͷهड़ͰࢦఆΛߦ͏͜ͱ͕Ͱ͖
    Δɻ
    Shader "example" {
    Category {
    Fog { Mode Off }
    Blend One One
    SubShader {
    // ...
    }
    SubShader {
    // ...
    }
    // ...
    }
    }
    ΧςΰϦϒϩοΫ͸ɺγΣʔμʔͷߏจղੳʹͷΈӨڹ͢Δ͕ɺԼͷ͢΂ͯͷϒ
    ϩοΫʹΧςΰϦ಺Ͱઃఆͨ͠ঢ়ଶΛߏจղੳ͢Δͷͱ·ͬͨ͘ಉ͡ʹͳΔɻ
    γΣʔμʔͷ࣮ߦ଎౓ʹ͸Ұ੾Өڹ͠ͳ͍ɻ

    View full-size slide

  9. Properties
    ShaderLabߏจ಺ͷPropertiesʹ͍ͭͯ

    View full-size slide

  10. Propertiesͱ͸
    ➤ γΣʔμʔʹΑΓɺUnity ͷ ϚςϦΞϧΠϯεϖΫλʔ ্
    ͰɺΞʔςΟετ͕ηοτͰ͖Δม਺ͷҰཡΛఆٛͰ͖Δɻ
    ➤ ϓϩύςΟʔ͸ γΣʔμʔϑΝΠϧͷ Properties ϒϩοΫͰ
    ఆٛ͢Δɻ
    Tint͔ΒColor Mask·ͰશͯϓϩύςΟɻ
    ϓϩύςΟ͸ϚςϦΞϧΠϯεϖΫλʔͰ
    ஋Λฤू͢Δ͜ͱ͕Մೳɻ

    View full-size slide

  11. Propertiesߏจ
    Properties { Property [Property ...] }
    ྫ Properties
    {
    _WaveScale ("Wave scale", Range (0.02,0.15)) = 0.07 // sliders
    _ReflDistort ("Reflection distort", Range (0,1.5)) = 0.5
    _RefrDistort ("Refraction distort", Range (0,1.5)) = 0.4
    _RefrColor ("Refraction color", Color) = (.34, .85, .92, 1) // color
    _ReflectionTex ("Environment Reflection", 2D) = "" {} // textures
    _RefractionTex ("Environment Refraction", 2D) = "" {}
    _Fresnel ("Fresnel (A) ", 2D) = "" {}
    _BumpMap ("Bumpmap (RGB) ", 2D) = "" {}
    }
    Propertiesʹ͸ม਺ͱͯ͠ѻ͏PropertyΛෳ਺ఆٛ͢Δ͜ͱ͕Ͱ͖Δɻ

    View full-size slide

  12. Property
    name ("display name",type) = value
    Propertyͷߏจ
    ➤ name

    γΣʔμʔϓϩάϥϜ্Ͱར༻͢Δม਺໊ɻΞϯμʔείΞ
    (_)Ͱ։࢝͢Δɻ
    ➤ display name

    ϚςϦΞϧΠϯεϖΫλʔͰදࣔ͢Δจࣈྻ
    ➤ type

    ม਺ͷܕ
    ➤ value

    ॳظ஋

    View full-size slide

  13. ܕ͝ͱͷϓϩύςΟهड़ྫ
    name("display name", Range( min, max)) = number
    floatϓϩύςΟΛఆٛ͠ɺΠϯεϖΫλ্ͰεϥΠυόʔ͕ min͔Β maxͱͯ͠දݱɻ
    name("display name", Color) = ( number, number, number, number)
    colorϓϩύςΟΛఆٛɻ
    name("display name", 2D) = "name" { options}
    2DςΫενϟϓϩύςΟΛఆٛɻ
    name("display name", Rect) = "name" { options}
    ௕ํܗʢ2ͷ΂͖৐Ͱͳ͍ʣςΫενϟͷϓϩύςΟΛఆٛɻ
    name("display name", Cube) = "name" { options}
    ΩϡʔϒϚοϓςΫενϟͷϓϩύςΟΛఆٛɻ
    name("display name", Float) = number
    floatϓϩύςΟΛఆٛɻ
    name("display name", Vector) = ( number, number, number, number)
    4ίϯϙʔωϯτɹϕΫτϧͷϓϩύςΟΛఆٛɻ
    ςΫενϟܥϓϩύςΟʔͷoptions͸Unity 5 Ͱ͸࡟আ͞ΕͨͷͰɺۭͷ{}Λఆٛ͢Δ

    View full-size slide

  14. ࣗಈ࣮૷ͷϓϩύςΟ
    ➤ ϓϩύςΟͱͯ͠ઃఆ͞Ε֤ͨςΫενϟͷͨΊʹɺUnity͸௥ՃͷϓϩύςΟͱͯ͠༨෼
    ͳ৘ใΛࣗಈతʹઃఆ͢Δɻ
    ➤ ࣗಈతʹఆٛ͞ΕΔͷͰɺγΣʔμʔ͔Β͸Propertiesʹఆٛ͠ͳͯ͘΋ΞΫηε͕Մೳɻ
    {TextureName}_ST - float4ϓϩύςΟɻλΠϦϯά/Φϑηοτͷ৘ใؚ͕·Ε͍ͯΔɻ
    • x͸ XλΠϦϯά஋
    • y͸ YλΠϦϯά஋
    • z͸ XΦϑηοτ஋
    • w͸ YΦϑηοτ஋
    ͨͱ͑͹ɺ_MainTexΛPropertiesʹఆٛͨ͠৔߹_MainTex_ST͕ࣗಈఆٛ͞ΕΔɻ
    {TextureName}_TexelSize - float4ϓϩύςΟɻςΫενϟαΠζͷ৘ใؚ͕·Ε͍ͯΔɻ
    • x͸ 1.0 /ςΫενϟͷ෯
    • y͸ 1.0 /ςΫενϟͷߴ͞
    • z͸ςΫενϟͷ෯
    • w͸ςΫενϟͷߴ͞
    {TextureName}_HDR - float4 ϓϩύςΟɻ࢖༻͞ΕΔ৭ۭؒʹԠͯ͡ɺજࡏతʹHDRʢྫ͑͹RGBMͰΤϯίʔυ
    ͞ΕͨʣςΫενϟΛσίʔυ͢Δํ๏ʹ͍ͭͯͷ৘ใؚ͕·ΕΔɻ σίʔυʹ༻͍ΔDecodeHDRؔ਺͸
    UnityCG.cgincͰఆٛ͞Ε͍ͯΔɻ

    View full-size slide

  15. γΣʔμʔ͔ΒϓϩύςΟʹΞΫηε
    ➤ ShaderLabߏจ಺Ͱ͸ɺϓϩύςΟʔͷ஋͸ׅހ [] ͰϓϩύςΟʔωʔϜΛ
    هड़ͯ͠ࢀর͢Δɻ

    Blend [_SrcBlend] [_DstBlend]

    Properties
    {
    _StencilComp ("Stencil Comparison", Float) = 8
    _Stencil ("Stencil ID", Float) = 0
    _StencilOp ("Stencil Operation", Float) = 0
    _StencilWriteMask ("Stencil Write Mask", Float) = 255
    _StencilReadMask ("Stencil Read Mask", Float) = 255
    }
    SubShader
    {
    Stencil
    {
    Ref [_Stencil]
    Comp [_StencilComp]
    Pass [_StencilOp]
    ReadMask [_StencilReadMask]
    WriteMask [_StencilWriteMask]
    }
    Pass
    {...}
    }

    View full-size slide

  16. γΣʔμʔ͔ΒϓϩύςΟʹΞΫηε
    ➤ Cg/HLSLهड़ՕॴͰγΣʔμʔϓϩύςΟʔΛࢀর͢Δ৔߹ɺCg/HLSLม਺Λಉ໊͡લͱϚον
    ϯά͢ΔλΠϓͰએݴ͢Δඞཁ͕͋Δɻ
    • Color ͱ Vector ϓϩύςΟʔ͸ɺfloat4ɺhalf4͋Δ͍͸fixed4ม਺ʹରԠ
    • Range ͱ Float ϓϩύςΟʔ͸ɺfloatɺhalf͋Δ͍͸fixedม਺ʹରԠ
    • Texture ϓϩύςΟʔ͸ɺ௨ৗʢ 2D ʣͷςΫενϟͷ৔߹͸sampler2Dม਺ʹରԠɺ3D ς
    Ϋενϟͷ৔߹͸sampler3Dม਺ʹରԠ
    Shader “Sample”{
    Properties{
    _MyColor ("Some Color", Color) = (1,1,1,1)
    _MyVector ("Some Vector", Vector) = (0,0,0,0)
    _MyFloat ("My float", Float) = 0.5
    _MyTexture ("Texture", 2D) = "white" {}
    _MyCubemap ("Cubemap", CUBE) = "" {}
    }
    SubShader{
    Pass{
    ….
    fixed4 _MyColor; // low precision type is usually enough for colors
    float4 _MyVector;
    float _MyFloat;
    sampler2D _MyTexture;
    samplerCUBE _MyCubemap;
    ….
    }
    }
    }

    View full-size slide

  17. Property Attributes
    ➤ γΣʔμʔͷϓϩύςΟʹ͸ଐੑΛ෇Ճ͢Δ͜ͱ͕Ͱ͖Δɻ
    ➤ ͦͷଐੑʹैͬͯɺΠϯεϖΫλʔͷදࣔΛมߋͰ͖Δɻ
    Properties {
    [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0
    [Toggle] _Invert ("Invert color?", Float) = 0
    }

    View full-size slide

  18. Property Attributes
    • [HideInInspector]


    ϓϩύςΟΛΠϯεϖΫλʔʹදࣔ͠ͳ͍
    • [NoScaleOffset]


    ςΫενϟͷTiling/OffsetϑΟʔϧυΛΠϯεϖΫλʔʹදࣔ͠ͳ͍ɻ
    • [Normal]


    ςΫενϟϓϩύςΟ͕๏ઢϚοϐϯάʹ༻͍Δ͜ͱΛظ଴͍ͯ͠Δ͜ͱΛࣔ͠·͢ɻ
    • [HDR]


    ςΫενϟϓϩύςΟ͕HDRςΫενϟΛظ଴͍ͯ͠Δ͜ͱΛࣔ͠·͢ɻ
    • [Gamma]


    float/vector ϓϩύςΟ͕sRGB஋Ͱ͋Δ͜ͱΛࣔ͠·͢ɻ࢖༻͢ΔΧϥʔεϖʔεʹԠͨ͡ม׵ॲཧ͕ߦΘΕ
    ΔՄೳੑ͕͋Δ͜ͱΛ͍ࣔͯ͠·͢ɻ
    • [PerRendererData]


    indicates that a texture property will be coming from per-renderer data in the form of a
    MaterialPropertyBlock. Material inspector changes the texture slot UI for these properties.
    • [Toggle]


    floatͷΠϯεϖΫλʔදࣔΛτάϧʹ͠·͢ɻfloat͸0͔1ͷ஋ΛͱΔΑ͏ʹͳΓ·͢ɻ

    // Will set "_INVERT_ON" shader keyword when set

    [Toggle] _Invert ("Invert?", Float) = 0

    // Will set "ENABLE_FANCY" shader keyword when set

    [Toggle(ENABLE_FANCY)] _Fancy ("Fancy?", Float) = 0
    σϑΥϧτͰ࢖༻Ͱ͖Δ΋ͷ(Ұ෦)

    View full-size slide

  19. Property Attributes
    • [Enum]


    floatϓϩύςΟʔʹϙοϓΞοϓϝχϡʔΛදࣔ͠·͢ɻྻڍମͷܕ໊ɺ·ͨ͸໌ࣔతͳ໊લ / ஋ͷϖΞΛࢦ
    ఆͰ͖·͢ɻ࠷େͰ 7 ͭͷ໊લ / ஋ͷϖΞΛࢦఆͰ͖·͢ɻ

    // Blend mode values

    [Enum(UnityEngine.Rendering.BlendMode)] _Blend ("Blend mode", Float) = 1

    // A subset of blend mode values, just "One" (value 1) and "SrcAlpha" (value 5)

    [Enum(One,1,SrcAlpha,5)] _Blend2 ("Blend mode subset", Float) = 1

    • [KeywordEnum]


    floatϓϩύςΟʹϙοϓΞοϓϝχϡʔΛදࣔ͠·͢ɻShaderͷΩʔϫʔυͱͯ͠஋Λ࢖༻ग़དྷ·͢ɻΩʔ
    ϫʔυʹ͸ʮ”ϓϩύςΟ໊”+”_”+”ྻڍ໊”ʯΛ࢖༻͠·͢ɻ࠷େ9ͭͷ஋ΛྻڍͰ͖·͢ɻ

    // Display a popup with None,Add,Multiply choices.

    // Each option will set _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY shader keywords.

    [KeywordEnum(None, Add, Multiply)] _Overlay ("Overlay mode", Float) = 0

    // ...later on in CGPROGRAM code:

    #pragma multi_compile _OVERLAY_NONE, _OVERLAY_ADD, _OVERLAY_MULTIPLY

    // ..
    σϑΥϧτͰ࢖༻Ͱ͖Δ΋ͷ(Ұ෦)

    View full-size slide

  20. Property Attributes
    • [PowerSlider]


    Range γΣʔμʔϓϩύςΟʔʹର͢ΔઢܗͰͳ͍൓ԠۂઢͷεϥΠμʔΛදࣔ͠·͢ɻ

    // A slider with 3.0 response curve

    [PowerSlider(3.0)] _Shininess ("Shininess", Range (0.01, 1)) = 0.08

    • [Space]


    γΣʔμʔϓϩύςΟʔͷલʹਨ௚ํ޲ͷεϖʔεΛ࡞੒͠·͢ɻ

    // Default small amount of space

    [Space] _Prop1 ("Prop1", Float) = 0

    // Large amount of space

    [Space(50)] _Prop2 ("Prop2", Float) = 0

    • [Header]


    γΣʔμʔϓϩύςΟʔͷલʹϔομʔςΩετΛ࡞੒͠·͢ɻ

    [Header(A group of things)] _Prop1 ("Prop1", Float) = 0
    σϑΥϧτͰ࢖༻Ͱ͖Δ΋ͷ(Ұ෦)

    View full-size slide

  21. Property Drawer
    Property Attributeͱͯ͠ར༻ग़དྷΔϨΠΞ΢τଐੑΛࣗ࡞Ͱ͖Δɻ

    ࣗ਎ͷ Drawer Λ࣮૷͢Δͱ͖ɺOnGUI ؔ਺ΛΦʔόʔϥΠυ͢Δɻ
    // The property drawer class should be placed in an editor script, inside a folder called Editor.
    // Use with "[MyToggle]" before a float shader property
    class MyToggleDrawer extends MaterialPropertyDrawer {
    // Draw the property inside the given rect
    function OnGUI (position : Rect, prop : MaterialProperty, label : String, editor : MaterialEditor) {
    // Setup
    EditorGUI.BeginChangeCheck ();
    var value : boolean = prop.floatValue != 0.0f;
    EditorGUI.showMixedValue = prop.hasMixedValue;
    // Show the toggle control
    value = EditorGUI.Toggle (position, label, value);
    EditorGUI.showMixedValue = false;
    if (EditorGUI.EndChangeCheck ()) {
    // Set the new value if it has changed
    prop.floatValue = value ? 1.0f : 0.0f;
    }
    }
    }

    View full-size slide

  22. SubShader
    ShaderLabߏจ಺ͷSubShaderʹ͍ͭͯ

    View full-size slide

  23. SubShaderͱ͸
    ➤ γΣʔμʔ̍ͭͷߏ੒୯Ґ
    ➤ αϒγΣʔμʔͰ͸ϨϯμϦϯάύεͷҰཡΛఆٛ͠ɺ೚ҙͷΦϓγϣϯͱ
    ͯ͢͠΂ͯͷύεʹڞ௨ͷ State ʢঢ়ଶʣΛઃఆ͢Δɻ
    ➤ ύεఆٛͰهड़Ͱ͖ΔϨϯμϦϯάεςʔτ͸αϒγΣʔμʔͷهड़ϒϩο
    ΫͰ΋ॻ͘͜ͱ͕Ͱ͖Δɻ͜ΕʹΑΓ͢΂ͯͷύε͕”ڞ༗ͷ” State (ঢ়ଶ)
    Λ࢖༻͢Δ͜ͱ͕Ͱ͖Δ(྆ํʹهड़ͨ͠৔߹͸Pass಺ͷState͕༏ઌ)ɻ
    ➤ ֤ύεͷఆٛ͸ Regular PassɺUse PassɺGrab Pass ͷ͍ͣΕ͔ɻ
    ➤ SubShader಺ͷTag ΛઃఆͰ͖Δɻ

    View full-size slide

  24. SubShaderߏจ
    Subshader { [Tags] [CommonState] Passdef [Passdef ...] }
    ߏจ
    ➤ Tags
    • SubShader಺ͷTagsɻͲͷΑ͏ʹͯ͠ϨϯμϦϯάΤϯδϯͰϨϯμϦϯά͢Δ
    ͔Λࢦఆ͢Δɻ
    ➤ CommonState
    • ͞·͟·ͳάϥϑΟοΫεϋʔυ΢ΣΞͷ State ʢঢ়ଶʣΛઃఆͰ͖ΔɻPass
    Ͱهड़Ͱ͖ΔεςʔτϝϯτͱಉҰ(εςʔτ͕༗ޮͳείʔϓ͕ҧ͏)ɻ
    ➤ Passdef
    • Regular PassɺUse Passɺ·ͨ͸ Grab Pass ͷ͍ͣΕ͔

    View full-size slide

  25. SubShader಺ͷTags
    ShaderLabߏจ಺ͷTagsʹ͍ͭͯ

    View full-size slide

  26. SubShader಺ͷTags
    SubShader͸TagsΛ࢖༻͍ͯͭ͠ͲͷΑ͏ʹͯ͠ϨϯμϦϯάΤϯδϯʹΑ
    ΓϨϯμϦϯά͢΂͖͔ΛࢦఆͰ͖Δɻ
    Tagsͷߏจ
    Tags { "TagName1" = "Value1" "TagName2" = "Value2" }
    λάͷ TagName1 ͕஋ͱͯ͠ Value1ɺλάͷ TagName2 ͕஋ͱͯ͠ Value2 Ͱ͋Δ͜ͱΛࢦఆ͍ͯ͠
    Δɻλά͸޷͖ͳ͚ͩࢦఆͰ͖Δɻλά͸جຊతʹ Key-Value ϖΞɻSubShaderͷதͰλά͸ɺ
    SubShader࣮ߦॱং΍ଞͷύϥϝʔλʔΛ൑ఆ͢Δͷʹ࢖༻͢Δɻ
    Tags͸SubShaderɺPass಺ͷͲͪΒʹͰ΋ఆٛ͢Δ͜ͱ͕Ͱ͖Δ͕ɺ࣍ͷλά͸ Unity ʹΑΓ
    ೝࣝ͞ΕɺPass಺ͷTagsͰͳ͘ඞͣSubShaderηΫγϣϯͷதʹఆٛ͢Δɻ

    • Queue λά
    • RenderType λά
    • DisableBatching λά
    • ForceNoShadowCasting λά
    • IgnoreProjector λά
    • CanUseSpriteAtlas λά
    • RenderType λά

    View full-size slide

  27. SubShader಺ͷTags
    Queueλά
    QueueʹΑΓΦϒδΣΫτΛඳը͢Δॱ൪ΛࢦఆͰ͖ΔɻγΣʔμʔ͸ΦϒδΣΫτ͕ଐ͢ΔϨϯμϦϯά
    ΩϡʔΛ൑ఆ͠ɺॱʹϨϯμϦϯάΛߦ͍·͢ɻྫ͑͹ɺಁ໌ͳΦϒδΣΫτ͸ෆಁ໌ͳΦϒδΣΫτͷޙ
    ʹඳը͞ΕΔ΂͖ͳͷͰQueueλάͰॱ൪Λࢦఆ͢Δඞཁ͕͋Γ·͢ɻ
    ఆٛࡁΈͷϨϯμϦϯάΩϡʔ
    ➤ Background


    ͜ͷϨϯμϦϯάΩϡʔ͸ଞΑΓલʹϨϯμϦϯά͞ΕΔɻSkybox ͳͲʹ࢖༻͞ΕΔɻ
    ➤ Geometry (default)


    ΄ͱΜͲͷΦϒδΣΫτʹ࢖༻͞ΕΔɻෆಁ໌ͳδΦϝτϦ͸͜ͷΩϡʔΛ࢖༻͢Δɻ
    ➤ AlphaTest


    ΞϧϑΝςετ͢Δܗঢ়Ͱ͜ͷΩϡʔΛ࢖༻͢ΔɻGeometry ͱ͸ผͷΩϡʔͰ͋Δͷ͸ΞϧϑΝςετ
    ͷΦϒδΣΫτΛ͢΂ͯͷෆಁ໌ͷΦϒδΣΫτͷޙʹඳը͢Δ΄͏͕ޮ཰తͰ͋ΔͨΊɻ
    ➤ Transparent


    ͜ͷϨϯμϦϯάΩϡʔ͸Geometry ͱAlphaTest ͷޙʹɺޙΖʹ͋Δ΋ͷ͔Βઌʹॱ൪ͰϨϯμϦϯά͞
    ΕΔɻΞϧϑΝϒϨϯσΟϯά͢Δ΋ͷʢ͢ͳΘͪɺσϓεόοϑΝʹॻ͖ࠐΈ͠ͳ͍γΣʔμʔʣ͸͢
    ΂ͯɺ͜͜ʹ͋Δ΂͖ʢΨϥεɺύʔςΟΫϧΤϑΣΫτʣɻ
    ➤ Overlay


    ͜ͷϨϯμϦϯάΩϡʔ͸ΦʔόʔϨΠΤϑΣΫτͷͨΊͷ΋ͷɻ࠷ޙʹϨϯμϦϯά͢Δ΋ͷ͸͜͜ʹ
    ͋Δ΂͖ʢྫ͑͹ɺϨϯζϑϨΞʣɻ

    View full-size slide

  28. SubShader಺ͷTags
    Queueλά
    ಛผͳ༻్ʹ͓͍ͯɺؒʹΩϡʔΛ࢖༻͢Δ͜ͱ͕Ͱ͖Δɻ֤Ωϡʔ͸
    ಺෦Ͱ੔਺ΠϯσοΫεʹΑΓදݱ͞ΕɺBackground ͸ 1000ɺ
    Geometry ͸ 2000ɺAlphaTest ͸ 2450ɺTransparent ͸ 3000ɺͦͯ͠
    Overlay ͸ 4000 ͱ͍͏੔਺஋Ͱදݱ͞ΕΔɻ΋͠γΣʔμʔ͕ͭ͗ͷΑ
    ͏ͳΩϡʔΛ࢖༻͢Δ৔߹
    Tags { "Queue" = "Geometry+1" }
    ͜ΕʹΑΓΦϒδΣΫτ͸͢΂ͯͷෆಁ໌ͷΦϒδΣΫτͷޙʹϨϯμϦ
    ϯά͞ΕΔ͕ɺϨϯμϦϯάΩϡʔ͕ 2001 ʢGeometry ʹ 1 ΛՃࢉʣͷͨ
    ΊɺಁաΦϒδΣΫτΑΓઌʹϨϯμϦϯά͞ΕΔɻ

    View full-size slide

  29. SubShader಺ͷTags
    RenderTypeλά
    RenderType λά͸γΣʔμʔΛఆٛࡁΈͷ͍͔ͭ͘ͷάϧʔϓ
    ʹ෼ྨ͢Δɻྫ͑͹ɺʮෆಁ໌ͳγΣʔμʔʯɺʮΞϧϑΝςε
    τͷγΣʔμʔʯͱ͍ͬͨΑ͏ʹ෼ྨ͢Δɻ͜Ε͸ Shader
    Replacement ʹΑΓ࢖༻͞Εɺଟ͘ͷ৔߹ Χϝϥͷਂ౓ςΫε
    νϟΛੜ੒͢Δͷʹ࢖༻͢Δɻ

    View full-size slide

  30. SubShader಺ͷTags
    DisableBatchingλά
    ͍͘Β͔ͷγΣʔμʔ(େ఍͸ΦϒδΣΫτεϖʔεͰ௖఺Λมܗͤ͞Δ΋
    ͷ)͸ɺυϩʔίʔϧόονϯά Λ࢖༻͍ͯ͠Δͱɺಈ࡞͠ͳ͍ɻ


    υϩʔίʔϧόονϯά͸ɺ͢΂ͯͷδΦϝτϦΛϫʔϧυεϖʔεʹม
    ׵͢ΔͷͰɺ“object space” ͕ࣦΘΕΔͨΊͰ͋Δɻ

    DisableBatching λάΛ࢖ͬͯυϩʔίʔϧόονϯάͷ༗ޮ/ແޮΛࢦࣔ
    Ͱ͖ΔɻઃఆՄೳͳͷ͸ҎԼ3ͭɻ
    ➤ True


    ͜ͷγΣʔμʔͰ͸ৗʹόονϯάΛແޮʹ͢Δɻ
    ➤ False


    όονϯάΛແޮʹ͠ͳ͍ɻσϑΥϧτ͸͜Εɻ
    ➤ LODFading


    LOD fading ͕ΞΫςΟϒͳ࣌͸όονϯάΛແޮʹ͢Δɻେ఍͸थ໦
    Ͱ࢖ΘΕΔɻ

    View full-size slide

  31. SubShader಺ͷTags
    ForceNoShadowCastingλά
    ΋͠ ForceNoShadowCasting ͕࢖༻͞Ε͍ͯͯɺ஋͕ “True” Ͱ͋Δ৔
    ߹ɺ͜ͷαϒγΣʔμʔΛ࢖༻͢ΔΦϒδΣΫτ͸γϟυ΢Λ౤Өͳ͍ɻ
    ͜Ε͸ɺಁաΦϒδΣΫτʹ Shader Replacement Λ࢖༻͍ͯ͠Δ৔߹
    ΍ɺผͷαϒγΣʔμʔ͔Βγϟυ΢ύεΛܧঝͨ͘͠ͳ͍৔߹ʹศརɻ

    View full-size slide

  32. SubShader಺ͷTags
    IgnoreProjectorλά
    ΋͠ IgnoreProjector ͕࢖༻͞Ε͍ͯͯɺ஋͕ “True” Ͱ͋Δ৔߹ɺ͜ͷ
    γΣʔμʔΛ࢖༻͢ΔΦϒδΣΫτ͸ ϓϩδΣΫλʔ ʹΑΓӨڹ͞Εͳ
    ͍ɻ͜Ε͸ɺProjectors ͕Өڹ͢ΔͨΊͷΑ͍ํ๏͕ͳ͍ͨΊɺ෦෼తʹ
    ಁաͰ͋ΔΦϒδΣΫτͰศརɻ

    View full-size slide

  33. SubShader಺ͷTags
    CanUseSpriteAtlasλά
    γΣʔμʔ͕εϓϥΠτʹ༻͍ΒΕΔ৔߹΍ΞτϥεʢεϓϥΠτύο
    ΧʔΛࢀরʣʹύοΩϯά͞Εͨͱ͖ಈ࡞͠ͳ͍৔߹ɺ
    CanUseSpriteAtlas λάΛ “False” ʹઃఆ͢Δɻ

    View full-size slide

  34. SubShader಺ͷTags
    PreviewTypeλά
    PreviewTypeλά͸ɺϚςϦΞϧͷΠϯεϖΫλʔϓϨϏϡʔ͕ͲͷΑ͏
    ʹϓϨϏϡʔΛදࣔ͢Δ͔Λࣔ͢ɻϚςϦΞϧ͸σϑΥϧτͰٿମ
    ʢsphereʣͱͯ͠දࣔ͞ΕΔ͕ɺPreviewType λά͸ “Plane”ʢ2D ͷΑ͏
    ʹදࣔ͢Δʣ΍ “Skybox”ʢۭςΫενϟ(Skybox)ͷΑ͏ʹදࣔ͢Δʣʹ
    ΋ઃఆͰ͖Δɻ

    View full-size slide

  35. ϨϯμϦϯάεςʔτ
    SubShader΍PassͰࢦఆͰ͖ΔϨϯμϦϯάεςʔτʹ͍ͭͯ

    View full-size slide

  36. ϨϯμϦϯάεςʔτͱ͸
    ➤ ͞·͟·ͳάϥϑΟοΫεϋʔυ΢ΣΞͷ State ʢঢ়ଶʣΛϨ
    ϯμϦϯάεςʔτͱ͍͏ɻ
    ➤ ྫ͑͹ΞϧϑΝϒϨϯσΟϯάΛ༗ޮԽͨ͠ΓɺϑΥάΛ࢖༻
    ͨ͠Γͱ͍͏͜ͱ͕Ͱ͖Δɻ
    ➤ SubShader಺ɺ·ͨ͸Pass಺Ͱར༻Ͱ͖Δɻ
    ➤ ҎԼͰ͸ɺϨϯμϦϯάεςʔτΛઃఆͰ͖ΔίϚϯυΛղ
    આ͢Δɻ

    View full-size slide

  37. ϨϯμϦϯάεςʔτ
    Cull
    ϙϦΰϯͷΧϦϯάϞʔυΛઃఆ͢Δɻৄࡉ͸ΧϦϯάͱਂ౓ςετ
    Ͱɻ
    Cull Back | Front | Off

    View full-size slide

  38. ϨϯμϦϯάεςʔτ
    ZTest
    ਂ౓όοϑΝʔͷςετϞʔυΛઃఆ͢Δɻৄࡉ͸ΧϦϯάͱਂ౓ςε
    τͰɻ
    ZTest (Less | Greater | LEqual | GEqual | Equal | NotEqual | Always)

    View full-size slide

  39. ϨϯμϦϯάεςʔτ
    ZWrite
    ਂ౓όοϑΝʔͷॻ͖ࠐΈϞʔυΛઃఆ͢Δɻৄࡉ͸ΧϦϯάͱਂ౓ς
    ετͰɻ
    ZWrite On | Off

    View full-size slide

  40. ϨϯμϦϯάεςʔτ
    ZWrite
    ਂ౓όοϑΝʔͷॻ͖ࠐΈϞʔυΛઃఆ͢Δɻৄࡉ͸ΧϦϯάͱਂ౓ς
    ετͰɻ
    ZWrite On | Off

    View full-size slide

  41. ϨϯμϦϯάεςʔτ
    Blend
    ΞϧϑΝϒϨϯσΟϯάϞʔυΛઃఆ͢Δɻৄࡉ͸BlendingͰɻ
    Blend SourceBlendMode DestBlendMode
    Blend SourceBlendMode DestBlendMode, AlphaSourceBlendMode AlphaDestBlendMode

    View full-size slide

  42. ϨϯμϦϯάεςʔτ
    ColorMask
    Χϥʔͷॻ͖ࠐΈʹϚεΫΛઃఆ͢Δɻ”ColorMask 0”ͱهࡌ͢Δ͜ͱͰ
    ͢΂ͯͷΧϥʔνϟωϧͷϨϯμϦϯάΛແޮԽ͢Δɻ σϑΥϧτϞʔ
    υ͸RGBA͢΂ͯʹॻ͖ࠐΈ͢Δɻ
    ϚεΫΛઃఆ͢Δ͜ͱͰɺઃఆͨ͠৭͕ϨϯμϦϯά͞ΕΔΑ͏ʹͳΔɻ
    ColorMask RGB | A | 0 | any combination of R, G, B, A

    View full-size slide

  43. ϨϯμϦϯάεςʔτ
    Offset
    Z όοϑΝͷσϓεΦϑηοτΛઃఆ͢Δɻৄࡉ͸ΧϦϯάͱਂ౓ςε
    τͰɻ
    Offset OffsetFactor, OffsetUnits

    View full-size slide

  44. Fallback
    ShaderLabߏจ಺ͷFallbackʹ͍ͭͯ

    View full-size slide

  45. Fallback
    ͢΂ͯͷ Subshader ͷࢼߦޙɺFallback Λఆٛ͢Δ͜ͱ͕Ͱ͖Δɻجຊత
    ͳҙຯͱͯ͠͸“͜ͷϋʔυ΢ΣΞͰ࣮ߦͰ͖ΔαϒγΣʔμʔ͕ͳ͍৔
    ߹ɺผͷγΣʔμʔ͔Βࢼ͢”ɻ
    Fallback "name"
    ߏจ
    nameͰࢦఆ͞ΕͨShaderΛFallbackͱͯ͠ఆٛ͢Δɻ
    OffΛࢦఆ͢Δ͜ͱ΋Ͱ͖Δɻ
    Fallback Off
    ͜ͷ৔߹͸໌ࣔతʹ Fallback ͕ͳ͘ɺͨͱ͑͜ͷϋʔυ΢ΣΞͰ࣮ߦͰ
    ͖ΔαϒγΣʔμʔ͕ͳ͔ͬͨͱͯ͠΋ɺܯࠂΛग़ྗ͠ͳ͍ͱ͍͏ҙຯ
    ʹͳΔɻ

    View full-size slide

  46. Pass
    ➤ SubShaderλά಺Ͱఆٛ͢Δ
    Passʹ͍ͭͯղઆ͢Δɻ
    • ʲUnityϚχϡΞϧʳShaderLab ϦϑΝϨϯε
    • ʲKCSʳ۶ંޮՌΛUnityͰʂ
    • ʲ͏ʹ͹ͳʳΤϑΣΫτ༻ͷγΣʔμʹؔ͢ΔΞΠσΞ
    • ʲMarveric ProjectʳϝϞॻ͖

    View full-size slide

  47. Pass
    ShaderLabߏจ಺ͷPassʹ͍ͭͯ

    View full-size slide

  48. Passͷ֓ཁ
    ➤ Pass ϒϩοΫ͸ΦϒδΣΫτܗঢ়ΛҰճͷΈϨϯμϦϯά͢ΔΑ͏ʹ͢Δɻ
    ➤ ෳ਺ύεͷϨϯμϦϯάΛ͢Δ৔߹͸ɺ̍ͭͷSubShaderʹෳ਺ͷPassΛهड़͢Δɻ
    ➤ PassϒϩοΫ಺Ͱར༻Ͱ͖Δεςʔτ͸ϨϯμϦϯάεςʔτΛࢀরɻ
    ➤ PassϒϩοΫ಺Ͱར༻Ͱ͖Δλά͸Pass಺ͷTagsΛࢀরɻ
    ➤ PassϒϩοΫ಺Ͱར༻Ͱ͖Δεςϯγϧʹ͍ͭͯ͸StencilΛࢀরɻ
    ➤ PassϒϩοΫ಺Ͱར༻Ͱ͖ΔϒϨϯσΟϯάʹ͍ͭͯ͸BlendingΛࢀরɻ
    ➤ Render Setup͸ݻఆؔ਺γΣʔμʔ/αʔϑΣεγΣʔμʔ/௖఺ɾϑϥάϝϯτγΣ
    ʔμʔΛࢀরɻ
    Pass { [Name and Tags] [RenderSetup] }
    ߏจ

    View full-size slide

  49. Pass Name
    ➤ ݱࡏͷύεʹ PassName ͷ໊લΛ෇͚Δɻ
    ➤ ಺෦Ͱ͸໊લ͕େจࣈʹͳ͍ͬͯΔͷͰ஫ҙ͢Δɻ
    ➤ UsePassίϚϯυͰ໊લΛ࢖ͬͯࢀরͰ͖ΔΑ͏ʹͳΔɻ
    Name "PassName"
    ߏจ

    View full-size slide

  50. UsePass
    ShaderLabߏจ಺ͷUsePassʹ͍ͭͯ

    View full-size slide

  51. UsePass
    ➤ UsePass͸ผͷγΣʔμʔͷPassΛ࢖͏ͨΊͷίϚϯυɻ
    ➤ ผͷγΣʔμʔͰ͸Pass Name͕ఆٛ͞Ε͍ͯΔඞཁ͕͋Δɻ
    ➤ Shader/Name ʹ͸ɺεϥογϡͰ۠੾ΒΕͨγΣʔμʔͷ໊
    લͱύεͷ໊લΛࢦఆ͢Δɻ
    ➤ ಺෦Ͱ͸Pass Name͸͢΂ͯେจࣈʹͳ͍ͬͯΔ͜ͱʹ஫ҙ͢
    Δɻ
    UsePass "Shader/Name"
    ߏจ
    UsePass "VertexLit/SHADOWCASTER"

    View full-size slide

  52. GrabPass
    ShaderLabߏจ಺ͷGrabPassʹ͍ͭͯ

    View full-size slide

  53. GrabPass
    ➤ GrabPass͸ಛผͷύελΠϓͰɺGrabPass࣮ߦ࣌ʹطʹϨϯμϦϯά͞Ε͍ͯΔը૾ΛςΫενϟͱ
    ͯ͠࢖༻Ͱ͖ΔΑ͏ʹ͢Δ(ݱࡏ·ͰͷϨϯμϦϯά݁ՌΛ௫ΈऔΔ)ɻ
    ➤ ௫ΈऔͬͨςΫενϟ͸ޙଓͷPassͰར༻͢Δ͜ͱ͕Ͱ͖Δɻ
    ➤ ͍ͣΕ͔ͷॻࣜΛར༻͢Δɻ
    • GrabPass { } ͱࢦఆ͠ɺ୯ʹݱࡏͷը໘ίϯςϯπΛςΫενϟ಺ʹ௫ΈͱΔɻ͜ͷςΫενϟ
    ͸ޙଓͷύεͰ _GrabTexture ͰΞΫηε͢Δ͜ͱ͕Ͱ͖Δɻ஫ҙɿ͜ͷܗࣜͷGrap Pass͸ը໘
    ͷ௫ΈͱΓॲཧΛ࢖༻͢Δ֤ΦϒδΣΫτ͝ͱʹߦ͏ɻྫ͑͹͜ͷܗࣜͷGrabPassΛ࣋ͭಉ͡
    ϚςϦΞϧΛద༻ͨ͠2ͭͷΦϒδΣΫτΛϨϯμϦϯά͢Δ৔߹ɺ̎ͭͷ_GrabTexture͕ੜ੒
    ͞ΕΔ͜ͱʹͳΔɻ
    • GrabPass { "TextureName" } ʹΑΓը໘ίϯςϯπΛςΫενϟ಺ʹ௫ΈऔΔɻϑϨʔϜ͝ͱʹ
    1౓͚ͩɺࢦఆͷςΫενϟ໊Λ࢖༻͢Δ࠷ॳͷΦϒδΣΫτ෼ʹͷΈ࣮ࢪ͢ΔɻςΫενϟ͸
    ޙଓͷύεͰࢦఆͷςΫενϟ໊ͰΞΫηε͢Δ͜ͱ͕Ͱ͖ΔɻγʔϯͰ Grab Pass Λ࢖༻͢Δ
    ΦϒδΣΫτ͕ෳ਺͋Δ৔߹ʹޮ཰తͳํ๏ɻ
    ➤ GrabPass಺Ͱ͸Name΍Tags ίϚϯυΛ࢖༻͢Δ͜ͱ͕Ͱ͖ΔɻRegular PassͰͷར༻ͱಉ͡༻్ɻ

    View full-size slide

  54. GrabPassͷྫ
    Shader "GrabPassInvert" {
    SubShader {
    // શͯͷෆಁ໌ͳܗঢ়ͷޙʹɺࣗ਎Λඳը͠·͢
    Tags { "Queue" = "Transparent" }
    // ΦϒδΣΫτΑΓޙΖͷγʔϯΛ_GrabTextureʹ௫ΈऔΓ·͢
    GrabPass { }
    // ্Ͱੜ੒ͨ͠ςΫενϟͰΦϒδΣΫτΛϨϯμϦϯά͠ɺΧϥʔΛ൓స͠·͢ɻ
    Pass {
    SetTexture [_GrabTexture] { combine one-texture }
    }
    }
    }
    લʹϨϯμϦϯά͞ΕͨΧϥʔΛ൓స͢Δ
    ͨΊʹGrabPassΛར༻͢Δྫ

    View full-size slide

  55. ݻఆؔ਺γΣʔμʔ
    ➤ Ұ൪جຊతͳUnityγΣʔμʔ
    Ͱ͋Δݻఆؔ਺γΣʔμʔʹ
    ͍ͭͯݟ͍ͯ͘ɻ
    ➤ Ͱ͖Δ͜ͱ͸গͳ͘ɺඪ४Ͱ
    උΘ͍ͬͯΔϚςϦΞϧͱಉ
    ఔ౓ͷදݱ͕ݶքͳͷͰɺج
    ຊతͳίʔυͷ঺հʹͱͲΊ
    ͓ͯ͘ɻ
    • ʲUnityϚχϡΞϧʳShaderLab ϦϑΝϨϯε

    View full-size slide

  56. ݻఆؔ਺γΣʔμʔͱ͸
    ݻఆؔ਺γΣʔμʔͷ֓ཁʹ͍ͭͯ

    View full-size slide

  57. ݻఆؔ਺γΣʔμʔͱ͸
    ➤ ݻఆؔ਺γΣʔμʔ͸ɺݹ͍ϋʔυ΢ΣΞͷͨΊʹهड़͢Δɻ
    ➤ ݻఆؔ਺γΣʔμʔ͸ϑϥάϝϯτγΣʔμ·ͨ͸αʔϑΣΠ
    εγΣʔμͷޙͷ n ൪໨ͷ fallback ͱͯ͠هड़ͯ͠ɺݹ͍ϋʔ
    υ΢ΣΞͰ࣮ߦͨ͠ͱ͖΋ϨϯμϦϯάΛߦ͑ΔΑ͏ʹ͢Δɻ
    ➤ ݻఆؔ਺γΣʔμʔ͸͢΂ͯ ShaderLab Ͱॻ͘ɻ
    ➤ ݻఆؔ਺γΣʔμʔ͸ݻఆػೳͱݺ͹ΕΔίϚϯυͷΈͰه
    ड़͞ΕͨγΣʔμʔͷ͜ͱɻ
    ➤ ݻఆػೳ͸ଞͷγΣʔμʔͰ΋ར༻Ͱ͖Δɻ

    View full-size slide

  58. ݻఆػೳϥΠςΟϯά
    ͱϚςϦΞϧ
    ݻఆػೳϥΠςΟϯάͱϚςϦΞϧʹ͍ͭͯ

    View full-size slide

  59. ݻఆػೳϥΠςΟϯάͱϚςϦΞϧ
    ➤ Lighting On | Off

    • ϚςϦΞϧϒϩοΫͰఆٛ͞ΕͨઃఆͰɺ೚ҙͷޮՌΛ࣋ͭΑ͏ʹ͢Δʹ͸ɺLighting ON ί
    ϚϯυΛ࢖༻ͯ͠ϥΠςΟϯάΛ༗ޮʹ͢ΔɻϥΠςΟϯά͕Φϑʹͳ͍ͬͯΔ৔߹͸ɺ৭͕
    Color ίϚϯυ͔Β௚઀औಘ͞ΕΔɻ
    ➤ Material { Material Block }

    • Diffuse color: ΦϒδΣΫτͷϕʔεΧϥʔɻ
    • Ambient color: ΞϯϏΤϯτ(؀ڥ)ޫ͕ΦϒδΣΫτʹরࣹͨ͠ͱ͖ͷ৭ɻ
    • Specular color: ΦϒδΣΫτͷεϖΩϡϥ(ڸ໘൓ࣹޫͷ৭)ɻ
    • Shininess number: 0 ͱ 1 ͷؒͷϋΠϥΠτͷγϟʔϓωε஋ɻ0 Ͱ֦ࢄর໌ͷΑ͏ͳͨ͘͞Μ
    ͷڊେͳϋΠϥΠτΛಘɺ1 Ͱখ͞ͳൗ఺ΛಘΔɻ
    • Emission color: ޫ͕౰͍ͨͬͯͳ͍ΦϒδΣΫτͷ৭ɻ
    ➤ SeparateSpecular On | Off

    • εϖΩϡϥʔϥΠςΟϯά͕γΣʔμʔύεͷ࠷ޙʹ௥Ճ͞ΕΔɻεϖΩϡϥʔϥΠςΟϯά͸
    ςΫενϟϦϯάͷӨڹΛड͚ͳ͍ɻLighting ON ͕࢖༻͞Ε͍ͯΔ৔߹ʹͷΈޮՌ͕͋Δɻ
    ➤ Color Color-value

    • ΦϒδΣΫτͷιϦουΧϥʔΛઃఆɻ৭͸ׅހͰׅͬͨ4 ͭͷ RGBA ஋ɺ·ͨ͸֯Χοίͷ
    தͷ৭ͷϓϩύςΟʔ໊ͷ͍ͣΕ͔ɻ
    ➤ ColorMaterial AmbientAndDiffuse | Emission

    • ϚςϦΞϧʹͯઃఆ͞Εͨ৭ͷ୅ΘΓʹ௖఺৭Λ࢖༻͢ΔɻAmbientAndDiffuse͸ɺϚςϦΞ
    ϧͷ Ambient ͓Αͼ Diffuse ஋Λஔ͖׵͑ΔɻEmission͸ϚςϦΞϧͷ Emission ஋Λஔ͖׵
    ͑Δɻ

    View full-size slide

  60. ݻఆػೳϑΥά
    ݻఆػೳϑΥάʹ͍ͭͯ

    View full-size slide

  61. ݻఆػೳϑΥάͱ͸
    ➤ ϑΥά͸ੜ੒͞ΕͨϐΫηϧͷ৭ΛɺΧϝϥ͔Βͷڑ཭ʹ΋
    ͱ͍ͮͨҰఆͷΧϥʔʹ޲͚ͯɺϒϨϯυ͢Δɻ
    ➤ ϑΥάʹΑΓɺϒϨϯυ͞ΕͨϐΫηϧͷΞϧϑΝ஋͸मਖ਼
    ͤͣɺRGB ͷΈมߋ͞ΕΔɻ
    ➤ σϑΥϧτͷϑΥάઃఆ͸ ϥΠςΟϯά΢Οϯυ΢ ͷઃఆʹ
    ج͍ͮͯઃఆ͞ΕΔɻ

    View full-size slide

  62. ݻఆػೳϑΥάͷߏจ
    Fog {Fog Commands}
    ߏจ
    Fog Commands
    ➤ Mode Off | Global | Linear | Exp | Exp2

    • ϑΥάϞʔυΛఆٛ͢ΔɻσϑΥϧτ͸ Global ͰɺϑΥά͕ϨϯμϦ
    ϯάઃఆͰ༗ޮԽ͞Ε͍ͯΔ͔ʹΑΓ Off ͔ Exp2 ʹม׵͞ΕΔɻ
    ➤ Color ColorValue

    • ϑΥάͷ৭Λઃఆ͢Δɻ
    ➤ Density FloatValue

    • Exp ʢࢦ਺ʣϞʔυͷϑΥάͷີ౓Λઃఆ͢Δɻ
    ➤ Range FloatValue, FloatValue

    • Linear ʢϦχΞʣϞʔυͷϑΥάͷ Near ͓Αͼ Far ͷൣғΛઃఆ͢
    Δɻ

    View full-size slide

  63. ݻఆػೳΞϧϑΝςετ
    ݻఆػೳΞϧϑΝςετʹ͍ͭͯ

    View full-size slide

  64. ݻఆػೳΞϧϑΝςετͱ͸
    ➤ ΞϧϑΝςετ͸ɺΞϧϑΝ஋Λࢀরͯ͠ϐΫηϧ͕ը໘ʹඳ
    ը͞ΕΔ͔Ͳ͏͔Λ੍ޚ͢Δɻ
    ➤ ݻఆػೳΞϧϑΝςετ͸ɺ ϑϥάϝϯτγΣʔμʔ͕࢖༻
    ͞Ε͍ͯΔͱ͖͸ޮՌ͕ͳ͍ɻ
    ➤ ΄ͱΜͲͷϓϥοτϑΥʔϜͰ͸ɺΞϧϑΝςετ͸γΣʔμʔ
    Ͱ HLSL clip() ؔ਺Λ࢖༻ͯ͠ߦΘΕΔ(ύϑΥʔϚϯεͷ࠷
    దԽ)ɻ

    View full-size slide

  65. ݻఆػೳΞϧϑΝςετͷߏจ
    ߏจ
    AlphaTest Off
    AlphaTest Comparison AlphaValue
    AlphaValue
    0 ͱ 1 ͷؒͷෆಈখ਺఺਺ɻ

    View full-size slide

  66. ݻఆػೳςΫενϟ߹੒
    ݻఆػೳςΫενϟ߹੒ʹ͍ͭͯ

    View full-size slide

  67. ݻఆػೳςΫενϟ߹੒ͱ͸
    ➤ SetTextureίϚϯυΛ࢖༻ͯ͠ ద༻͢ΔςΫενϟͱͦͷίϯ
    όΠϯϞʔυ(߹੒ػೳ)Λࢦఆ͢Δ͜ͱ͕Ͱ͖Δɻ
    ➤ SetTexture ίϚϯυ͸ ϑϥάϝϯτϓϩάϥϜ͕࢖༻͞Εͯ
    ͍Δͱ͖͸ޮՌ͕ͳ͍(ϐΫηϧॲཧ͕γΣʔμʔͰ׬શʹද
    ݱ͞Ε͍ͯΔͨΊ)ɻ
    ➤ ύεͷதʹෳ਺ͷ SetTexture Λ΋ͭ͜ͱ͕Ͱ͖Δɻ
    ➤ SetTexture ίϚϯυ͸ Pass ͷऴΘΓʹ഑ஔ͢Δඞཁ͕͋Δɻ

    View full-size slide

  68. ݻఆػೳςΫενϟ߹੒ͷߏจ
    ߏจ
    SetTexture [TextureName] {Texture Block}
    TextureName ͸ςΫενϟϓϩύςΟʔͱͯ͠ఆٛ͢Δɻ
    ςΫενϟϒϩοΫʹ͸ςΫενϟΛద༻͢Δํ๏Λهࡌ͢Δɻ
    ςΫενϟϒϩοΫʹ͸ ҎԼͷ2 ͭͷίϚϯυ·ͰؚΉ͜ͱ͕Ͱ͖
    Δɻ
    ➤ combine
    ➤ constantColor

    View full-size slide

  69. ݻఆػೳςΫενϟ߹੒ͷߏจ
    Combine
    ➤ combine src1 * src2 : src1 ͱ src2 Λ৐ࢉɻ
    ➤ combine src1 + src2 : src1 ͱ src2 ΛՃࢉɻ
    ➤ combine src1 - src2 : src2 Λ src1 ΑΓݮࢉɻ
    ➤ combine src1 lerp ( src2 ) src3 : src3 ͱ src1 ͷิؒΛ src2 ͷΞϧϑΝΛ༻͍ͯߦ͏ɻิؒͷ޲͖͕ٯͰ
    ͋Δ͜ͱʹ஫ҙɻΞϧϑΝ͕ 1 ͷͱ͖ʹ src1ɺΞϧϑΝ͕ 0 ͷͱ͖ʹ src3 ͱͳΔɻ
    ➤ combine src1 * src2 + src3 : src1 Λ src2 ͷΞϧϑΝͰ৐ࢉ͠ src3 ΛՃࢉɻ
    ͢΂ͯͷ src ϓϩύςΟʔ͸ previousɺconstantɺprimaryɺ͋Δ͍͸ texture ͷ͍ͣΕ͔Ͱ͢ɻ
    previous ͸௚લͷ SetTexture ͷ݁Ռɻ
    primary ͸ lighting calculation ͷ৭·ͨ͸ bound Ͱ͋Δ৔߹͸௖఺Χϥʔɻ
    texture ͸ SetTexture Ͱࢦఆ͞Εͨ [TextureName] ɻ
    constant ͸ constantColor Ͱࢦఆͨ͠৭ɻ
    म০ࢠɿ
    ্Ͱࣔͨ͠ܭࢉࣜ͸ Double ·ͨ͸ Quad ΩʔϫʔυΛ೚ҙͰࢦఆ͢Δ͜ͱͰ݁ՌͷΧϥʔΛ 2 ഒ·ͨ͸ 4 ഒ
    ໌Δ͘Ͱ͖Δɻ
    lerp จݴΛআ͍ͨɺ͢΂ͯͷ src ϓϩύςΟʔ͸ɺ೚ҙͰ one - Λࢦఆ͢Δ͜ͱͰɺ݁Ռͷ৭Λωήʔτ͢Δ
    ͜ͱ͕Ͱ͖Δɻ
    ͢΂ͯͷ src ϓϩύςΟʔ͸ɺalpha Λࢦఆ͢Δ͜ͱͰΞϧϑΝͷΈΛऔಘͤ͞Δ͜ͱ͕Ͱ͖Δɻ

    View full-size slide

  70. ݻఆػೳςΫενϟ߹੒ͷߏจ
    ConstantColor
    ConstantColor color
    ఆ਺ΧϥʔΛఆٛ͠ɺcombine ίϚϯυͰ࢖༻Ͱ͖ΔΑ͏ʹ͠·͢ɻ
    constantColor (1,1,1,1)
    constantColor [_IlluminCol] //PropertiesͰ_IlluminColΛఆٛͯ͠Δ৔߹

    View full-size slide

  71. αϯϓϧ
    ݻఆؔ਺γΣʔμʔͷαϯϓϧ

    View full-size slide

  72. 2 ͭͷςΫενϟͷΞϧϑΝϒϨϯσΟϯά
    Shader "Examples/2 Alpha Blended Textures" {
    Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    _BlendTex ("Alpha Blended (RGBA) ", 2D) = "white" {}
    }
    SubShader {
    Pass {
    // Apply base texture
    SetTexture [_MainTex] {
    combine texture
    }
    // Blend in the alpha texture using the lerp operator
    SetTexture [_BlendTex] {
    combine texture lerp (texture) previous
    }
    }
    }
    }

    View full-size slide

  73. ΞϧϑΝ੍ޚͨࣗ͠ݾর໌
    Shader "Examples/Self-Illumination" {
    Properties {
    _MainTex ("Base (RGB) Self-Illumination (A)", 2D) = "white" {}
    }
    SubShader {
    Pass {
    // Set up basic white vertex lighting
    Material {
    Diffuse (1,1,1,1)
    Ambient (1,1,1,1)
    }
    Lighting On
    // Use texture alpha to blend up to white (= full illumination)
    SetTexture [_MainTex] {
    constantColor (1,1,1,1)
    combine constant lerp(texture) previous
    }
    // Multiply in texture
    SetTexture [_MainTex] {
    combine previous * texture
    }
    }
    }
    }

    View full-size slide

  74. ΞϧϑΝ੍ޚͨࣗ͠ݾর໌(৭ࢦఆ)
    Shader "Examples/Self-Illumination 2" {
    Properties {
    _IlluminCol ("Self-Illumination color (RGB)", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Self-Illumination (A)", 2D) = "white" {}
    }
    SubShader {
    Pass {
    // Set up basic white vertex lighting
    Material {
    Diffuse (1,1,1,1)
    Ambient (1,1,1,1)
    }
    Lighting On
    // Use texture alpha to blend up to white (= full illumination)
    SetTexture [_MainTex] {
    // Pull the color property into this blender
    constantColor [_IlluminCol]
    // And use the texture's alpha to blend between it and
    // vertex color
    combine constant lerp(texture) previous
    }
    // Multiply in texture
    SetTexture [_MainTex] {
    combine previous * texture
    }
    }
    }
    }

    View full-size slide

  75. ௖఺γΣʔμʔͷϥΠςΟϯάϓϩύςΟʔΛ׆༻
    Shader "Examples/Self-Illumination 3" {
    Properties {
    _IlluminCol ("Self-Illumination color (RGB)", Color) = (1,1,1,1)
    _Color ("Main Color", Color) = (1,1,1,0)
    _SpecColor ("Spec Color", Color) = (1,1,1,1)
    _Emission ("Emmisive Color", Color) = (0,0,0,0)
    _Shininess ("Shininess", Range (0.01, 1)) = 0.7
    _MainTex ("Base (RGB)", 2D) = "white" {}
    }
    SubShader {
    Pass {
    // Set up basic vertex lighting
    Material {
    Diffuse [_Color]
    Ambient [_Color]
    Shininess [_Shininess]
    Specular [_SpecColor]
    Emission [_Emission]
    }
    Lighting On
    // Use texture alpha to blend up to white (= full illumination)
    SetTexture [_MainTex] {
    constantColor [_IlluminCol]
    combine constant lerp(texture) previous
    }
    // Multiply in texture
    SetTexture [_MainTex] {
    combine previous * texture
    }
    }
    }
    }

    View full-size slide

  76. αʔϑΣΠεγΣʔμʔ
    ➤ UnityͷϥΠςΟϯάύΠϓϥ
    Πϯʹ૊Έࠐ·ΕΔαʔϑΣ
    ΠεγΣʔμʔͷ͍ͭͯݟͯ
    ͍͘ɻ
    • ʲUnityϚχϡΞϧʳSurfaceγΣʔμʔ

    View full-size slide

  77. αʔϑΣΠεγΣʔμʔͱ͸
    αʔϑΣΠεγΣʔμʔʹ͍ͭͯ

    View full-size slide

  78. αʔϑΣΠεγΣʔμʔͱ͸
    ➤ ௖఺γΣʔμʔͱ Fragment γΣʔμʔͷϓϩάϥϛϯά Λ࢖༻
    ͨ͠৔߹ΑΓ΋ɺϦοτγΣʔμʔͷهड़Λίʔυੜ੒ʹΑͬ
    ͯང͔ʹ؆୯ʹ͢Δख๏ɻ
    ➤ Surface Shaders͸खಈͰهड़͢ΔඞཁͳΔ܁Γฦ͠ίʔυΛ͢
    ΂ͯੜ੒͍ͯ͠Δ͚ͩɻ
    ➤ Cg/HLSL ͰγΣʔμʔίʔυΛهड़͢Δɻ
    ➤ Surface Shaders ίϯύΠϥ͸ɺͲΜͳೖྗ͕ඞཁͰɺͲΜͳग़
    ྗΛग़͔͢ͱ͍͏͜ͱΛܾఆ͠ɺ௖఺γΣʔμʔͱϑϥάϝϯ
    τγΣʔμʔ Λੜ੒͢ΔɻForward ϨϯμϦϯά΍ Deferred Ϩ
    ϯμϦϯάΛॲཧ͢ΔϨϯμϦϯάύε΋ੜ੒͢Δɻ

    View full-size slide

  79. αʔϑΣΠεγΣʔμʔͷهड़৔ॴ
    αʔϑΣΠεγΣʔμʔͷهड़͢Δ৔ॴʹ͍ͭͯ

    View full-size slide

  80. αʔϑΣΠεγΣʔμʔͷهड़৔ॴ
    ➤ ݻఆؔ਺γΣʔμʔ/௖఺ɾϑϥάϝϯτγΣʔμʔ͸Passϒ
    ϩοΫ಺ʹهड़͢Δ͕ɺαʔϑΣΠεγΣʔμʔͷ৔߹ෳ਺ύ
    εΛ࣋ͭ௖఺ɾϑϥάϝϯτγΣʔμʔʹίϯύΠϧ͞ΕΔͨ
    ΊɺPassϒϩοΫΛهड़͠ͳ͍(SubShaderϒϩοΫ಺ʹهड़
    ͞ΕΔ)ɻ
    ➤ Cg/HLSLͷهड़͸ CGPROGRAM..ENDCG ϒϩοΫ಺ʹஔ͔
    ΕΔɻ

    View full-size slide

  81. ίϯύΠϧ໋ྩ
    αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩʹ͍ͭͯ

    View full-size slide

  82. αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩ
    #pragma surface surfaceFunction lightModel [optionalparams]
    ➤ surfaceFunction

    • Cg Ͱهड़͞ΕͨαʔϑΣΠεγΣʔμʔͷؔ਺໊Λࢦఆ͢Δɻ

    surfΛࢦఆͨ͠৔߹ɺvoid surf(Input IN, inout o) ͱ͍͏ؔ਺Λ࣋ͭ͜ͱΛҙ
    ຯ͢Δɻ͜͜ͷ Input ͸લ΋ͬͯఆٛ͢Δඞཁͷ͋Δೖྗߏ଄ମɻInput ͸ɺsurface ؔ਺͕ඞཁ
    ͱ͢ΔςΫενϟ࠲ඪͱ௥Ճͷࣗಈม਺ΛؚΉඞཁ͕͋Δ(ৄࡉ͸ޙड़)ɻ͸
    αʔϑΣΠεγΣʔμʔ͕ఆ͍ٛͯ͠Δೖग़ྗߏ଄ମɻ࢖༻͢ΔlightModelʹΑͬͯ࢖༻͢΂͖
    ೖग़ྗߏ଄ମ͕มΘΔ(ͭ·Γ͸਺छྨ͋Δɻৄࡉ͸ޙड़)ɻ
    ➤ lightModel

    • ࢖༻͢ΔϥΠςΟϯάϞσϧɻࣗલͷϥΠςΟϯάϞσϧΛهड़͢Δํ๏ʹؔͯ͠͸ɺαʔϑΣ
    ΠεγΣʔμʔͰͷΧελϜϥΠςΟϯάϞσϧ Λࢀরɻ

    ✴ Standard 

    ✴ ۚଐΛදݱ͢ΔϥΠςΟϯάϞσϧΛར༻͢ΔɻαʔϑΣΠεγΣʔμʔͷೖग़ྗߏ଄ମ
    ʹ͸SurfaceOutputStandardΛ࢖͏͜ͱɻ
    ✴ StandardSpecular 

    ✴ ڸ໘Λදݱ͢ΔϥΠςΟϯάϞσϧΛར༻͢ΔɻαʔϑΣΠεγΣʔμʔͷೖग़ྗߏ଄ମ
    ʹ͸SurfaceOutputStandardSpecularΛ࢖͏͜ͱɻ
    ✴ Lambert

    ✴ Lambert (σϑϡʔζ)Λར༻͢Δɻ
    ✴ BlinnPhong

    ✴ BlinnPhong (εϖΩϡϥ) Λར༻͢Δɻ

    View full-size slide

  83. αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩ
    #pragma surface surfaceFunction lightModel [optionalparams]
    ➤ [optionalparams]

    • alpha/decalΦϓγϣϯ
    ★ alpha or alpha:auto

    ✴ ΞϧϑΝςετΛߦ͏Α͏ࢦఆ͢Δɻ
    ★ alpha:fade

    ✴ ैདྷͷΞϧϑΝϒϨϯσΟϯά(ΦϒδΣΫτͷϑΣʔυΛߦ͏Α͏ͳϒϨϯυϞʔυ)Λ
    ࢖༻͢Δɻ
    ★ alpha:premul

    ✴ ΞϧϑΝϒϨϯσΟϯάʹϓϨϚϧνϓϥΠυ ϒϨϯσΟϯάΛར༻͢Δɻ
    ★ alphatest:VariableFloat

    ✴ ΞϧϑΝςετΛ༗ޮʹ͢ΔɻςετͰΧοτ͢ΔΞϧϑΝͷᮢ஋ΛVariableFloatʹࢦ
    ఆ͢Δɻ
    ★ keepalpha

    ✴ ೖྗ͞ΕͨΞϧϑΝ஋Λग़ྗʹΩʔϓ͢Δɻ
    ★ decal:add

    ✴ Additive decal shader (e.g. terrain AddPass). This is meant for objects that lie atop of 


    other surfaces, and use additive blending. See Surface Shader Examples

    ★ decal:blend

    ✴ Semitransparent decal shader. This is meant for objects that lie atop of other surfaces, 


    and use alpha blending. See Surface Shader Examples
    ಁ໌౓ͱΞϧϑΝςετ ͸ɺσΟϨΫςΟϒ alpha ͓Αͼ alphatest ʹΑ੍ͬͯޚ͞ΕΔɻ ಁ໌౓ʹ͸௨ৗɺೋछྨ͋Δɻͻͱͭ͸ैདྷܕ
    ͷΞϧϑΝ ϒϨϯσΟϯάʢΦϒδΣΫτͷϑΣʔυΞ΢τʹ࢖ΘΕΔʣɻ ΋͏ͻͱͭ͸ɺΑΓ෺ཧతʹઆಘྗͷ͋ΔʮϓϨϚϧνϓϥ
    Πυ ϒϨϯσΟϯάʯʢ൒ಁ໌ͷαʔϑΣʔε͕ద੾ͳڸ໘൓ࣹΛอͯΔΑ͏ʹ͢Δʣɻ

    View full-size slide

  84. αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩ
    #pragma surface surfaceFunction lightModel [optionalparams]
    ➤ [optionalparams]

    • ௥Ճؔ਺Φϓγϣϯ
    ★ vertex:VertexFunction

    ✴ ௖఺γΣʔμʔΛఆ͍ٛͨ͠৔߹ʹࢦఆ͢ΔɻVertexFunction͸௖఺γΣʔμʔؔ਺໊Λ
    ࢦఆ͢Δɻ௖఺γΣʔμʔؔ਺ͷҾ਺ʹ͸inout appdata_fullߏ଄ମΛ࢖͏ඞཁ͕͋Δɻ
    ೚ҙͰୈೋҾ਺ʹout InputܕΛར༻Ͱ͖Δɻ
    ★ finalcolor:ColorFunction

    ✴ ࠷ऴతͳϐΫηϧ৭Λௐઅ͢ΔͨΊͷؔ਺Λఆ͍ٛͨ͠৔߹ʹࢦఆ͢ΔɻColorFunction
    ʹ͸ఆٛ͢Δؔ਺໊Λࢦఆ͢Δɻ͜ͷؔ਺ͷҾ਺ʹ͸(Input IN, SurfaceOutput o, inout
    fixed4 color)Λར༻͢Δ(ม਺໊͸ԿͰ΋ྑ͍)ɻ࠷ऴతͳग़ྗ৭Λfixed4 colorʹ֨ೲ͢
    Δ͜ͱͰϐΫηϧ৭Λௐ੔Ͱ͖Δɻ
    ★ finalgbuffer:ColorFunction

    ✴ Custom deferred path for altering gbuffer content.

    ★ finalprepass:ColorFunction

    ✴ Custom prepass base path.

    View full-size slide

  85. αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩ
    #pragma surface surfaceFunction lightModel [optionalparams]
    ➤ [optionalparams]

    • ӨͱςοηϨʔγϣϯʹؔ͢ΔΦϓγϣϯ
    ★ addshadow

    ✴ γϟυ΢Ωϟελ͓ΑͼίϨΫλύεΛ௥Ճ͢Δɻ௨ৗɺΧελϜ௖఺ฤूͰ࢖༻͞Ε
    ΔͷͰɺγϟυ΢ΩϟεςΟϯά΋खଓ͖త௖఺ΞχϝʔγϣϯΛऔಘ͠·͢ɻଟ͘ͷ৔
    ߹ɺγΣʔμʔ͸ϑΥʔϧόοΫ͔Βγϟυ΢ΩϟελʔύεΛ࢖༻͢Δ͜ͱ͕Ͱ͖Δͨ
    Ίɺಛผͳγϟυ΢ͷॲཧΛߦ͏ඞཁ͸ͳ͍ɻ
    ★ fullforwardshadows

    ✴ Support all light shadow types in Forward rendering path. By default shaders only 


    support shadows from one directional light in forward rendering (to save on internal 


    shader variant count). If you need point or spot light shadows in forward rendering, use


    this directive.

    ★ tessellate:TessFunction

    ✴ CDX11 GPU ςοηϨʔγϣϯΛ࢖͏ɻৄ͘͠͸ DX11 / OpenGL ίΞςοηϨʔγϣ
    ϯͷαʔϑΣʔεγΣʔμʔΛࢀরɻ


    View full-size slide

  86. αʔϑΣΠεγΣʔμʔίϯύΠϧ໋ྩ
    #pragma surface surfaceFunction lightModel [optionalparams]
    ➤ [optionalparams]

    • ίʔυੜ੒໋ྩΦϓγϣϯ
    ★ exclude_path:deferred, exclude_path:forward, exclude_path:prepass

    ✴ ͦΕͧΕDeferred ShadingɺForward RenderingɺLegacy Deferred ShadingͷPassੜ੒Λແޮʹ͢
    ΔίϚϯυɻ
    ★ noshadow

    ✴ ͜ͷγΣʔμʔͰγϟυ΢ͷαϙʔτΛແޮʹ͢Δɻ

    ★ noambient

    ✴ ΞϯϏΤϯτϥΠτ΍ϥΠτϓϩʔϒΛద༻͠ͳ͍ɻ
    ★ novertexlights

    ✴ Forward ϨϯμϦϯάͰɺϥΠτϓϩʔϒ΍௖఺͝ͱͷϥΠτΛద༻͠ͳ͍ɻ
    ★ nolightmap

    ✴ ϥΠτϚοϓͷαϙʔτΛແޮʹ͢Δɻ
    ★ nodynlightmap

    ✴ ϥϯλΠϜͷμΠφϛοΫͳάϩʔόϧΠϧϛωʔγϣϯͷαϙʔτΛແޮʹ͢Δɻ
    ★ nodirlightmap

    ✴ σΟϨΫγϣφϧϥΠτϚοϓΛແޮʹ͢Δɻ
    ★ nofog

    ✴ ϑΥάͷαϙʔτΛແޮʹ͢Δɻ
    ★ nometa

    ✴ Does not generate a “meta” pass (that’s used by lightmapping & dynamic global illumination to
    extract surface information).

    ★ noforwardadd

    ✴ ɻ Forward ϨϯμϦϯά௥ՃύεΛແޮʹ͢Δɻ͜ΕʹΑΓɺγΣʔμʔ͸׬શͳσΟϨΫγϣφ
    ϧϥΠταϙʔτ͠ɺͦͷଞ͢΂ͯͷϥΠτ͸ɺ௖఺͝ͱ/SH Ͱܭࢉ͞ΕΔɻ

    View full-size slide

  87. ೖྗߏ଄ମ
    αʔϑΣΠεγΣʔμʔͷೖྗߏ଄ମʹ͍ͭͯ

    View full-size slide

  88. ೖྗߏ଄ମInput
    ҎԼͷ஋͕ೖྗߏ଄ମInputʹೖྗͰ͖Δɻ
    ➤ float2 uvNXXX

    • PropertiesͰࢦఆͨ͠ςΫενϟͷςΫενϟ࠲ඪɻXXX͸ม਺໊ʹஔ͖׵͑ΔɻNʹ͸Կݸ໨ͷuvม਺ͳͷ͔ͱ͍͏஋͕ೖΔ(1
    ݸ໨ͷ৔߹͸ͳ͠ɺ2ݸ໨͸uv2XXXɺ…)ɻ
    ➤ float3 viewDir

    • Ϗϡʔํ޲ɻࢹࠩޮՌɺϦϜϥΠςΟϯάͳͲͷܭࢉʹ࢖༻Ͱ͖Δɻ
    ➤ float4 XXXColor

    • ิؒ͞Εͨ௖఺͝ͱͷ৭ɻXXXʹ͸PropertiesͰࢦఆͨ͠ม਺໊Λ͚ͭΔ͜ͱ͕Ͱ͖Δɻ
    ➤ float4 screenPos

    • εΫϦʔϯ࠲ඪͷҐஔɻ
    ➤ float3 worldPos

    • ϫʔϧυ࠲ඪͷҐஔɻ
    ➤ float3 worldRefl

    • Surface Shaders ͕ o.Normal ʹॻ͖ࠐ·ͳ͍৔߹ ͷϫʔϧυ࠲ඪͷ൓ࣹϕΫτϧɻ
    ➤ float3 worldNormal

    • Surface Shaders ͕ o.Normal ʹॻ͖ࠐ·ͳ͍৔߹ ͷϫʔϧυ࠲ඪͷ๏ઢϕΫτϧɻ
    ➤ float3 worldRefl; INTERNAL_DATA

    • Surface Shaders ͕ o.Normal ʹॻ͖ࠐΉ৔߹ ͷϫʔϧυ࠲ඪͷ൓ࣹϕΫτϧɻϐΫηϧ͝ͱͷ๏ઢϚοϓʹج͍ͮͯɺ൓ࣹϕΫτ
    ϧΛऔಘ͢Δʹ͸ɺWorldReflectionVector (IN, o.Normal) Λ࢖༻͢Δɻ
    ➤ float3 worldNormal; INTERNAL_DATA

    • Surface Shaders ͕ o.Normal ʹॻ͖ࠐΉ৔߹ ͷϫʔϧυ࠲ඪͷ൓ࣹϕΫτϧɻϐΫηϧ͝ͱͷ๏ઢϚοϓʹج͍ͮͯɺ๏ઢϕΫτ
    ϧΛऔಘ͢Δʹ͸ɺWorldNormalVector (IN, o.Normal) Λ࢖༻͢Δɻ

    View full-size slide

  89. ೖग़ྗߏ଄ମ
    αʔϑΣΠεγΣʔμʔͷೖग़ྗߏ଄ମʹ͍ͭͯ

    View full-size slide

  90. ೖग़ྗߏ଄ମ
    ➤ ίϯύΠϧ໋ྩͷlightModelʹΑͬͯߏ଄ମͷछྨ͕͔ΘΔɻ
    ➤ ඪ४Ͱ͸SurfaceOutputߏ଄ମΛ࢖͏
    ➤ lightModel͕Standardͷ৔߹SurfaceOutputStandardߏ଄ମΛ
    ࢖͏ɻ
    ➤ lightModel͕StandardSpecularͷ৔߹
    SurfaceOutputStandardSpecularߏ଄ମΛ࢖͏ɻ

    View full-size slide

  91. ೖग़ྗߏ଄ମ
    struct SurfaceOutput
    {
    fixed3 Albedo; // diffuse color
    fixed3 Normal; // tangent space normal, if written
    fixed3 Emission;
    half Specular; // specular power in 0..1 range
    fixed Gloss; // specular intensity
    fixed Alpha; // alpha for transparencies
    };
    struct SurfaceOutputStandard
    {
    fixed3 Albedo; // base (diffuse or specular) color
    fixed3 Normal; // tangent space normal, if written
    half3 Emission;
    half Metallic; // 0=non-metal, 1=metal
    half Smoothness; // 0=rough, 1=smooth
    half Occlusion; // occlusion (default 1)
    fixed Alpha; // alpha for transparencies
    };
    struct SurfaceOutputStandardSpecular
    {
    fixed3 Albedo; // diffuse color
    fixed3 Specular; // specular color
    fixed3 Normal; // tangent space normal, if written
    half3 Emission;
    half Smoothness; // 0=rough, 1=smooth
    half Occlusion; // occlusion (default 1)
    fixed Alpha; // alpha for transparencies
    };

    View full-size slide

  92. αϯϓϧ
    αʔϑΣΠεγΣʔμʔͷαϯϓϧ

    View full-size slide

  93. Lambert (σϑϡʔζ)
    Shader "Example/Diffuse Simple" {
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float4 color : COLOR;
    };
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = 1;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  94. ςΫενϟ
    Shader "Example/Diffuse Texture" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    };
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  95. ๏ઢϚοϐϯά
    Shader "Example/Diffuse Bump" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    };
    sampler2D _MainTex;
    sampler2D _BumpMap;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex,
    IN.uv_MainTex).rgb;
    o.Normal = UnpackNormal (tex2D (_BumpMap,
    IN.uv_BumpMap));
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  96. ϦϜϥΠςΟϯά
    Shader "Example/Rim" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}
    _RimColor ("Rim Color", Color) = (0.26,0.19,0.16,0.0)
    _RimPower ("Rim Power", Range(0.5,8.0)) = 3.0
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float3 viewDir;
    };
    sampler2D _MainTex;
    sampler2D _BumpMap;
    float4 _RimColor;
    float _RimPower;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    o.Normal = UnpackNormal (tex2D (_BumpMap,
    IN.uv_BumpMap));
    half rim = 1.0 - saturate(dot (normalize(IN.viewDir),
    o.Normal));
    o.Emission = _RimColor.rgb * pow (rim, _RimPower);
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  97. ࡉ෦ςΫενϟ
    Shader "Example/Detail" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}
    _Detail ("Detail", 2D) = "gray" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float2 uv_Detail;
    };
    sampler2D _MainTex;
    sampler2D _BumpMap;
    sampler2D _Detail;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex,
    IN.uv_MainTex).rgb;
    o.Albedo *= tex2D (_Detail, IN.uv_Detail).rgb *
    2;
    o.Normal = UnpackNormal (tex2D (_BumpMap,
    IN.uv_BumpMap));
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  98. ը໘ۭؒ಺ͷࡉ෦ςΫενϟ
    Shader "Example/ScreenPos" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _Detail ("Detail", 2D) = "gray" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float4 screenPos;
    };
    sampler2D _MainTex;
    sampler2D _Detail;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex,
    IN.uv_MainTex).rgb;
    float2 screenUV = IN.screenPos.xy /
    IN.screenPos.w;
    screenUV *= float2(8,6);
    o.Albedo *= tex2D (_Detail, screenUV).rgb * 2;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  99. ΩϡʔϒϚοϓ൓ࣹ
    Shader "Example/WorldRefl" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _Cube ("Cubemap", CUBE) = "" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float3 worldRefl;
    };
    sampler2D _MainTex;
    samplerCUBE _Cube;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex,
    IN.uv_MainTex).rgb * 0.5;
    o.Emission = texCUBE (_Cube,
    IN.worldRefl).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  100. ๏ઢϚοϓʹӨڹ͞ΕΔΩϡʔϒϚοϓ൓ࣹ
    Shader "Example/WorldRefl Normalmap" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}
    _Cube ("Cubemap", CUBE) = "" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float3 worldRefl;
    INTERNAL_DATA
    };
    sampler2D _MainTex;
    sampler2D _BumpMap;
    samplerCUBE _Cube;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb *
    0.5;
    o.Normal = UnpackNormal (tex2D (_BumpMap,
    IN.uv_BumpMap));
    o.Emission = texCUBE (_Cube, WorldReflectionVector
    (IN, o.Normal)).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  101. ੈքۭؒͷҐஔΛհͨ͠εϥΠε
    Shader "Example/Slices" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _BumpMap ("Bumpmap", 2D) = "bump" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    Cull Off
    CGPROGRAM
    #pragma surface surf Lambert
    struct Input {
    float2 uv_MainTex;
    float2 uv_BumpMap;
    float3 worldPos;
    };
    sampler2D _MainTex;
    sampler2D _BumpMap;
    void surf (Input IN, inout SurfaceOutput o) {
    clip (frac((IN.worldPos.y+IN.worldPos.z*0.1) * 5) -
    0.5);
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    o.Normal = UnpackNormal (tex2D (_BumpMap,
    IN.uv_BumpMap));
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  102. ๏ઢԡ͠ग़͠
    Shader "Example/Normal Extrusion" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _Amount ("Extrusion Amount", Range(-1,1)) = 0.5
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert vertex:vert
    struct Input {
    float2 uv_MainTex;
    };
    float _Amount;
    void vert (inout appdata_full v) {
    v.vertex.xyz += v.normal * _Amount;
    }
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  103. ௖఺͝ͱʹܭࢉ͞ΕͨΧελϜͷσʔλ
    Shader "Example/Custom Vertex Data" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert vertex:vert
    struct Input {
    float2 uv_MainTex;
    float3 customColor;
    };
    void vert (inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input,o);
    o.customColor = abs(v.normal);
    }
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    o.Albedo *= IN.customColor;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  104. ࠷ऴతͳΧϥʔम০ࢠʢColor Modifierʣ
    Shader "Example/Tint Final Color" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _ColorTint ("Tint", Color) = (1.0, 0.6, 0.6, 1.0)
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert finalcolor:mycolor
    struct Input {
    float2 uv_MainTex;
    };
    fixed4 _ColorTint;
    void mycolor (Input IN, SurfaceOutput o, inout
    fixed4 color)
    {
    color *= _ColorTint;
    }
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex,
    IN.uv_MainTex).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  105. Final Color Modifier ʹΑΔΧελϜϑΥά
    Shader "Example/Fog via Final Color" {
    Properties {
    _MainTex ("Texture", 2D) = "white" {}
    _FogColor ("Fog Color", Color) = (0.3, 0.4, 0.7, 1.0)
    }
    SubShader {
    Tags { "RenderType" = "Opaque" }
    CGPROGRAM
    #pragma surface surf Lambert finalcolor:mycolor vertex:myvert
    struct Input {
    float2 uv_MainTex;
    half fog;
    };
    void myvert (inout appdata_full v, out Input data)
    {
    UNITY_INITIALIZE_OUTPUT(Input,data);
    float4 hpos = mul (UNITY_MATRIX_MVP, v.vertex);
    hpos.xy/=hpos.w;
    data.fog = min (1, dot (hpos.xy, hpos.xy)*0.5);
    }
    fixed4 _FogColor;
    void mycolor (Input IN, SurfaceOutput o, inout fixed4 color)
    {
    fixed3 fogColor = _FogColor.rgb;
    #ifdef UNITY_PASS_FORWARDADD
    fogColor = 0;
    #endif
    color.rgb = lerp (color.rgb, fogColor, IN.fog);
    }
    sampler2D _MainTex;
    void surf (Input IN, inout SurfaceOutput o) {
    o.Albedo = tex2D (_MainTex, IN.uv_MainTex).rgb;
    }
    ENDCG
    }
    Fallback "Diffuse"
    }

    View full-size slide

  106. ௖఺ɾϑϥάϝϯτγΣʔμʔ
    ➤ ௖఺γΣʔμʔɾϑϥάϝϯτ
    γΣʔμʔʹ͍ͭͯݟ͍ͯ͘ɻ
    • ʲUnityϚχϡΞϧʳ௖఺γΣʔμʔͱ Fragment γΣʔ
    μʔͷϓϩάϥϛϯά
    • ʲΏʹͯ͘උ๨࿥ʳUnityγΣʔμʔ·ͱΊ

    View full-size slide

  107. ௖఺ɾϑϥάϝϯτγΣʔμʔͱ͸
    ௖఺ɾϑϥάϝϯτγΣʔμʔʹ͍ͭͯ

    View full-size slide

  108. ௖఺ɾϑϥάϝϯτγΣʔμʔͱ͸
    ➤ ͦΕͧΕ௖఺ɾϐΫηϧσʔλॲཧ࣌ʹݺͼग़͢͜ͱͷͰ͖Δϓϩάϥ
    Ϝɻ
    ➤ ௖఺γΣʔμʔؔ਺͸௖఺̍ͭ̍ͭΛॲཧ͢Δࡍʹݺ͹ΕΔɻ
    ➤ ϑϥάϝϯτγΣʔμʔؔ਺͸̍ͭ̍ͭͷϐΫηϧΛॲཧ͢Δࡍʹݺ͹
    ΕΔɻ
    ➤ Cg/HLSLͰهड़͢Δɻ
    ➤ UnityͰ͸ϥΠςΟϯάʹ൓Ԡ͢ΔγΣʔμʔΛॻ͘৔߹͸αʔϑΣΠε
    γΣʔμʔΛॻ͘΂͖ɻ௖఺ɾϑϥάϝϯτγΣʔμʔͰϥΠςΟϯά
    Λܭࢉ͢Δ৔߹શͯࣗ෼Ͱ࣮૷͢Δඞཁ͕͋Δɻ
    ➤ ϥΠςΟϯάͷܭࢉ͕ඞཁͳ͍ΤϑΣΫτʹར༻͢Δ͜ͱ͕ଟ͍(Π
    ϝʔδΤϑΣΫτ౳)ɻ

    View full-size slide

  109. ௖఺γΣʔμʔ
    ➤ ֤௖఺ʹରͯ͠ॲཧΛߦ͏ؔ਺
    ➤ جຊతʹ͸ϫʔϧυม׵/ϏϡʔΠϯάม׵/ϓϩδΣΫγϣϯ
    ม׵Λߦ͏ɻ
    ➤ ௖఺γΣʔμʔͷ໭Γ஋͸ɺϥελϥΠζޙʹϑϥάϝϯτ
    γΣʔμʔͰར༻͢Δɻ

    View full-size slide

  110. ϑϥάϝϯτγΣʔμʔ
    ➤ ֤ϐΫηϧʹରͯ͠ߦ͏ॲཧ
    ➤ جຊతʹ͸௖఺γΣʔμʔ͔Βड͚औͬͨ஋Λ΋ͱʹɺ࠷ऴ
    తͳϐΫηϧ৭Λܭࢉ͢Δɻ
    ➤ ϑϥάϝϯτγΣʔμʔ͸float4ܕͷ৭৘ใΛฦ͢ඞཁ͕͋
    Δɻ͜Ε͕࠷ऴతͳϐΫηϧ৭ͱͳΔɻ

    View full-size slide

  111. ௖఺ɾϑϥάϝϯτγΣʔμʔͷهड़৔ॴ
    ௖఺ɾϑϥάϝϯτγΣʔμʔͷهड़৔ॴʹ͍ͭͯ

    View full-size slide

  112. ௖఺ɾϑϥάϝϯτγΣʔμʔͷهड़৔ॴ
    ➤ PassϒϩοΫ಺ʹهड़͢Δɻ
    ➤ Cg/HLSLͷهड़͸CGPROGRAM..ENDCG ϒϩοΫ಺ʹஔ͔
    ΕΔɻ

    View full-size slide

  113. ίϯύΠϧ໋ྩ
    ௖఺ɾϑϥάϝϯτγΣʔμʔίϯύΠϧ໋ྩʹ͍ͭͯ

    View full-size slide

  114. ௖఺ɾϑϥάϝϯτγΣʔμʔίϯύΠϧ໋ྩ
    γΣʔμʔؔ਺ࢦఆ໋ྩ
    ➤ #pragma vertex name

    • ௖఺γΣʔμʔͱͯ͠ name ͱ͍͏໊લͷؔ਺Λఆٛ
    ➤ #pragma fragment name

    • ϑϥάϝϯτγΣʔμʔͱͯ͠ name ͱ͍͏໊લͷؔ਺Λఆٛ
    ➤ #pragma geometry name

    • DX10 ͷδΦϝτϦγΣʔμʔͱͯ͠ name ͱ͍͏໊લͷؔ਺Λఆٛɻ͜ͷΦϓγϣϯ͸ࣗಈత
    ʹ #pragma target 4.0 ͷίϯύΠϧ໋ྩΛΦϯʹ͢Δɻ
    ➤ #pragma hull name

    • DX11 ͷ Hull γΣʔμʔͱͯ͠ name ͱ͍͏໊લͷؔ਺Λఆٛɻ͜ͷΦϓγϣϯ͸ࣗಈతʹ
    #pragma target 5.0 ͷίϯύΠϧ໋ྩΛΦϯʹ͢Δɻ
    ➤ #pragma domain name

    • DX11 ͷ Domein γΣʔμʔͱͯ͠ name ͱ͍͏໊લͷؔ਺Λఆٛɻ͜ͷΦϓγϣϯ͸ࣗಈతʹ
    #pragma target 5.0 ͷίϯύΠϧ໋ྩΛΦϯʹ͢Δɻ
    ͦΕͧΕͷεχϖοτʹ͸࠷௿Ͱ΋௖఺ϓϩάϥϜͱϑϥάϝϯτϓϩάϥϜؚ͕·Ε͍ͯͳ͚Ε
    ͹ͳΒͳ͍ɻͦΕΏ͑ʹ #pragma vertex ͱ #pragma fragment ໋ྩ͸ඞͣඞཁɻ

    View full-size slide

  115. ௖఺ɾϑϥάϝϯτγΣʔμʔίϯύΠϧ໋ྩ
    ͦͷଞͷίϯύΠϧ໋ྩ
    ➤ #pragma target requirements

    • ίϯύΠϧ͢ΔγΣʔμʔλʔήοτͷࢦఆɻৄࡉ͸ Shader Compilation Target Levels Λࢀরɻ
    ➤ #pragma only_renderers space_separated_names

    • ࢦఆͷϨϯμϦϯάϓϥοτϑΥʔϜͷΈγΣʔμʔΛίϯύΠϧɻσϑΥϧτͰ͸͢΂ͯͷϨϯμ
    ϥʔͷγΣʔμʔ͕ίϯύΠϧ͞ΕΔɻ
    ➤ #pragma exclude_renderers space_separated_names

    • ࢦఆͷϨϯμϦϯάϓϥοτϑΥʔϜͷΈγΣʔμʔΛίϯύΠϧ͠ͳ͍ɻσϑΥϧτͰ͸͢΂ͯͷ
    ϨϯμϥʔͷγΣʔμʔ͕ίϯύΠϧ͞ΕΔɻ
    ➤ #pragma multi_compile …_

    • ϚϧνγΣʔμʔόϦΞϯτͱͱ΋ʹಈ࡞͢Δɻ
    ➤ #pragma enable_d3d11_debug_symbols

    • DirectX 11 ༻ʹίϯύΠϧ͞ΕͨγΣʔμʔͷσόοά৘ใΛੜ੒͢Δɻ͜ΕʹΑΓɺVisual
    Studio 2012 (·ͨ͸ͦΕҎ߱ͷόʔδϣϯ)ͷάϥϑΟοΫεσόοΨʔΛܦ༝ͯ͠γΣʔμʔͷσ
    όοά͕ՄೳʹͳΔɻ

    View full-size slide

  116. ௖఺ɾϑϥάϝϯτγΣʔμʔίϯύΠϧ໋ྩ
    ϨϯμϦϯάϓϥοτϑΥʔϜࢦఆ໋ྩ
    ➤ d3d9 - Direct3D 9.

    ➤ d3d11 - Direct3D 11/12

    ➤ glcore - OpenGL 3.x/4.x

    ➤ gles - OpenGL ES 2.0

    ➤ gles3 - OpenGL ES 3.x

    ➤ metal - iOS/Mac Metal

    ➤ d3d11_9x - Ұൠతʹ͸ WSA/WP8 ϓϥοτϑΥʔϜ্Ͱ࢖༻͞ΕΔ Direct3D 11
    9.x ϑΟʔνϟʔϨϕϧɻ
    ➤ xbox360 - Xbox 360

    ➤ xboxone - Xbox One

    ➤ ps3 - PlayStation 3

    ➤ ps4 - PlayStation 4

    ➤ psp2 - PlayStation Vita

    ➤ n3ds - Nintendo 3DS

    ➤ wiiu - Nintendo Wii U
    Unity ͸͍͔ͭ͘ͷϨϯμϦϯά API ʢ͢ͳΘͪ Direct3D 9 ͱ OpenGL ʣΛαϙʔτ͠ɺσϑΥϧτͰ͢΂ͯͷγΣʔμʔϓϩάϥϜ͸
    αϙʔτ͞Ε͍ͯΔϨϯμϥʔʹίϯύΠϧ͞ΕΔɻͲͷϨϯμϥʔʹίϯύΠϧ͢Δ͔͸ #pragma only_renderers ͋Δ͍͸ #pragma
    exclude_renderers σΟϨΫςΟϒͰࢦఆͰ͖Δɻ͜Ε͸ɺಛఆͷγΣʔμʔ͕͋ΔϨϯμϥʔͰ͔͠࢖༻Ͱ͖ͣଞͰ͸࢖༻Ͱ͖ͳ͍৔߹
    ʹར༻͢Δɻ

    View full-size slide

  117. ηϚϯςΟοΫ
    ௖఺ɾϑϥάϝϯτγΣʔμʔͷηϚϯςΟοΫʹ͍ͭͯ

    View full-size slide

  118. ηϚϯςΟοΫͱ͸
    ➤ ηϚϯςΟοΫ͸ɺύϥϝʔλͷ࢖༻໨తʹ͍ͭͯͷ৘ใΛ఻
    ͑ΔγΣʔμͷೖྗ·ͨ͸ग़ྗʹ઀ଓ͞Ε͍ͯΔจࣈྻɻ
    ➤ ηϚϯςΟοΫ͸ɺγΣʔμʔεςʔδؒͰ౉͞ΕΔ͢΂ͯͷ
    ม਺ʹඞཁͱ͞ΕΔɻ
    ➤ γΣʔμʔม਺ʹηϚϯςΟοΫΛ௥Ճ͢ΔͨΊͷߏจ͸ɺ࣍
    ͷͱ͓Γ(DirectX HLSL)ɻ

    View full-size slide

  119. ௖఺γΣʔμʔηϚϯςΟοΫ
    ➤ Ҿ਺ʹ͸ೖྗύϥϝʔλʔηϚϯςΟοΫʹଇͬͨม਺Λ೚
    ҙͰࢦఆͰ͖Δɻೖྗύϥϝʔλʔ͕ଟ͍৔߹͸ߏ଄ମʹ·
    ͱΊͯɺͦͷߏ଄ମΛҾ਺ʹऔΔ͜ͱ΋Ͱ͖Δɻ
    ➤ ໭Γ஋ʹ௖఺࠲ඪͱͳΔfloat4ܕͷ஋΋͘͠͸ɺ͜ΕΛؚΉߏ
    ଄ମΛࢦఆ͠ͳ͚Ε͹ͳΒͳ͍ɻ͜ͷ௖఺࠲ඪͷ஋ʹ͸
    POSITION΋͘͠͸SV_POSITIONηϚϯςΟοΫΛࢦఆ͠ͳ
    ͚Ε͹ͳΒͳ͍ɻ
    ➤ ࢖༻Ͱ͖ΔηϚϯςΟοΫͷৄࡉ͸MSDNΛࢀরɻ

    View full-size slide

  120. ௖఺γΣʔμʔηϚϯςΟοΫ
    ೖྗύϥϝʔλʔηϚϯςΟοΫ
    ೖྗ આ໌ λΠϓ
    BINORMAL[n] ै๏ઢ float4
    BLENDINDICES[n] ϒϨϯυࢦ਺ uint
    BLENDWEIGHT[n] ϒϨϯυ΢ΣΠτ float
    COLOR[n] σΟϑϡʔζͱεϖΩϡϥ৭ float4
    NORMAL[n] ๏ઢϕΫτϧ float4
    POSITION[n] ΦϒδΣΫτۭؒ಺ͷ௖఺Ґஔɻ float4
    POSITIONT ม׵͞Εͨ௖఺Ґஔɻ float4
    PSIZE[n] ϙΠϯταΠζ float
    TANGENT[n] ઀ઢϕΫτϧ float4
    TEXCOORD[n] ςΫενϟ࠲ඪ float4

    View full-size slide

  121. ௖఺γΣʔμʔηϚϯςΟοΫ
    ग़ྗύϥϝʔλʔηϚϯςΟοΫ
    ग़ྗ આ໌ λΠϓ
    COLOR[n] ֦ࢄ·ͨ͸εϖΩϡϥ৭ float4
    FOG ௖఺ϑΥά float
    POSITION[n] ۉ࣭ͳۭؒͰͷ௖఺ͷҐஔɻWͰʢxɺyɺzʣΛ෼ׂ͢Δ͜ͱʹΑΓɺ
    εΫϦʔϯۭؒ಺ͷҐஔΛܭࢉ͢Δɻ͢΂ͯͷ௖఺γΣʔμ͸ɺ͜ͷη
    ϚϯςΟοΫΛ࣋ͭύϥϝʔλΛॻ͖ग़͢ඞཁ͕͋ΔɻDirect3D 10Ҏ
    ߱ͷ৔߹Ͱ͋Ε͹SV_POSITIONΛར༻ՄೳɻDirect3D 10ҎલͷγΣʔ
    μʔίʔυͰSV_POSITIONηϚϯςΟοΫΛར༻ͨ͠৔߹ɺ୯ʹ
    POSITIONηϚϯςΟοΫͱͯ͠ղऍ͞ΕΔɻ
    float4
    PSIZE ϙΠϯταΠζ float
    TESSFACTOR[n] ςοηϨʔγϣϯ܎਺ float
    TEXCOORD[n] ςΫενϟ࠲ඪ float4

    View full-size slide

  122. ϑϥάϝϯτγΣʔμʔηϚϯςΟοΫ
    ➤ ϑϥάϝϯτγΣʔμؔ਺Ͱ͸໭Γ஋ʹ৭ͱͳΔfloat4ܕͷ஋
    ΋͘͠͸ɺfixed4ܕΛࢦఆ͠ͳ͚Ε͹ͳΒͳ͍ɻ·ͨɺ͜ͷ஋
    ʹ͸COLORηϚϯςΟοΫΛࢦఆ͠ͳ͚Ε͹ͳΒͳ͍ɻ
    ➤ #pragma target 3.0ΛPASSͰࢦఆ͢Δ͜ͱͰɺWPOSηϚϯ
    ςΟΫεΛ͚ͭͨҾ਺Λ࣋ͨͤΔ͜ͱ͕Ͱ͖Δɻ͜ͷҾ਺ʹ
    ͸εΫϦʔϯ࠲ඪ͕୅ೖ͞Ε͍ͯΔɻ

    View full-size slide

  123. ϑϥάϝϯτγΣʔμʔηϚϯςΟοΫ
    ೖྗύϥϝʔλʔηϚϯςΟοΫ
    ೖྗ આ໌ λΠϓ
    COLOR[n] ֦ࢄ·ͨ͸ڸ໘৭ɻ float4
    TEXCOORD[n] ςΫενϟ࠲ඪ float4
    VFACE ϓϦϛςΟϒ͕ޙΖ޲͖͔Ͳ͏͔Λ͍ࣔͯ͠Δුಈখ਺఺εΧϥʔɻਖ਼ͷ
    ஋͸ɺΧϝϥʹ௚໘͍ͯ͠Δɻෛͷ஋͸ɺޙํʹ௚໘͍ͯ͠Δɻ
    ʢ஫ʣ ͜ͷηϚϯςΟοΫ͕Ͱར༻Ͱ͖ΔͷDirect3D 9γΣʔμʔϞσ
    ϧ3.0ɻDirect3Dͷ10Ҏ߱Ͱ͸ɺ࢖༻SV_IsFrontFaceΛ୅ΘΓʹ࢖༻͢
    Δɻ
    float
    VPOS εΫϦʔϯۭؒ಺ͷϐΫηϧҐஔʢXɺYʣɻDirect3Dͷ10Ҏ߱ͷγΣʔμ
    ʔͰ༻͍Δ৔߹͸SV_VPOSΛ༻͍Δɻৄࡉ͸Direct3D 9 VPOSͱDirect3D
    10 SV_PositionΛࢀরɻ
    float2

    View full-size slide

  124. ϑϥάϝϯτγΣʔμʔηϚϯςΟοΫ
    ग़ྗύϥϝʔλʔηϚϯςΟοΫ
    ग़ྗ આ໌ λΠϓ
    COLOR[n] ग़ྗ৭ float4
    DEPTH[n] ग़ྗͷਂ͞ float

    View full-size slide

  125. γεςϜ஋ηϚϯςΟοΫ
    ➤ Direct3D 10Ҏ߱ͰͷΈαϙʔτ͞Ε͍ͯΔηϚϯςΟοΫɻ
    ➤ SV_઀಄ࣙͰ࢝·Δɻ
    ➤ ৄࡉ͸MSDNΛࢀরɻ

    View full-size slide

  126. Cg/HLSLͰPropertyΛࢀর͢Δ
    Cg/HLSL ͰγΣʔμʔϓϩύςΟʔΛࢀর͢Δख๏ʹ͍ͭͯ

    View full-size slide

  127. Cg/HLSL ͰγΣʔμʔϓϩύςΟʔΛࢀর͢Δ
    ྫ͑͹࣍ͷγΣʔμʔϓϩύςΟʔ

    _MyColor ("Some Color", Color) = (1,1,1,1) 

    _MyVector ("Some Vector", Vector) = (0,0,0,0) 

    _MyFloat ("My float", Float) = 0.5 

    _MyTexture ("Texture", 2D) = "white" {} 

    _MyCubemap ("Cubemap", CUBE) = "" {}
    ʹ͍ͭͯɺCg/HLSL Ͱࢀর͢ΔͨΊʹએݴ͢Δίʔυ͸
    fixed4 _MyColor; // low precision type is usually enough for colors

    float4 _MyVector;

    float _MyFloat;

    sampler2D _MyTexture;

    samplerCUBE _MyCubemap;


    Cg/HLSL ͸uniformΩʔϫʔυΛهड़Ͱ͖Δ͕ɺඞਢͰ͸ͳ͍ɻ
    uniform float4 _MyColor;

    View full-size slide

  128. ShaderLabͱCg/HLSLͷม਺ܕͷϚοϐϯά
    ShaderLab ͷϓϩύςΟʔλΠϓ͸ Cg/HLSL ม਺λΠϓͱͷରԠ͸࣍ͷΑ͏ʹ
    Ϛοϐϯά͞ΕΔɻ
    ➤ Color ͱ Vector ϓϩύςΟʔ͸ɺfloat4ɺhalf4͋Δ͍͸fixed4ม਺ʹରԠɻ

    ➤ Range ͱ Float ϓϩύςΟʔ͸ɺfloatɺhalf͋Δ͍͸fixedม਺ʹରԠɻ

    ➤ Texture ϓϩύςΟʔ͸ɺ௨ৗʢ 2D ʣͷςΫενϟͷ৔߹͸sampler2Dม਺
    ʹରԠɺ3D ςΫενϟͷ৔߹͸sampler3Dม਺ʹରԠɻ

    View full-size slide

  129. UnityCG.cginc
    Unity಺ଂͷincludeϑΝΠϧUnityCG.cgincʹ͍ͭͯ

    View full-size slide

  130. UnityCG.cginc
    ➤ Unity͕༻ҙ͍ͯ͠ΔɺγΣʔμʔΛॻ͘ࡍʹ࢖͏͜ͱͷͰ͖
    Δؔ਺΍ม਺ɺϚΫϩͳͲ͕ఆٛͯ͋͠ΔincludeϑΝΠϧɻ
    ➤ #include “UnityCG.cginc”એݴʹΑΓར༻ՄೳʹͳΔɻ

    View full-size slide

  131. UnityCG.cginc ͷσʔλߏ଄
    ➤ struct appdata_base

    • Ґஔɺ๏ઢɺςΫενϟ࠲ඪΛ΋ͭɻ
    ➤ struct appdata_tan

    • Ґஔɺ๏ઢɺ઀ઢɺςΫενϟ࠲ඪΛ΋ͭɻ
    ➤ struct appdata_full

    • Ґஔɺ๏ઢɺ઀ઢɺ௖఺Χϥʔɺ;ͨͭͷςΫενϟ࠲ඪ
    Λ΋ͭɻ
    ➤ struct appdata_img

    • ҐஔɺςΫενϟ࠲ඪΛ΋ͭɻ
    ௖఺γΣʔμʔೖྗߏ଄ମఆٛ

    View full-size slide

  132. UnityCG.cginc ͷ൚༻ϔϧύʔؔ਺
    ➤ float3 WorldSpaceViewDir (float4 v)

    • ϫʔϧυۭؒͷಛఆͷΦϒδΣΫτۭؒͷ௖఺Ґஔ͔ΒΧϝϥʹ޲͔ͬͨ(ਖ਼نԽ͞Ε͍ͯͳ͍)
    ํ޲Λऔಘ͢Δɻ
    ➤ float3 ObjSpaceViewDir (float4 v)

    • ΦϒδΣΫτۭؒͷಛఆͷΦϒδΣΫτۭؒͷ௖఺Ґஔ͔ΒΧϝϥʹ޲͔ͬͨʢਖ਼نԽ͞Ε͍ͯ
    ͳ͍ʣํ޲Λऔಘ͢Δɻ
    ➤ float2 ParallaxOffset (half h, half height, half3 viewDir)

    • ࢹࠩ๏ઢϚοϐϯάͷ UV ΦϑηοτΛܭࢉɻ
    ➤ fixed Luminance (fixed3 c)

    • ৭Λً౓ʢάϨʔεέʔϧʣʹม׵͢Δɻ
    ➤ fixed3 DecodeLightmap (fixed4 color)

    • Unity ϥΠτϚοϓͷ৭Λσίʔυ͢ΔʢϓϥοτϑΥʔϜʹΑΓɺRGBM ͋Δ͍͸ dLDR ʣɻ
    ➤ float4 EncodeFloatRGBA (float v)

    • ਫ਼౓ͷ௿͍ϨϯμϦϯάλʔήοτΛ֨ೲ͢ΔͨΊɺ0 ʙ 1 ͷൣғͷුಈখ਺఺Λ RGBAcolor ʹ
    Τϯίʔυ͢Δɻ
    ➤ float DecodeFloatRGBA (float4 enc)

    • RGBA color Λ float ʹσίʔυ͢Δɻಉ༷ʹɺfloat2 EncodeFloatRG (float v) ͓Αͼ float
    DecodeFloatRG (float2 enc) ͸ೋͭͷΧϥʔνϟωϧΛ࢖༻͢Δɻ
    ➤ float2 EncodeViewNormalStereo (float3 n)

    • Ϗϡʔۭؒ๏ઢΛ 0 ʙ 1 ͷൣғͷೋͭͷ਺ࣈʹΤϯίʔυ͢Δɻ
    ➤ float3 DecodeViewNormalStereo (float4 enc4)

    • enc4.xy ͔ΒϏϡʔۭؒ๏ઢΛσίʔυ͢Δɻ

    View full-size slide

  133. UnityCG.cginc ͷ Forward Rendering ϔϧύʔؔ਺
    Forward Rendering ༻ͷؔ਺ɻ( ForwardBase ·ͨ͸ ForwardAdd ͷύελΠϓ)
    ➤ float3 WorldSpaceLightDir (float4 v)

    • ϫʔϧυۭؒͷΦϒδΣΫτۭؒͷ௖఺Ґஔ͔ΒϥΠτ΁޲͚ͨʢਖ਼نԽ͞Εͯͳ͍ʣํ޲Λܭ
    ࢉ͢Δɻ
    ➤ float3 ObjSpaceLightDir (float4 v)

    • ΦϒδΣΫτۭؒͷΦϒδΣΫτۭؒͷ௖఺Ґஔ͔ΒϥΠτ΁޲͚ͨʢਖ਼نԽ͞Εͯͳ͍ʣํ޲
    Λܭࢉ͢Δɻ
    ➤ float3 Shade4PointLights (...)

    • ࢛ͭͷϙΠϯτϥΠτ͔ΒɺϥΠτͷσʔλΛ vector ʹ֨ೲͯ͠ɺً౓Λࢉग़͢ΔɻForward
    Rendering ͸֤௖఺͝ͱͷϥΠςΟϯάʹ͜ͷ৘ใΛ࢖༻͢Δɻ
    Shade4PointLights (
    unity_4LightPosX0, unity_4LightPosY0, unity_4LightPosZ0,
    unity_LightColor0, unity_LightColor1, unity_LightColor2, unity_LightColor3,
    unity_4LightAtten0, worldPos, worldN );

    ͷΑ͏ͳܗͰར༻͢Δɻ
    ֤ύϥϝʔλʔ͸UnityShaderVariables.cgincͷϥΠςΟϯάม਺Λࢀর

    View full-size slide

  134. UnityCG.cginc ͷ Vertex-lit ϔϧύʔؔ਺
    ௖఺ϥΠςΟϯάΛߦ͏৔߹ʹͷΈศར
    ➤ float3 ShadeVertexLights (float4 vertex, float3 normal)

    • 4 ͭͷ֤௖఺ϥΠτ͔ΒΦϒδΣΫτۭؒͷҐஔͱ๏ઢΛࢦఆͯ͠ɺً౓ͱ؀ڥޫΛࢉग़͢Δɻ

    View full-size slide

  135. UnityShaderVariables.cginc
    Unity಺ଂͷincludeϑΝΠϧUnityShaderVariables.cgincʹ͍ͭͯ

    View full-size slide

  136. UnityShaderVariables.cginc
    ➤ UnityͰγΣʔμʔΛॻ͘৔߹ɺUnityShaderVariables.cginc
    ϑΝΠϧ͸ࣗಈతʹinclude͞ΕΔɻ
    ➤ ม׵ߦྻ΍ɺϨϯμϦϯάʹӨڹΛٴ΅͢Մೳੑͷ͋ΔΦϒδΣ
    Ϋτͷ৘ใΛऔಘ͢Δม਺͕਺ଟ͘ఆٛ͞Ε͍ͯΔɻ

    View full-size slide

  137. UnityShaderVariables.cgincͷม׵ߦྻ
    ͜ΕΒ͢΂ͯͷϚτϦοΫε͸ float4x4ܕɻ

    View full-size slide

  138. UnityShaderVariables.cgincͷΧϝϥม਺

    View full-size slide

  139. UnityShaderVariables.cgincͷ࣌ؒม਺

    View full-size slide

  140. UnityShaderVariables.cgincͷϥΠςΟϯά༻ม਺
    ϥΠτύϥϝʔλʔ͸ɺͲͷϨϯμϦϯάύε ͕࢖༻͞Ε͍ͯΔ͔ɺ ·ͨͲͷ LightMode Pass λά ͕
    γΣʔμʔ಺Ͱ࢖༻͞Ε͍ͯΔ͔ʹΑͬͯɺҟͳΔํ๏ͰγΣʔμʔʹύε͞ΕΔɻ
    Forward RenderingͰ࢖༻Ͱ͖ΔϥΠςΟϯά༻ม਺(ύελΠϓ ForwardBase ͱ ForwardAdd )

    View full-size slide

  141. UnityShaderVariables.cgincͷϥΠςΟϯά༻ม਺
    ϥΠτύϥϝʔλʔ͸ɺͲͷϨϯμϦϯάύε ͕࢖༻͞Ε͍ͯΔ͔ɺ ·ͨͲͷ LightMode Pass λά ͕
    γΣʔμʔ಺Ͱ࢖༻͞Ε͍ͯΔ͔ʹΑͬͯɺҟͳΔํ๏ͰγΣʔμʔʹύε͞ΕΔɻ
    Deferred RenderingͰ࢖༻Ͱ͖ΔϥΠςΟϯά༻ม਺

    View full-size slide

  142. UnityShaderVariables.cgincͷϑΥάɾΞϯϏΤϯτม਺

    View full-size slide

  143. UnityShaderVariables.cgincͷͦͷଞͷม਺

    View full-size slide

  144. αϯϓϧ
    ௖఺ɾϑϥάϝϯτγΣʔμʔαϯϓϧ

    View full-size slide

  145. ୯৭
    Shader "Unlit/SingleColor"
    {
    Properties
    {
    // Color property for material inspector, default to white
    _Color ("Main Color", Color) = (1,1,1,1)
    }
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // vertex shader
    // this time instead of using "appdata" struct, just spell inputs manually,
    // and instead of returning v2f struct, also just return a single output
    // float4 clip position
    float4 vert (float4 vertex : POSITION) : SV_POSITION
    {
    return mul(UNITY_MATRIX_MVP, vertex);
    }
    // color from the material
    fixed4 _Color;
    // pixel shader, no inputs needed
    fixed4 frag () : SV_Target
    {
    return _Color; // just return it
    }
    ENDCG
    }
    }
    }

    View full-size slide

  146. ๏ઢํ޲Ͱ৭෇͚
    Shader "Unlit/WorldSpaceNormals"
    {
    // no Properties block this time!
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // include file that contains UnityObjectToWorldNormal helper function
    #include "UnityCG.cginc"
    struct v2f {
    // we'll output world space normal as one of regular ("texcoord") interpolators
    half3 worldNormal : TEXCOORD0;
    float4 pos : SV_POSITION;
    };
    // vertex shader: takes object space normal as input too
    v2f vert (float4 vertex : POSITION, float3 normal : NORMAL)
    {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, vertex);
    // UnityCG.cginc file contains function to transform
    // normal from object to world space, use that
    o.worldNormal = UnityObjectToWorldNormal(normal);
    return o;
    }
    fixed4 frag (v2f i) : SV_Target
    {
    fixed4 c = 0;
    // normal is a 3D vector with xyz components; in -1..1
    // range. To display it as color, bring the range into 0..1
    // and put into red, green, blue components
    c.rgb = i.worldNormal*0.5+0.5;
    return c;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  147. ๏ઢʹΑΔ৭෇͚
    Shader "Debug/Normals" {
    SubShader {
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // vertex input: position, normal
    struct appdata {
    float4 vertex : POSITION;
    float3 normal : NORMAL;
    };
    struct v2f {
    float4 pos : SV_POSITION;
    fixed4 color : COLOR;
    };
    v2f vert (appdata v) {
    v2f o;
    o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
    o.color.xyz = v.normal * 0.5 + 0.5;
    o.color.w = 1.0;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target { return i.color; }
    ENDCG
    }
    }
    }

    View full-size slide

  148. UV஋Ͱ৭෇͚
    Shader "Unlit/Show UVs"
    {
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    struct v2f {
    float2 uv : TEXCOORD0;
    float4 pos : SV_POSITION;
    };
    v2f vert (
    float4 vertex : POSITION, // vertex position input
    float2 uv : TEXCOORD0 // first texture coordinate input
    )
    {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, vertex);
    o.uv = uv;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target
    {
    return fixed4(i.uv, 0, 0);
    }
    ENDCG
    }
    }
    }

    View full-size slide

  149. ௖఺৭Λදࣔ
    Shader "Debug/Vertex color" {
    SubShader {
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // vertex input: position, color
    struct appdata {
    float4 vertex : POSITION;
    fixed4 color : COLOR;
    };
    struct v2f {
    float4 pos : SV_POSITION;
    fixed4 color : COLOR;
    };
    v2f vert (appdata v) {
    v2f o;
    o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
    o.color = v.color;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target { return i.color; }
    ENDCG
    }
    }
    }

    View full-size slide

  150. ઀ઢʹΑΔ৭෇͚
    Shader "Debug/Tangents" {
    SubShader {
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    // vertex input: position, tangent
    struct appdata {
    float4 vertex : POSITION;
    float4 tangent : TANGENT;
    };
    struct v2f {
    float4 pos : SV_POSITION;
    fixed4 color : COLOR;
    };
    v2f vert (appdata v) {
    v2f o;
    o.pos = mul( UNITY_MATRIX_MVP, v.vertex );
    o.color = v.tangent * 0.5 + 0.5;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target { return i.color; }
    ENDCG
    }
    }
    }

    View full-size slide

  151. SkyBoxΛCubeMapͱͯ͠๏ઢΛ࢖ͬͨಁաॲཧ
    Shader "Unlit/SkyReflection"
    {
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    struct v2f {
    half3 worldRefl : TEXCOORD0;
    float4 pos : SV_POSITION;
    };
    v2f vert (float4 vertex : POSITION, float3 normal : NORMAL)
    {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, vertex);
    // compute world space position of the vertex
    float3 worldPos = mul(_Object2World, vertex).xyz;
    // compute world space view direction
    float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
    // world space normal
    float3 worldNormal = UnityObjectToWorldNormal(normal);
    // world space reflection vector
    o.worldRefl = reflect(-worldViewDir, worldNormal);
    return o;
    }
    fixed4 frag (v2f i) : SV_Target
    {
    // sample the default reflection cubemap, using the reflection vector
    half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
    // decode cubemap data into actual color
    half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
    // output it!
    fixed4 c = 0;
    c.rgb = skyColor;
    return c;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  152. ଞͷςΫενϟΛՃࢉ
    Shader "Unlit/More Textures"
    {
    Properties {
    // three textures we'll use in the material
    _MainTex("Base texture", 2D) = "white" {}
    _OcclusionMap("Occlusion", 2D) = "white" {}
    _BumpMap("Normal Map", 2D) = "bump" {}
    }
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    // exactly the same as in previous shader
    struct v2f {
    float3 worldPos : TEXCOORD0;
    half3 tspace0 : TEXCOORD1;
    half3 tspace1 : TEXCOORD2;
    half3 tspace2 : TEXCOORD3;
    float2 uv : TEXCOORD4;
    float4 pos : SV_POSITION;
    };
    v2f vert (float4 vertex : POSITION, float3 normal : NORMAL, float4 tangent : TANGENT, float2 uv : TEXCOORD0)
    {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, vertex);
    o.worldPos = mul(_Object2World, vertex).xyz;
    half3 wNormal = UnityObjectToWorldNormal(normal);
    half3 wTangent = UnityObjectToWorldDir(tangent.xyz);
    half tangentSign = tangent.w * unity_WorldTransformParams.w;
    half3 wBitangent = cross(wNormal, wTangent) * tangentSign;
    o.tspace0 = half3(wTangent.x, wBitangent.x, wNormal.x);
    o.tspace1 = half3(wTangent.y, wBitangent.y, wNormal.y);
    o.tspace2 = half3(wTangent.z, wBitangent.z, wNormal.z);
    o.uv = uv;
    return o;
    }
    // textures from shader properties
    sampler2D _MainTex;
    sampler2D _OcclusionMap;
    sampler2D _BumpMap;
    fixed4 frag (v2f i) : SV_Target
    {
    // same as from previous shader...
    half3 tnormal = UnpackNormal(tex2D(_BumpMap, i.uv));
    half3 worldNormal;
    worldNormal.x = dot(i.tspace0, tnormal);
    worldNormal.y = dot(i.tspace1, tnormal);
    worldNormal.z = dot(i.tspace2, tnormal);
    half3 worldViewDir = normalize(UnityWorldSpaceViewDir(i.worldPos));
    half3 worldRefl = reflect(-worldViewDir, worldNormal);
    half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, worldRefl);
    half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
    fixed4 c = 0;
    c.rgb = skyColor;
    // modulate sky color with the base texture, and the occlusion map
    fixed3 baseColor = tex2D(_MainTex, i.uv).rgb;
    fixed occlusion = tex2D(_OcclusionMap, i.uv).r;
    c.rgb *= baseColor;
    c.rgb *= occlusion;
    return c;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  153. Checkerboardύλʔϯ
    Shader "Unlit/Checkerboard"
    {
    Properties
    {
    _Density ("Density", Range(2,50)) = 30
    }
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    struct v2f
    {
    float2 uv : TEXCOORD0;
    float4 vertex : SV_POSITION;
    };
    float _Density;
    v2f vert (float4 pos : POSITION, float2 uv : TEXCOORD0)
    {
    v2f o;
    o.vertex = mul(UNITY_MATRIX_MVP, pos);
    o.uv = uv * _Density;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target
    {
    float2 c = i.uv;
    c = floor(c) / 2;
    float checker = frac(c.x + c.y) * 2;
    return checker;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  154. ֨ࢠঢ়ʹ੾Γൈ͘
    Shader "Unlit/Screen Position"
    {
    Properties
    {
    _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Pass
    {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma target 3.0
    // note: no SV_POSITION in this struct
    struct v2f {
    float2 uv : TEXCOORD0;
    };
    v2f vert (
    float4 vertex : POSITION, // vertex position input
    float2 uv : TEXCOORD0, // texture coordinate input
    out float4 outpos : SV_POSITION // clip space position output
    )
    {
    v2f o;
    o.uv = uv;
    outpos = mul(UNITY_MATRIX_MVP, vertex);
    return o;
    }
    sampler2D _MainTex;
    fixed4 frag (v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
    {
    // screenPos.xy will contain pixel integer coordinates.
    // use them to implement a checkerboard pattern that skips rendering
    // 4x4 blocks of pixels
    // checker value will be negative for 4x4 blocks of pixels
    // in a checkerboard pattern
    screenPos.xy = floor(screenPos.xy * 0.25) * 0.5;
    float checker = -frac(screenPos.r + screenPos.g);
    // clip HLSL instruction stops rendering a pixel if value is negative
    clip(checker);
    // for pixels that were kept, read the texture and output it
    fixed4 c = tex2D (_MainTex, i.uv);
    return c;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  155. Diffuse Light
    Shader "Lit/Simple Diffuse"
    {
    Properties
    {
    [NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Pass
    {
    // indicate that our pass is the "base" pass in forward
    // rendering pipeline. It gets ambient and main directional
    // light data set up; light direction in _WorldSpaceLightPos0
    // and color in _LightColor0
    Tags {"LightMode"="ForwardBase"}
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc" // for UnityObjectToWorldNormal
    #include "UnityLightingCommon.cginc" // for _LightColor0
    struct v2f
    {
    float2 uv : TEXCOORD0;
    fixed4 diff : COLOR0; // diffuse lighting color
    float4 vertex : SV_POSITION;
    };
    v2f vert (appdata_base v)
    {
    v2f o;
    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    o.uv = v.texcoord;
    // get vertex normal in world space
    half3 worldNormal = UnityObjectToWorldNormal(v.normal);
    // dot product between normal and light direction for
    // standard diffuse (Lambert) lighting
    half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
    // factor in the light color
    o.diff = nl * _LightColor0;
    return o;
    }
    sampler2D _MainTex;
    fixed4 frag (v2f i) : SV_Target
    {
    // sample texture
    fixed4 col = tex2D(_MainTex, i.uv);
    // multiply by lighting
    col *= i.diff;
    return col;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  156. ؀ڥޫΛߟྀͨ͠Diffuse Light
    Shader "Lit/Diffuse With Ambient"
    {
    Properties
    {
    [NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Pass
    {
    Tags {"LightMode"="ForwardBase"}
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    #include "UnityLightingCommon.cginc"
    struct v2f
    {
    float2 uv : TEXCOORD0;
    fixed4 diff : COLOR0;
    float4 vertex : SV_POSITION;
    };
    v2f vert (appdata_base v)
    {
    v2f o;
    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    o.uv = v.texcoord;
    half3 worldNormal = UnityObjectToWorldNormal(v.normal);
    half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
    o.diff = nl * _LightColor0;
    // the only difference from previous shader:
    // in addition to the diffuse lighting from the main light,
    // add illumination from ambient or light probes
    // ShadeSH9 function from UnityCG.cginc evaluates it,
    // using world space normal
    o.diff.rgb += ShadeSH9(half4(worldNormal,1));
    return o;
    }
    sampler2D _MainTex;
    fixed4 frag (v2f i) : SV_Target
    {
    fixed4 col = tex2D(_MainTex, i.uv);
    col *= i.diff;
    return col;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  157. Shadow
    Shader "Lit/Shadow Casting"
    {
    SubShader
    {
    // very simple lighting pass, that only does non-textured ambient
    Pass
    {
    Tags {"LightMode"="ForwardBase"}
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    struct v2f
    {
    fixed4 diff : COLOR0;
    float4 vertex : SV_POSITION;
    };
    v2f vert (appdata_base v)
    {
    v2f o;
    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
    half3 worldNormal = UnityObjectToWorldNormal(v.normal);
    // only evaluate ambient
    o.diff.rgb = ShadeSH9(half4(worldNormal,1));
    o.diff.a = 1;
    return o;
    }
    fixed4 frag (v2f i) : SV_Target
    {
    return i.diff;
    }
    ENDCG
    }
    // shadow caster rendering pass, implemented manually
    // using macros from UnityCG.cginc
    Pass
    {
    Tags {"LightMode"="ShadowCaster"}
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #pragma multi_compile_shadowcaster
    #include "UnityCG.cginc"
    struct v2f {
    V2F_SHADOW_CASTER;
    };
    v2f vert(appdata_base v)
    {
    v2f o;
    TRANSFER_SHADOW_CASTER_NORMALOFFSET(o)
    return o;
    }
    float4 frag(v2f i) : SV_Target
    {
    SHADOW_CASTER_FRAGMENT(i)
    }
    ENDCG
    }
    }
    }

    View full-size slide

  158. DiffuseͱShadow
    Shader "Lit/Diffuse With Shadows"
    {
    Properties
    {
    [NoScaleOffset] _MainTex ("Texture", 2D) = "white" {}
    }
    SubShader
    {
    Pass
    {
    Tags {"LightMode"="ForwardBase"}
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    #include "Lighting.cginc"
    // compile shader into multiple variants, with and without shadows
    // (we don't care about any lightmaps yet, so skip these variants)
    #pragma multi_compile_fwdbase nolightmap nodirlightmap nodynlightmap novertexlight
    // shadow helper functions and macros
    #include "AutoLight.cginc"
    struct v2f
    {
    float2 uv : TEXCOORD0;
    SHADOW_COORDS(1) // put shadows data into TEXCOORD1
    fixed3 diff : COLOR0;
    fixed3 ambient : COLOR1;
    float4 pos : SV_POSITION;
    };
    v2f vert (appdata_base v)
    {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    o.uv = v.texcoord;
    half3 worldNormal = UnityObjectToWorldNormal(v.normal);
    half nl = max(0, dot(worldNormal, _WorldSpaceLightPos0.xyz));
    o.diff = nl * _LightColor0.rgb;
    o.ambient = ShadeSH9(half4(worldNormal,1));
    // compute shadows data
    TRANSFER_SHADOW(o)
    return o;
    }
    sampler2D _MainTex;
    fixed4 frag (v2f i) : SV_Target
    {
    fixed4 col = tex2D(_MainTex, i.uv);
    // compute shadow attenuation (1.0 = fully lit, 0.0 = fully shadowed)
    fixed shadow = SHADOW_ATTENUATION(i);
    // darken light's illumination with shadow, keep ambient intact
    fixed3 lighting = i.diff * shadow + i.ambient;
    col.rgb *= lighting;
    return col;
    }
    ENDCG
    }
    // shadow casting support
    UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
    }
    }

    View full-size slide

  159. Fog
    Shader "Custom/TextureCoordinates/Fog" {
    SubShader {
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    //Needed for fog variation to be compiled.
    #pragma multi_compile_fog
    #include "UnityCG.cginc"
    struct vertexInput {
    float4 vertex : POSITION;
    float4 texcoord0 : TEXCOORD0;
    };
    struct fragmentInput{
    float4 position : SV_POSITION;
    float4 texcoord0 : TEXCOORD0;
    //Used to pass fog amount around number should be a free texcoord.
    UNITY_FOG_COORDS(1)
    };
    fragmentInput vert(vertexInput i){
    fragmentInput o;
    o.position = mul (UNITY_MATRIX_MVP, i.vertex);
    o.texcoord0 = i.texcoord0;
    //Compute fog amount from clip space position.
    UNITY_TRANSFER_FOG(o,o.position);
    return o;
    }
    fixed4 frag(fragmentInput i) : SV_Target {
    fixed4 color = fixed4(i.texcoord0.xy,0,0);
    //Apply fog (additive pass are automatically handled)
    UNITY_APPLY_FOG(i.fogCoord, color);
    //to handle custom fog color another option would have been
    //#ifdef UNITY_PASS_FORWARDADD
    // UNITY_APPLY_FOG_COLOR(i.fogCoord, color, float4(0,0,0,0));
    //#else
    // fixed4 myCustomColor = fixed4(0,0,1,0);
    // UNITY_APPLY_FOG_COLOR(i.fogCoord, color, myCustomColor);
    //#endif
    return color;
    }
    ENDCG
    }
    }
    }

    View full-size slide

  160. ΧϦϯάͱਂ౓ςετ
    ➤ ΧϦϯάͱਂ౓ςετʹ͍ͭ
    ͯղઆ͢Δɻ
    • ʲUnityϚχϡΞϧʳΧϦϯάͱਂ౓ςΫενϟ
    • ʲڧՐͰਐΊʳUnityͰͷZϑΝΠςΟϯάରॲ๏

    View full-size slide

  161. ΧϦϯάͱ͸
    ΧϦϯάʹ͍ͭͯ

    View full-size slide

  162. ΧϦϯάͷ֓ཁ
    ➤ ΧϦϯά͸ɺࢹ఺ͱ൓ରଆʹ޲͍ͨϙϦΰϯΛϨϯμϦϯά
    ͠ͳ͍ɺ࠷దԽɻ
    ➤ UnityͰ͸͜ͷΧϦϯάΛγΣʔμʔ͔Β੍ޚ͢Δ͜ͱ͕Ͱ͖
    Δɻ

    View full-size slide

  163. ΧϦϯάͷߏจ
    Cull Back | Front | Off
    ߏจ
    ϙϦΰϯͷͲͪΒଆΛΧϦϯά͢Δʢඳը͠ͳ͍ʣ੍͔ޚɻ

    ➤ Back
    • ࢹ఺ͱ൓ରଆͷϙϦΰϯΛϨϯμϦϯά͠ͳ͍Α͏ʹ͢Δ(σϑΥϧ
    τ) ɻ
    ➤ Front
    • ࢹ఺ͱಉ͡ଆͷϙϦΰϯΛϨϯμϦϯά͠ͳ͍ɻΦϒδΣΫτΛ൓
    స͢Δͷʹ࢖༻͢Δɻ
    ➤ Off
    • ΧϦϯάΛແޮʹͯ͠ɺ͢΂ͯͷ໘Λඳը͢Δɻ

    View full-size slide

  164. ਂ౓ςετͱ͸
    ਂ౓ςετʹ͍ͭͯ

    View full-size slide

  165. ਂ౓ςετ
    ➤ ਂ౓ςετʹΑΓɺγʔϯͷதͰ΋ͬͱ΋͍ۙΦϒδΣΫτද໘
    ͷΈඳը͞ΕΔΑ͏ʹͰ͖Δɻ
    ➤ ΦϒδΣΫτͷਂ౓৘ใ͸σϓεόοϑΝͰ؅ཧ͞ΕΔɻ
    ➤ γΣʔμʔ͔Βσϓεςετͷ࣮ߦํ๏Λ੍ޚͰ͖Δɻ
    ➤ γΣʔμʔ͔ΒϨϯμϦϯάλʔήοτͷਂ౓৘ใΛσϓεόο
    ϑΝʹॻ͖ࠐΉ͔Ͳ͏੍͔ޚͰ͖Δɻ

    View full-size slide

  166. ਂ౓ςετͷߏจ
    ZTest Less | Greater | LEqual | GEqual | Equal | NotEqual | Always
    ZTest
    σϓεςετͷ࣮ߦํ๏ɻσϑΥϧτ͸ LEqual ʢ͢Ͱʹඳը͞Ε͍ͯΔΦϒδΣΫτͱڑ཭͕౳͍͠
    ͔ɺΑΓ͍ۙ৔߹ʹඳըʣɻ
    Offset
    Offset Factor, Units
    σϓεΦϑηοτΛೋͭͷύϥϝʔλʔɺFactor ͓Αͼ UnitsɺͰࢦఆͰ͖ΔɻFactor ͸ɺϙϦΰϯͷ
    X ͋Δ͍͸ Y ʹؔ࿈ͯ͠ɺ࠷େͷ Z ޯ഑Λεέʔϧ͠ɺUnits ͸࠷খͷσϓεόοϑΝ஋Λεέʔϧ
    ͢Δɻྫ͑͹ɺOffset 0, –1 ʹΑΓɺϙϦΰϯͷޯ഑Λແࢹͯ͠ϙϦΰϯΛΧϝϥʹ͚ۙͮɺҰํͰ
    Offset –1, –1 ͸͞Βʹݟ্͛Δ֯౓ͰϙϦΰϯΛ͚ۙͮΔɻZϑΝΠςΟϯά(ಉ͡Ґஔʹ2ͭͷϙϦΰ
    ϯ͕ଘࡏ͢Δ࣌ʹϨϯμϦϯά͞ΕΔϐΫηϧ͕2ͭͷϙϦΰϯ͕ࠞͬͯ͟͠·͏ݱ৅)ͷղܾͰར༻͢
    Δɻ
    ZWrite On | Off
    ZWrite
    ϨϯμϦϯάλʔήοτͷਂ౓৘ใΛDepth Bufferʹॻ͖ࠐΉ͔Ͳ͏͔ɻσϑΥϧτ͸Onɻ

    View full-size slide

  167. Stencil
    ➤ εςϯγϧόοϑΝ΍εςϯ
    γϧςετʹ͍ͭͯղઆ͢Δɻ
    • ʲςϥγϡʔϧϒϩάʳεςϯγϧόοϑΝΛ࢖ͬͨ2D໘ന
    දݱΛ৭ʑͱࢼ͢
    • ʲQiitaʳUnityͷShaderͰεςϯγϧόοϑΝΛࢼ͢
    • ʲwgld.orgʳεςϯγϧόοϑΝ
    • ʲUnityϚχϡΞϧʳεςϯγϧ

    View full-size slide

  168. εςϯγϧͱ͸
    εςϯγϧͷ֓ཁʹ͍ͭͯ

    View full-size slide

  169. εςϯγϧͱ͸
    ➤ ܕࢴɺݪࢴΛҙຯ͢ΔɻγΣʔμʔʹ͓͍ͯ͸ʮܕൈ͖ʯͷҙ
    ຯɻ
    • γϧΤοτ΍Ξ΢τϥΠϯͷඳը
    • σΧʔϧ
    • ϑΣʔυΠϯ΍ϑΣʔυΞ΢τԋग़
    ͳͲ͕Ͱ͖Δɻ
    ➤ ར༻༻్͸ओʹϚεΩϯάɻ

    View full-size slide

  170. ࣮ߦॱ
    εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈ͸ϐΫηϧ৭͕ϑϥάϝϯτγΣʔμʔ
    Ͱreturn͞Εͨ৔߹ʹߦΘΕΔ(Discardͨ͠৔߹͸εςϯγϧόοϑΝ΁
    ͷॻ͖ࠐΈ͸ߦΘΕͳ͍)ɻ
    εςϯγϧςετ͸ϐΫηϧॲཧ࣌ʹߦΘΕΔɻ͜ͷςετʹࣦഊͨ͠
    ৔߹͸ϐΫηϧͷඳըॲཧ͕ഁغ͞ΕΔɻ੒ޭͨ͠৔߹͸௨ৗͲ͓Γʹ
    ඳը͞ΕΔɻ

    View full-size slide

  171. εςϯγϧόοϑΝ
    εςϯγϧͷ৘ใΛ࣋ͭεςϯγϧόοϑΝʹ͍ͭͯ

    View full-size slide

  172. εςϯγϧόοϑΝͱ͸
    ➤ εςϯγϧόοϑΝ্ͷσʔλ͸શͯ੔਺஋(খ਺஋͡Όͳ
    ͍)ɻͭ·Γ੔਺஋Λ֨ೲ͢ΔόοϑΝɻ
    ➤ ಛఆͷϑϥάϝϯτΛϨϯμϦϯά͢Δ΂͖͔൱͔Λܾఆ͢Δ
    ݖݶ(σʔλ)Λ͍࣋ͬͯΔɻ
    ➤ εςϯγϧόοϑΝʹରͯ͠ߦͳ͑Δͷ͸ɺͦͷϐΫηϧʹϞ
    σϧͳͲ͕ϨϯμϦϯά͞ΕΔ͜ͱΛڐՄ͢Δ͔Ͳ͏͔ɺͦΕ
    Λ൑அ͢ΔͨΊͷج४ͱͳΔ஋Λઃఆ͢Δ͜ͱɻ

    View full-size slide

  173. εςϯγϧόοϑΝʹॻ͖ࠐΉ
    Stencil
    {
    Ref 1 // εςϯγϧ஋(όοϑΝ΁ͷॻ͖ࠐΈɾಡΈग़͠)
    Comp Always // ࣮ߦ͞ΕΔ৚݅͸ʢৗʹʣ
    Pass Replace // ࣮ߦ͞ΕΔίϚϯυ͸ʢ্ॻ͖ʣ
    }
    εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈɻྫͷ৔߹Comp (࣮ߦ৚݅)ΛAlways
    ʹઃఆ͠ɺ৚͕݅ਅͩͬͨ৔߹(͜ͷ৔߹͸ৗʹਅ)࣮ߦ͢Δಈ࡞Ͱ͋Δ
    PassʹReplace(Refͷ஋Ͱ্ॻ͖)Λࢦఆ͍ͯ͠Δɻ
    ͭ·Γ͜ͷࢦఆํ๏ͷ৔߹ɺϑϥάϝϯτඳը࣌ʹৗʹεςϯγϧόοϑΝ
    ʹ1ͱ͍͏੔਺஋Λॻ͖ࠐΉ͜ͱʹͳΔɻ
    ߏจʹ͍ͭͯ͸ޙड़

    View full-size slide

  174. ஫ҙ
    Stencil
    {
    Ref 1 // εςϯγϧ஋(όοϑΝ΁ͷॻ͖ࠐΈɾಡΈग़͠)
    Comp Always // ࣮ߦ͞ΕΔ৚݅͸ʢৗʹʣ
    Pass Replace // ࣮ߦ͞ΕΔίϚϯυ͸ʢ্ॻ͖ʣ
    }
    ઌ΄Ͳͷ͜ͷΑ͏ͳεςϯγϧόοϑΝ΁ͷॻ͖ࠐΈΛ3DϞσϧͷඳըʹ
    ߦͬͯ΋໰୊͸ͳ͍ɻ
    ͔͠͠2DεϓϥΠτ౳ʹߦ͏ͱɺϙϦΰϯͰεςϯγϧ͕࡞੒͞Εͯ͠·͏ɻ
    ͜ΕΛճආ͢ΔͨΊʹ͸
    if (color.a < 0.001) discard;
    ͷΑ͏ʹɺεϓϥΠτͷΞϧϑΝ஋͕ҰఆҎԼͳΒഁغ͢Δͱ͍͏ॲཧ͕ඞཁɻ
    εϓϥΠτΛඳը͢Δࡍʹ
    ϙϦΰϯͰඳը͞ΕΔͨΊʹ
    εςϯγϧ΁ͷॻ͖ࠐΈ͕
    ΩϟϥΫλʔͷܗʹͳΒͳ͍
    ಁ໌౓ʹΑΔDiscardॲཧΛ
    ϑϥάϝϯτγΣʔμʔͷॲཧʹ
    ௥Ճ͢Δ͜ͱͰɺΩϟϥΫλʔͷ
    ܗʹεςϯγϧόοϑΝΛॻ͖ࠐΊΔ

    View full-size slide

  175. ஫ҙ
    ➤ ͭ·Γɺը૾ͷΞϧϑΝ஋Λར༻ͯ͠εςϯγϧόοϑΝ΁ͷ
    ॻ͖ࠐΈΛߦ͍͍ͨ৔߹͸ɺϑϥάϝϯτγΣʔμʔͰΞϧϑΝ
    ஋͕ҰఆҎԼͳΒDiscard͢Δͱ͍͏Α͏ͳॲཧΛॻ͘ඞཁ͕
    ͋Δɻ
    ➤ ϑϥάϝϯτγΣʔμʔͰDiscard͢Ε͹ͦͷϐΫηϧʹؔ͠
    ͯ͸εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈ͕࣮ߦ͞ΕΔ͜ͱ͸ͳ
    ͍ɻ
    ➤ ͜ΕΛར༻ͯ͠ɺϑϥάϝϯτγΣʔμʔ಺Ͱ͋ΒΏΔ৚݅ͷ
    ΋ͱεςϯγϧόοϑΝ΁ͷॻ͖ࠐΈΛ੍ݶ͢Δ͜ͱ͕Ͱ͖
    Δɻ

    View full-size slide

  176. εςϯγϧςετ
    εςϯγϧόοϑΝΛ༻͍ͯඳըΛ
    ੍ޚ͢Δεςϯγϧςετʹ͍ͭͯ

    View full-size slide

  177. εςϯγϧςετͱ͸
    ➤ εςϯγϧόοϑΝͷ஋ͱɺࢦఆͨ͠஋Λൺ΂ͯର৅ͷϐΫ
    ηϧʹϨϯμϦϯάΛߦͳ͏͔൱͔Λܾఆ͢Δɻ
    ➤ ൺֱʹར༻͢Δؔ਺Λൺֱؔ਺ͱ͍͏ɻ
    ➤ ൺֱ੒ޭ࣌(Pass)ɺࣦഊ࣌(Fail)ɺ੒ޭ͕ͩਂ౓ςετʹ͸ෆ
    ߹֨ͩͬͨ৔߹(ZFail)ͷॲཧΛهड़Ͱ͖Δɻ
    ➤ ͢ͰʹεςϯγϧόοϑΝʹԿ͔͠Βͷ஋͕ॻ͖ࠐ·Ε͍ͯ
    Δͱ͍͏લఏɻͳͷͰγΣʔμʔͷ࣮ߦॱʹ͸஫ҙ(εςϯγ
    ϧόοϑΝ΁ॻ͖ࠐ·ΕͨޙʹεςϯγϧςετΛߦ͏)ɻ

    View full-size slide

  178. εςϯγϧςετ
    Stencil
    {
    Ref 1 // εςϯγϧ஋(όοϑΝ΁ͷॻ͖ࠐΈɾಡΈग़͠)
    Comp Equal // ࣮ߦͷ৚݅͸ʢόοϑΝͷ஋͕Refͷ࣌ʣ
    }
    εςϯγϧςετɻྫͷ৔߹͸ɺεςϯγϧόοϑΝ
    ͷ஋ͱൺֱͯ͠ɺ஋͕̍ʹ౳͚͠Ε͹ϐΫηϧͷඳը
    ͕ߦΘΕΔɻ
    ߏจʹ͍ͭͯ͸ޙड़

    View full-size slide

  179. ஫ҙ
    όοϑΝ΁ͷॻ͖ࠐΈͱςετͰߏจ͕ಉ͡Α͏ͳײ͡ʹͳ͍ͬͯ
    ΔͨΊɺࠞཚ͢Δ͜ͱ͕͋Δɻجຊతʹεςϯγϧॲཧ͸γΣʔ
    μʔͰෳ਺ͷύεΛ༻͍ͯϚεΩϯάॲཧΛ͢Δͷʹ࢖ΘΕΔ͜ͱΛ
    ͓֮͑ͯ͘ͱ͍͍ɻ
    ྫ͑͹ɺTags {“Queue”=“Transparent+1”}ͷPassͰεςϯγϧόο
    ϑΝ΁ͷॻ͖ࠐΈΛߦ͍ɺ
    Tags {“Queue”=“Transparent+2”}ͷPassͰεςϯγϧςετΛߦ
    ͏ɻͱ͍ͬͨΑ͏ʹར༻͢Δɻ
    ·ͨɺ2ύεͰಈ࡞͢ΔγΣʔμʔΛ࡞Γɺ1Pass໨Ͱεςϯγϧ
    όοϑΝ΁ͷॻ͖ࠐΈɺ2ύε໨ͰεςϯγϧςετΛ͢Δɻͱ͍ͬ
    ͨར༻΋Մೳɻ

    View full-size slide

  180. ஫ҙ
    εςϯγϧΛෳ਺ͷ༻్Ͱѻ͏৔߹ɺϏοτϚεΫΛར༻ͯ͠
    ༻్͝ͱʹ஋Λ2ਅ਺ͷϏοτԋࢉʹΑͬͯ؅ཧ͢Δ͜ͱʹͳ
    Δɻ
    ϚεΫΛར༻ͯ͠εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈɺεςϯγ
    ϧςετΛߦ͏Α͏ʹͨ͠΄͏͕ྑ͍ɻ

    View full-size slide

  181. ߏจ
    εςϯγϧͷߏจʹ͍ͭͯ

    View full-size slide

  182. εςϯγϧߏจ
    SubShader
    {

    Stencil {
    Ref 1
    Comp always
    Pass replace
    }

    }
    SubShader
    {
    Pass{

    Stencil {
    Ref 1
    Comp always
    Pass replace
    }
    }

    }
    SubShaderҎԼʹॻ͖ࠐΉ͜ͱ͕Ͱ͖Δ
    PassҎԼʹॻ͖ࠐΉ͜ͱ͕Ͱ͖Δ
    Stencil{…} ͱ͍͏ܗࣜͰهड़͍ͯ͘͠ɻ
    ಺༰͸ޙड़


    View full-size slide

  183. ߏจ
    Ref [੔਺஋]
    Comp [ൺֱؔ਺]
    Pass [߹֨࣌ͷεςϯγϧૢ࡞]
    Fail [ෆ߹֨࣌ͷεςϯγϧૢ࡞]
    ZFail [߹͕֨ͩਂ౓ςετෆ߹֨࣌ͷεςϯγϧૢ࡞]
    ReadMask [ಡΈࠐΈϚεΫ஋]
    WriteMask [ॻ͖ࠐΈϚεΫ஋]

    View full-size slide

  184. εςϯγϧૢ࡞

    View full-size slide

  185. αϯϓϧ
    εςϯγϧΛ༻͍ͨαϯϓϧ

    View full-size slide

  186. εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈ
    Shader "Red" {
    SubShader {
    Tags { "RenderType"="Opaque" "Queue"="Geometry"}
    Pass {
    Stencil {
    Ref 2
    Comp always
    Pass replace
    ZFail decrWrap
    }
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    struct appdata {
    float4 vertex : POSITION;
    };
    struct v2f {
    float4 pos : SV_POSITION;
    };
    v2f vert(appdata v) {
    v2f o;
    o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
    return o;
    }
    half4 frag(v2f i) : COLOR {
    return half4(1,0,0,1);
    }
    ENDCG
    }
    }
    }
    εςϯγϧόοϑΝ΁ͷॻ͖ࠐΈ
    Λߦ͏γΣʔμʔϓϩάϥϜྫɻ
    ॻ͖ࠐΜͩεςϯγϧͷ಺༰Λ
    Θ͔Γ΍͘͢͢ΔͨΊʹɺ
    ϑϥάϝϯτγΣʔμʔͰ͸
    ॻ͖ࠐΜͩ಺༰Λ੺Ͱදࣔ͢Δ
    Α͏ʹͳ͍ͬͯΔɻ

    View full-size slide

  187. εςϯγϧόοϑΝͷར༻
    Shader "Custom/SpineShader"{
    SubShader
    {
    Tags {"Queue"="Transparent+2" "IgnoreProjector"="True" "RenderType"="Transparent"}
    ZWrite Off
    Blend SrcAlpha OneMinusSrcAlpha
    Stencil {
    Ref 1
    Comp Equal
    }
    Pass{…}
    }
    Shader "Custom/SpineSpriteMask"{
    SubShader
    {
    Tags {"Queue"="Transparent+1" "IgnoreProjector"="True"}
    ZWrite Off
    AlphaTest Greater 0.5
    ColorMask 0
    ZTest Always
    Stencil {
    Ref 1
    Comp always
    Pass replace
    }
    Pass{…}
    }
    όοϑΝॻ͖ࠐΈ
    εςϯγϧςετ

    View full-size slide

  188. Propertiesͷ஋ΛStencilʹར༻͢Δ
    Shader "UI/Fade"
    {
    Properties
    {
    _StencilComp ("Stencil Comparison", Float) = 8
    _Stencil ("Stencil ID", Float) = 0
    _StencilOp ("Stencil Operation", Float) = 0
    _StencilWriteMask ("Stencil Write Mask", Float) = 255
    _StencilReadMask ("Stencil Read Mask", Float) = 255
    }
    SubShader
    {
    Stencil
    {
    Ref [_Stencil]
    Comp [_StencilComp]
    Pass [_StencilOp]
    ReadMask [_StencilReadMask]
    WriteMask [_StencilWriteMask]
    }
    Pass
    {...}
    }
    }
    Propertiesͷ஋ΛShaderLab
    ಛ༗ͷ߲໨Ͱར༻͢Δʹ͸
    []ͰϓϩύςΟΛғΉɻ

    View full-size slide

  189. Blending
    ➤ ϒϨϯσΟϯάʹ͍ͭͯղઆ͢
    Δɻ
    • ʲUnityϚχϡΞϧʳBlending

    View full-size slide

  190. Blendingͱ͸
    Blendingॲཧʹ͍ͭͯ

    View full-size slide

  191. Blending
    ϑϥάϝϯτʹ͋Δݩͷ৭ͱ৽͍͠৭ͱΛͲ͏߹੒͢Δ͔ͷࢦఆΛߦ͏ɻ
    ಁաͷΧϥʔ࡞੒ʹ࢖༻͢Δɻ
    άϥϑΟοΫε͕ϨϯμϦϯά͞Εͯɺ͞Βʹ͢΂ͯͷγΣʔμʔ͕࣮ߦ
    ͞Εͯɺ͢΂ͯͷςΫενϟ͕ద༻͞ΕΔͱɺը໘ʹϐΫηϧ͕ඳը͞Ε
    Δɻ
    ͢Ͱʹଘࡏ͍ͯ͠ΔϐΫηϧʹରͯ͠ɺͲͷΑ͏ʹ߹੒͢Δ͔͸ϒϨϯσΟ
    ϯάͰ੍ޚ͞ΕΔɻ


    ͭ·ΓɺBlendingͰ͸ݱࡏܭࢉதͷιʔεΧϥʔͱݺ͹ΕΔ৭ͱɺϑϨʔ
    ϜόοϑΝʹॻ͖ࠐ·Ε͍ͯΔσΟεςΟωʔγϣϯΧϥʔͱͷ߹੒ൺ཰
    Λࢦఆ͢Δɻ

    View full-size slide

  192. ߏจ
    Blendingͷߏจʹ͍ͭͯ

    View full-size slide

  193. Blendingͷߏจ
    ➤ Blend Off
    • ϒϨϯσΟϯάΛແޮʹ͢Δɻ
    ➤ Blend SrcFactor DstFactor
    • ੜ੒͞ΕͨΧϥʔʢ͜Ε͔ΒృΔ৭ʣʹSrcFactor Λ৐ࢉ͠ը໘ʹ͢Ͱʹ͋ΔΧϥʔʢϑϨʔϜόο
    ϑΝʹ͋Δ৭ʣʹDstFactor Λ৐ࢉͯ͠ɺ2ͭΛՃࢉ͢Δɻͭ·Γɺݟ͑Δ৭ʹ͜Ε͔ΒృΔ৭
    *SrcFactorʴݱࡏͷ৭*DstFactor ͱͳΔΑ͏ʹϒϨϯυ͢Δɻ
    ➤ Blend SrcFactor DstFactor, SrcFactorA DstFactorA
    • ্هͱಉ༷͕ͩɺΞϧϑΝ஋ΛϒϨϯυ͢Δͷʹผͳεέʔϧ஋ʢSrcFactorA DstFactorAʣΛ࢖͏ɻ
    ➤ BlendOp BlendOp
    • ϒϨϯσΟϯά͞ΕͨΧϥʔΛ࢖༻͢Δ୅ΘΓʹɺBlendOpͰࢦఆ͞ΕΔผͷॲཧΛߦ͏ɻ
    ➤ BlendOp OpColor, OpAlpha
    • ্هͱಉ༷͕ͩɺΞϧϑΝνϟωϧΛϒϨϯσΟϯά͢ΔͷʹҟͳΔૢ࡞Λ࢖༻͢Δɻ
    ੨ࣈɾɾɾBlend ܎਺
    ੺ࣈɾɾɾBlend ૢ࡞
    ͱͯ͠આ໌͍ͯ͘͠ɻ

    View full-size slide

  194. αϯϓϧ
    Blendingͷαϯϓϧ

    View full-size slide

  195. ҰൠతͳϒϨϯσΟϯάͷλΠϓ
    Blend SrcAlpha OneMinusSrcAlpha // Alpha blending
    Blend One One // Additive
    Blend OneMinusDstColor One // Soft Additive
    Blend DstColor Zero // Multiplicative
    Blend DstColor SrcColor // 2x Multiplicative

    View full-size slide

  196. ShaderLabৄࡉτϐοΫ
    ➤ ShaderLabͷৄࡉͳτϐοΫʹ
    ͍ͭͯղઆ͢Δɻ
    • ʲUnityϚχϡΞϧʳৄࡉͳ ShaderLab τϐοΫ
    • ʲϝϞϒϩάʳUnity 5ͰG-Bufferͷςετ
    • ʲଠ࿠WorkʳSetReplacementShaderͷ࢖͍ํ Unity
    • ʲQiitaʳσϓεόοϑΝΛར༻͢Δ
    • ʲCross RoadʳUnity࢖༻தʹֶΜͩύϑΥʔϚϯενϡʔ
    χϯάํ๏:LOD
    • ʲͱ·ͱɾιϑτ΢ΣΞ੡࡞ॴʳDirect3D9΍ϨϯμϦϯά
    ύΠϓϥΠϯؔ࿈༻ޠʢ3DCGશൠͷجૅ஌ࣝΊ΋ʣ
    • ʲচҪݚڀࣨʳϨϯμϦϯάύΠϓϥΠϯ

    View full-size slide

  197. ϨϯμϦϯάύΠϓϥΠϯ
    Unity ͷϨϯμϦϯάύΠϓϥΠϯʹ͍ͭͯ
    Surface ShaderͰந৅Խ͞Ε͍ͯΔ಺༰ͷৄࡉ

    View full-size slide

  198. ϨϯμϦϯάύε
    ➤ ϥΠςΟϯά͕ͲͷΑ͏ʹద༻͞ΕΔ͔ɺ͓
    ΑͼγΣʔμʔͷͲͷ Pass ͕࢖༻͞ΕΔ͔
    ͸ɺͲͷϨϯμϦϯάύε͕࢖༻͞ΕΔ͔Ͱ
    ܾ·ΔɻγΣʔμʔ಺ͷ֤ύε͸ɺPass಺ͷ
    Tags Λհͯ͠ɺͦͷϥΠςΟϯάλΠϓͱ௨
    ৴͢Δɻ
    ➤ Ͳͷ৔߹Ͱ΋ɺӨΛϨϯμϦϯά͢ΔͨΊʹ
    ͸ ShadowCaster ύε͕࢖ΘΕΔɻ

    View full-size slide

  199. ϨϯμϦϯάύε
    ➤ ͭ·ΓɺPass಺ͷTagsʹΑͬͯɺ࣮ߦ͞ΕΔϨϯμϦϯάύε
    ΛࢦఆͰ͖Δɻ
    ➤ SurfaceγΣʔμʔͳΒ͹ࣗಈͰܾ·ΔΒ͍͠ͷͰߟྀ͠ͳ͘
    ͍͍ͯɻ
    ➤ γΣʔμ಺͔ΒࢀরͰ͖ΔϥΠτྨͷσʔλ͕ϨϯμϦϯάύ
    εʹΑͬͯҟͳΔɻ
    ➤ ͪͳΈʹίϚϯυόοϑΝΛ࢖͏ͱɺUnityͷϨϯμϦϯάύ
    ΠϓϥΠϯΛಠࣗʹ֦ு͢Δ͜ͱ͕Ͱ͖Δɻ

    View full-size slide

  200. Pass಺ͷTags
    Pass ͸TagsΛ࢖༻͍ͯͭ͠ͲͷΑ͏ʹͯ͠ϨϯμϦϯάΤϯδϯʹΑΓϨ
    ϯμϦϯά͢΂͖͔ΛࢦఆͰ͖Δɻ
    Tagsͷߏจ
    Tags { "TagName1" = "Value1" "TagName2" = "Value2" }
    λάͷ TagName1 ͕஋ͱͯ͠ Value1ɺλάͷ TagName2 ͕஋ͱͯ͠ Value2 Ͱ͋Δ͜ͱΛࢦఆ͍ͯ͠
    Δɻλά͸޷͖ͳ͚ͩࢦఆͰ͖Δɻλά͸جຊతʹ Key-Value ϖΞɻPass ͷதͰλά͸ɺ౰֘ύε͕ϥ
    ΠςΟϯάύΠϓϥΠϯʢ؀ڥޫɺ௖఺ϥΠςΟϯάɺϐΫηϧϥΠςΟϯάʣͷதͰͲͷ໾ׂͰ͋Δ͔
    Λ੍ޚͨ͠ΓɺଞͷύϥϝʔλʔΛ൑ఆ͢Δͷʹ࢖༻͢Δɻ
    Tags͸SubShaderɺPass಺ͷͲͪΒʹͰ΋ఆٛ͢Δ͜ͱ͕Ͱ͖Δ͕ɺ࣍
    ͷλά͸ Unity ʹΑΓೝࣝ͞ΕɺSubShader಺ͷTagsͰͳ͘ඞͣPassη
    Ϋγϣϯͷதʹఆٛ͢Δɻ

    • LightMode λά
    • RequireOptions λά

    View full-size slide

  201. Pass಺ͷTags
    LightModeλά
    LightMode λά͸ϥΠςΟϯάύΠϓϥΠϯͰͷύεͷ໾ׂΛఆٛ͢Δɻ͜ΕΒͷλά͸खಈͰ࢖༻͞ΕΔ͜ͱ
    ͸كͰɺϥΠςΟϯάͱ૬ޓ࡞༻ͷ͋Δ΄ͱΜͲͷγΣʔμʔ͸ Surface Shader Ͱهड़͞Εɺͦ͏͍ͬͨৄࡉ͸
    ͦͷதͰॲཧ͞ΕΔɻ
    LightMode Ͱར༻Մೳͳ஋
    Always
    ৗʹϨϯμϦϯά͞ΕɺϥΠςΟϯά͸ద༻͞Εͳ͍ɻ
    ForwardBase
    Forward Rendering Ͱ࢖༻͞Εɺ؀ڥޫɺϝΠϯͷσΟϨΫγϣφϧϥΠτɺ௖఺/SH ϥ
    Πτ͕ద༻͞ΕΔɻ
    ForwardAdd
    Forward Rendering Ͱ࢖༻͞ΕɺϥΠτ͝ͱʹҰͭͷύεͰɺAdditive ϐΫηϧϥΠςΟ
    ϯά͕ద༻͞ΕΔɻ
    Deferred
    Deferred Shading Ͱ࢖༻͞Εɺg-όοϑΝΛඳը͠·͢ɻ
    ShadowCaster
    ΦϒδΣΫτͷσϓεΛγϟυ΢Ϛοϓ΍ਂ౓ςΫενϟʹඳը͠·͢ɻ

    View full-size slide

  202. Pass಺ͷTags
    RequireOptions λά
    ಛఆͷ֎෦৚͕݅ຬͨ͞Εͨ৔߹ͷΈϨϯμϦϯά͞ΕΔ͜ͱΛɺύεͰࢦఆ͢Δ͜ͱ͕Ͱ͖Δɻ͜Ε͸
    RequireOptions ʹΑΓ࣮ݱ͞Εɺ஋͸εϖʔεͰ۠੾ΒΕͨจࣈྻʹΑΔΦϓγϣϯɻ
    RequireOptions Ͱར༻Մೳͳ஋
    SoftVegetation
    ΋͠ ը࣭ઃఆ Ͱ Soft Vegetation ͕༗ޮͰ͋Δ৔߹ͷΈɺ͜ͷύεΛϨϯμϦϯά͢Δɻ

    View full-size slide

  203. Forward Renderingύε
    Forward Rendering ύε͸֤ΦϒδΣΫτΛɺΦϒδΣΫτʹ࡞༻͢ΔϥΠτʹ΋ͱ͍ͮͯϨϯμϦϯά͢Δɻϥ
    Πτͦͷ΋ͷ͸ɺઃఆ͓Αͼڧ౓ʹΑͬͯɺForward Rendering ʹΑΓผʑʹѻΘΕΔɻ
    Forward RenderingͰѻ͏ύεʹ͸

    ➤ ʲForwardBaseʳ LightModeͰࢦఆͰ͖ΔBase Pass
    • ΦϒδΣΫτͷϐΫηϧΛͻͱͭͷࢦ޲ੑϥΠτͱ࢒Γ͢΂ͯͷٿ໘ௐ
    ࿨Ͱܭࢉ͞ΕͨϥΠτͰϨϯμϦϯά͢Δɻ͜ͷύεͰ͸͞Βʹଞͷϥ
    ΠτϚοϓɺ؀ڥޫϥΠςΟϯάɺ͓ΑͼࣗݾൃޫϥΠςΟϯάΛ௥Ճ
    ͢Δɻ
    ➤ ʲForwardAddʳLightModeͰࢦఆͰ͖ΔAdditional Passes
    • ΦϒδΣΫτʹ࡞༻͢Δɺ֤ʑͷ௥Ճ͞ΕͨϐΫηϧϥΠτͰϨϯμϦ
    ϯά͞ΕΔɻ͜ΕΒͷύεͷϥΠτ͸ӨΛ࣋ͯͳ͍ʢ݁Ռͱͯ͠
    Forward Rendering ͕αϙʔτ͢Δͷ͸ͻͱͭͷࢦ޲ੑϥΠτͱӨʣɻ

    ͕͋Δɻ

    View full-size slide

  204. Deferred Renderingύε
    Deferred Shading (஗ԆγΣʔσΟϯά)Λ࢖༻͢Δ৔߹ɺΦϒδΣΫτʹӨڹΛ༩͑Δ͜ͱ͕Ͱ͖Δޫͷ਺
    ʹ੍ݶ͸ͳ͍ɻ͢΂ͯͷޫ͸ɺͦΕΒ͕͢΂ͯ౳๏Ϛοϓ౳ͱਖ਼͘͠૬ޓ࡞༻͢Δ͜ͱΛҙຯ͠ɺϐΫηϧ
    ͝ͱʹධՁ͞ΕΔɻ͞Βʹɺ͢΂ͯͷޫ͸ɺΫοΩʔͱγϟυ΢Λ࣋ͭ͜ͱ͕Ͱ͖Δɻ

    Deferred Shading ͸ɺΞϯνΤΠϦΞγϯάͷͨΊͷ࣮ࡍͷαϙʔτ͕ͳ͘ɺ൒ಁ໌ͷΦϒδΣΫτΛॲཧ
    ͢Δ͜ͱ͸Ͱ͖ͳ͍ʢ͜ΕΒ͸ɺForward ϨϯμϦϯάΛ࢖༻ͯ͠ϨϯμϦϯά͞ΕΔʣɻ


    Deferred Shading Λ࢖༻͢Δ৔߹ɺUnity ͰͷϨϯμϦϯάϓϩηε͸2ͭͷύεͰߦΘΕΔɻ
    ➤ G-buffer Pass

    ΦϒδΣΫτ͸ɺdiffuse colorɺspecular colorɺsmoothnessɺ world space normalɺemission ͓Αͼ
    depth ͱεΫϦʔϯεϖʔεόοϑΝΛੜ੒͢ΔͨΊʹϨϯμϦϯά͞ΕΔ(G-bufferΛੜ੒͢ΔͨΊͷ
    ϨϯμϦϯά޻ఔ)ɻ
    ➤ Lighting pass

    G-buffer ΍σϓεʹج͍ͮͯর໌Λܭࢉ͢Δɻ

    ͜ͷϓϩηε͕׬ྃͨ͠ޙɺdeferred shading Λѻ͏͜ͱ͕Ͱ͖ͳ͍γΣʔμʔΛ࣋ͭΦϒδΣΫτ͸ɺ
    Forward Rendering ύεΛ࢖༻ͯ͠ϨϯμϦϯά͞ΕΔ͜ͱʹͳΔɻ

    View full-size slide

  205. άϥϑΟοΫػೳͷϋʔυ΢ΣΞཁ݅

    View full-size slide

  206. ύϑΥʔϚϯεͷώϯτ
    γΣʔμʔΛॻ͘৔߹ͷύϑΥʔϚϯεͷώϯτ

    View full-size slide

  207. ܭࢉͷਫ਼౓
    ➤ ϫʔϧυۭؒҐஔͱςΫενϟ࠲ඪͷ৔߹͸ɺfloatΛ࢖༻͢Δɻ
    ➤ ଞͷ͢΂ͯʢϕΫτϧɺHDRͷ৭ͳͲʣͷ৔߹͸ɺhalfΛ࢖༻͢ΔɻΑΓଟ͘ͷਫ਼౓͕ඞ
    ཁͳ৔߹ʹͷΈfloatʹ͢Δɻ
    ➤ ςΫενϟσʔλ্ͷඇৗʹ؆୯ͳૢ࡞Ͱ͸ɺfixedΛ࢖༻͢Δɻ
    ➤ ͋ΒΏΔݱ୅ͷσεΫτοϓ GPU ͸ɺৗʹ͢΂ͯͷࣄΛ׬શͳුಈখ਺఺਺ਫ਼౓Ͱܭࢉ͠
    ͍ͯͯɺfloat/half/fixed Ͱ͸ɺ·ͬͨ͘ಉ݁͡ՌͰऴΘΔɻ͜ͷࣄ͕ςετΛࠔ೉ʹͯ͠
    ͓Γɺhalf/fixed ͷਫ਼౓Ͱ࣮ࡍ͸े෼ͳͷ͔Ͳ͏͔ɺPC্Ͱ͸൑Γʹ͍͘ɻ࡞੒ͨ͠
    γΣʔμʔΛɺ࣮ࡍʹϞόΠϧσόΠεͰࢼ͢ඞཁ͕༗Δɻ
    ➤ ϞόΠϧ GPU ͸൒ਫ਼౓ුಈখ਺఺਺Λαϙʔτ͓ͯ͠Γɺେ఍͸ܭࢉ͕ΑΓૣ͘ɺΑΓল
    ΤωͰ͋Δɻ
    ➤ fixedͷਫ਼౓͸ɺҰൠతʹݹ͍ϞόΠϧ GPU ͰͷΈ࢖͑Δɻݱ୅ͷଟ͘ͷ GPU(OpenGL
    ES 3 ΍ Metal Λ࣮ߦ͢Δ͜ͱ͕Ͱ͖Δ΋ͷ)͸ɺݻఆখ਺఺਺ͱ൒ਫ਼౓ුಈখ਺఺਺Λɺ಺
    ෦తʹ͸·ͬͨ͘ಉ͡΋ͷͱͯ͠औΓѻ͏ɻΑͬͯ࢖͏ػձ͸গͳ͍ɻ

    View full-size slide

  208. Replaced Shaders ͰͷϨϯμϦϯά
    γΣʔμʔΛஔ׵͢Δ

    View full-size slide

  209. Replaced Shaderͱ͸
    ➤ ΧϝϥʹөΔશମΛ୯ҰγΣʔμͰඳըͰ͖Δ
    ➤ ΧϝϥʹөΔશମͷ಺ɺಛఆͷγΣʔμͷ৔߹ͷΈඳըͨ͠
    ͍৔߹͸λάΛࢦఆ͢Δ͜ͱͰՄೳʹͳΔɻ
    ➤ γΣʔμʔͷஔ͖׵͑ΛεΫϦϓτͰߦ͏ʹ͸ɺ
    Camera.RenderWithShader ΍ Camera.SetReplacementShader
    ؔ਺Λ࢖༻͢Δɻ
    ➤ ྆ํͷؔ਺͸Ҿ਺ͰreplacedShader ͱreplacementTag Λ࢖༻
    ͢Δɻ

    View full-size slide

  210. Replaced Shaderͷಈ࡞
    Χϝϥ͸γʔϯΛ௨ৗͲ͓ΓʹϨϯμϦϯά͢ΔɻΦϒδΣΫτ͸ϚςϦΞϧΛ࢖༻͢Δ
    ͕ɺ࣮ࡍʹ࢖༻͞ΕΔ͜ͱʹͳΔγΣʔμʔ͕มߋ͞ΕΔɻ
    ➤ replacementTag ͕ۭͷ৔߹ɺγʔϯͷ͢΂ͯͷΦϒδΣΫτ͸ࢦఆ͞Εͨ replaced
    Shader ͰϨϯμϦϯά͞ΕΔɻ
    ➤ replacementTag ͕ۭͰͳ͍৔߹ɺϨϯμϦϯά͞ΕΔ֤ΦϒδΣΫτ͸
    • ΦϒδΣΫτͷγΣʔμʔ͸SubShader಺ͷλάʹreplacementTagΛ΋ͭSubShader
    Λݕࡧ͢Δɻ
    • replacementTagΛ࣋ͨͳ͍৔߹ɺΦϒδΣΫτ͸ ϨϯμϦϯά͞Εͳ͍ɻ
    • replacementTagΛݟ͚ͭͨ৔߹ɺͦͷSubShaderΛ࢖༻ͯ͠ΦϒδΣΫτ͕ϨϯμϦ
    ϯά͞ΕΔɻ
    ΋͢͠΂ͯͷγΣʔμʔ͕ɺྫ͑͹ɺ“RenderType” λά͕ “Opaque”ɺ“Transparent”ɺ
    “Background”ɺ“Overlay” ͷ஋Ͱ͋ͬͨ৔߹ɺෆಁ໌ͳΦϒδΣΫτͷΈϨϯμϦϯά͢
    Δ Replacement Shader ΛɺRenderType=“Solid”Ͱ͋ΔͻͱͭͷαϒγΣʔμʔΛ࢖༻͠
    ͯɺهड़͢Δ͜ͱ͕Ͱ͖Δɻͳ͓ɺ͢΂ͯͷ Unity ϏϧτΠϯγΣʔμʔ͸ “RenderType”
    λάͷηοτΛ͍࣋ͬͯΔɻ

    View full-size slide

  211. ϏϧτΠϯγΣʔμʔͰͷReplacement Shaderλά
    ͢΂ͯͷ Unity ϏϧτΠϯγΣʔμʔ͸“RenderType” λάͷηοτΛ࣋ͪɺReplaced Shader Ͱ࢖༻͢Δ͜ͱ͕
    Ͱ͖Δɻ
    ➤ Opaque


    ΄ͱΜͲͷγΣʔμʔ(NormalɺSelf IlluminatedɺReflectiveɺTerrain γΣʔμʔ)ɻ
    ➤ Transparent


    ΄ͱΜͲͷ෦෼తʹಁաͳγΣʔμʔ(TransparentɺύʔςΟΫϧɺϑΥϯτɺTerrain ௥Ճύε
    γΣʔμʔ)ɻ
    ➤ TransparentCutout


    ϚεΩϯά͞ΕͨಁաγΣʔμʔ(Transparent Cutoutɺ2 ύε২ੜγΣʔμʔ)ɻ
    ➤ Background


    Skybox γΣʔμʔɻ
    ➤ Overlay


    GUITextureɺϋϩʔɺϑϨΞγΣʔμʔɻ
    ➤ TreeOpaque


    Terrain Τϯδϯ Tree ͷथൽɻ
    ➤ TreeTransparentCutout


    Terrain Τϯδϯ Tree Leavesɻ
    ➤ TreeBillboard


    Terrain ΤϯδϯϏϧϘʔυͷ Treeɻ
    ➤ Grass


    Terrain Τϯδϯͷ Grassɻ
    ➤ GrassBillboard


    Terrain ΤϯδϯϏϧϘʔυͷ Grassɻ

    View full-size slide

  212. ࢖༻ྫ
    camera.SetReplacementShader (shadow, "Shadow");
    Tags {
    "RenderType"="Opaque"
    "Queue"="Geometry"
    "Shadow"="Character"
    }
    Tags {
    "RenderType"="Opaque"
    "Queue"="Geometry"
    "Shadow"="Character"
    }
    shadowcamera.cs
    shadow.shader
    character.shader
    Replace͠ͳ͍৔߹ɺΧϝϥ͸charactor.shaderΛ࢖ͬͯΩϟϥΫλʔΛϨϯμϦϯά͢Δɻ
    shadowcamera.csͰ͜ͷΑ͏ʹ͢ΔͱUnityଆ͕ShadowλάΛ֬ೝ͜͜͠Ͱ͸Character͕ڞ௨ͳͨΊɺ
    ΩϟϥΫλʔ͕shadow.shaderΛ࢖ͬͯඳը͞ΕΔ(charactor.shader͕shadow.shaderʹஔ͖׵ΘΔ)ɻ

    ଞͷShadowλά͕ଘࡏ͠ͳ͍γΣʔμ͸ඳը͕ແࢹ͞Ε·͢ɻ

    View full-size slide

  213. CustomEditor
    Materialʹදࣔ͞ΕΔΠϯεϖΫλʔΛ֦ு͢Δ

    View full-size slide

  214. ϚςϦΞϧΠϯεϖΫλʔͷΧελϚΠζ
    ΧελϜΤσΟλʔΛఆٛ͢Δʹ͸ɺ ShaderGUI ͷΫϥεΛܧঝ͠ɺΞηοτͷ֊૚಺ʹ͋Δ Editor
    ϑΥϧμʔͷԼʹɺεΫϦϓτΛஔ͘ɻ
    Shader "Custom/Redify" {
    Properties {
    _MainTex ("Base (RGB)", 2D) = "white" {}
    }
    SubShader {
    Tags { "RenderType"="Opaque" }
    LOD 200
    CGPROGRAM
    #pragma surface surf Lambert addshadow
    #pragma shader_feature REDIFY_ON
    sampler2D _MainTex;
    struct Input {
    float2 uv_MainTex;
    };
    void surf (Input IN, inout SurfaceOutput o) {
    half4 c = tex2D (_MainTex, IN.uv_MainTex);
    o.Albedo = c.rgb;
    o.Alpha = c.a;
    #if REDIFY_ON
    o.Albedo.gb *= 0.5;
    #endif
    }
    ENDCG
    }
    CustomEditor "CustomShaderGUI"
    }
    using UnityEngine;
    using UnityEditor;
    using System;
    public class CustomShaderGUI : ShaderGUI
    {
    public override void OnGUI(MaterialEditor materialEditor,
    MaterialProperty[] properties)
    {
    base.OnGUI(materialEditor, properties);
    Material targetMat = materialEditor.target as Material;
    // see if redify is set, and show a checkbox
    bool redify = Array
    .IndexOf(targetMat.shaderKeywords,
    "REDIFY_ON") != -1;
    EditorGUI.BeginChangeCheck();
    redify = EditorGUILayout.Toggle("Redify material", redify);
    if (EditorGUI.EndChangeCheck())
    {
    // enable or disable the keyword based on checkbox
    if (redify)
    targetMat.EnableKeyword("REDIFY_ON");
    else
    targetMat.DisableKeyword("REDIFY_ON");
    }
    }
    }
    γΣʔμʔͷઃఆʹ REDIFY_ON ͱ͍͏Ωʔϫʔυ͕͋Δɻ͜Ε͸ɺϚςϦΞϧͷΠϯεϖΫλʔΛ
    ֦ு͢Δ͜ͱͰϚςϦΞϧ͝ͱʹΩʔϫʔυͷ༗ޮ/ແޮΛ੾Γସ͑Δ͜ͱ͕Ͱ͖Δɻ
    ͨͩ͠ɺ্هͷ؆୯ͳྫ͸MaterialPropertyDrawersΛ࢖ͬͯɺ͞Βʹ୯७ԽͰ͖Δɻ

    View full-size slide

  215. Depth Texture ͷ࢖༻
    Depth Textureͷ࢖༻ํ๏ʹ͍ͭͯ

    View full-size slide

  216. Depth Textureͱ͸
    ➤ ਂ౓৘ใΛςΫενϟʹඳըͨ͠΋ͷɻ
    ➤ ਂ౓όοϑΝΛՄࢹԽͰ͖Δɻ

    View full-size slide

  217. Depth Texture࢖༻ྫ
    public class RenderDepthBuffer : MonoBehaviour
    {
    private RenderTexture m_colorTex;
    private RenderTexture m_depthTex;
    public Material m_postRenderMat;
    void Start ()
    {
    Camera cam = GetComponent();
    cam.depthTextureMode = DepthTextureMode.Depth;
    // ΧϥʔόοϑΝ༻ RenderTexture
    m_colorTex = new RenderTexture(Screen.width, Screen.height, 0, RenderTextureFormat.ARGB32);
    m_colorTex.Create();
    // σϓεόοϑΝ༻ RenderTexture
    m_depthTex = new RenderTexture(Screen.width, Screen.height, 24, RenderTextureFormat.Depth);
    m_depthTex.Create();
    // cameraʹΧϥʔόοϑΝͱσϓεόοϑΝΛηοτ͢Δ
    cam.SetTargetBuffers(m_colorTex.colorBuffer, m_depthTex.depthBuffer);
    }
    void OnPostRender()
    {
    // RenderTargetແ͠ɿը໘ʹग़ྗ͞ΕΔ
    Graphics.SetRenderTarget(null);
    // σϓεόοϑΝΛඳը͢Δ(m_postRenderMat͸ςΫενϟը૾Λͦͷ··ඳը͢ΔϚςϦΞϧ)
    Graphics.Blit(m_depthTex, m_postRenderMat);
    }
    }

    View full-size slide

  218. Depth Texture࢖༻ྫ

    View full-size slide

  219. σϓεςΫενϟϔϧϓϚΫϩ
    ➤ UNITY_TRANSFER_DEPTH(o)


    ௖఺ͷ Eye Space Depth ʢࢹ఺ۭؒσϓεʣΛܭࢉ͠ɺo ʢ float2 Ͱ͋Δ͜ͱ͕ඞਢʣʹग़ྗ͢Δɻσϓε
    ςΫενϟʹରͯ͠ϨϯμϦϯά͢Δͱ͖ʹ௖఺ϓϩάϥϜͰ࢖༻͢ΔɻωΠςΟϒσϓεςΫενϟͷ
    ͋ΔϓϥοτϑΥʔϜͰ͸ɺZ όοϑΝͷ஋͸҉໧తʹϨϯμϦϯά͞ΕΔͨΊɺ͜ͷϚΫϩ͸Կ΋͠ͳ
    ͍ɻ
    ➤ UNITY_OUTPUT_DEPTH(i)


    ௖఺ͷ Eye Space Depth Λi (float2 Ͱ͋Δ͜ͱ͕ඞਢ)͔Βฦ͢ɻσϓεςΫενϟʹରͯ͠ϨϯμϦϯά͢
    Δͱ͖ʹɺϑϥάϝϯτϓϩάϥϜͰ࢖༻͢ΔɻωΠςΟϒσϓεςΫενϟͷ͋ΔϓϥοτϑΥʔϜͰ
    ͸͜ͷϚΫϩ͸ɺZ όοϑΝ஋͕҉໧తʹϨϯμϦϯά͞ΕΔͨΊɺৗʹ 0 Λฦ͢ɻ
    ➤ COMPUTE_EYEDEPTH(o)


    ௖఺ͷ Eye Space Depth Λܭࢉ͠ɺoʹग़ྗ͢Δɻ௖఺ϓϩάϥϜͰɺσϓεςΫενϟʹ ϨϯμϦϯά͠
    ͳ͍ͱ͖ʹɺ࢖༻͢Δɻ
    ➤ DECODE_EYEDEPTH(i)


    σϓεςΫενϟi ͔Βߴਫ਼౓ͷ஋Λड͚औΓɺ֘౰͢Δ Eye Space Depth Λฦ͢ɻ͜ͷϚΫϩ͸ Direct3D
    Ͱ͸୯ʹi*FarPlane Λฦ͢ɻωΠςΟϒσϓεςΫενϟͷ͋ΔϓϥοτϑΥʔϜͰ͸͜ͷϚΫϩ͸ɺΧ
    ϝϥͷൣғʹҰக͢ΔΑ͏ʹɺ஋ΛઢܗԽ֦͠ு͢Δɻ


    View full-size slide

  220. DepthΛϨϯμϦϯά͢ΔγΣʔμʔ
    Shader "Render Depth" {
    SubShader {
    Tags { "RenderType"="Opaque" }
    Pass {
    CGPROGRAM
    #pragma vertex vert
    #pragma fragment frag
    #include "UnityCG.cginc"
    struct v2f {
    float4 pos : SV_POSITION;
    float2 depth : TEXCOORD0;
    };
    v2f vert (appdata_base v) {
    v2f o;
    o.pos = mul (UNITY_MATRIX_MVP, v.vertex);
    UNITY_TRANSFER_DEPTH(o.depth);
    return o;
    }
    half4 frag(v2f i) : SV_Target {
    UNITY_OUTPUT_DEPTH(i.depth);
    }
    ENDCG
    }
    }
    }

    View full-size slide

  221. LOD
    γΣʔμʔ಺ͰࢦఆՄೳͳLODʹ͍ͭͯ

    View full-size slide

  222. LODͱ͸
    ➤ Level of Detail
    ➤ ΧϝϥͱΦϒδΣΫτͷڑ཭͕཭Εͨ৔߹ʹϨϯμϦϯά͢Δ
    ϙϦΰϯͷ਺ΛݮΒ͢ࣄ͕Ͱ͖Δɻ
    ➤ Unity Ͱ͸ɺLOD Group ίϯϙʔωϯτΛ࢖͏ͱΦϒδΣΫ
    τʹରͯ͠ LOD ϨϯμϦϯάΛηοτΞοϓͰ͖Δɻ

    View full-size slide

  223. Shader LOD
    γΣʔμʔ Level of Detail (LOD) ͸ɺLOD ஋͕ܾΊΒΕ͖͍ͨ͠஋ҎԼͷ৔߹ʹɺγΣʔμʔ͋Δ͍͸
    αϒγΣʔμʔΛ࢖༻ͯ͠ඳը͢Δɻ
    σϑΥϧτͰ͸ɺڐ༰͞ΕΔ LOD Ϩϕϧ͸ແݶͰ͋Γɺ͢ͳΘͪϢʔβʔͷϋʔυ΢ΣΞͰαϙʔτ͞
    ΕΔ͢΂ͯͷγΣʔμʔΛ࢖༻͢Δ͜ͱ͕Ͱ͖Δɻ͔͠͠ɺ͍͔ͭ͘ͷέʔεͰ͸ɺͨͱ͑ϋʔυ΢ΣΞ
    ͕αϙʔτ͢Δ৔߹Ͱ͋ͬͯ΋ɺγΣʔμʔͷσΟςʔϧΛམͱ͍ͨ͠৔߹͕͋Δɻͦ͏͍ͬͨ৔߹ʹ
    LODΛར༻͢Δɻ

    Shader LOD ͸εΫϦϓτʹΑͬͯݸผͷγΣʔμʔ͝ͱʹઃఆʢ Shader.maximumLOD ʣ͢Δ͜ͱ΋ɺ
    ͢΂ͯͷγΣʔμʔͰάϩʔόϧʹ࢖༻͢Δʢ Shader.globalMaximumLOD ʣ͜ͱ΋Մೳɻ


    Ϣʔβʔ࡞੒ͷΧελϜͷγΣʔμʔͰ͸ɺLOD ίϚϯυΛ࢖༻ͯ͠ͲͷΑ͏ͳαϒγΣʔμʔͰ΋
    LOV ஋Λઃఆ͢Δ͜ͱ͕Ͱ͖Δɻ


    Unity ͷϏϧτΠϯγΣʔμʔ͸ LOD Λ࣍ͷΑ͏ʹઃఆ͞Ε͍ͯΔɻ
    ➤ VertexLit ͷΑ͏ͳγΣʔμʔ = 100
    ➤ DecalɺReflective VertexLit = 150
    ➤ Diffuse = 200

    ➤ Diffuse DetailɺReflective Bumped UnlitɺReflective Bumped VertexLit = 250
    ➤ BumpedɺSpecular = 300
    ➤ Bumped Specular = 400

    ➤ Parallax = 500

    ➤ Parallax Specular = 600

    View full-size slide

  224. Shader LODͷࢦఆ
    Shader LODͷࢦఆ͸SubShaderλά಺ͰҎԼͷΑ͏ʹߦ͑͹ྑ͍ɻ
    LOD 200
    200ͱදهͨ͠෦෼͸ࣗ༝ʹ੔਺஋ΛઃఆͰ͖Δɻ

    View full-size slide