Advertisement
whiteflare

WF_UnToonURP_Meta.cginc

May 20th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. /*
  2. * The MIT License
  3. *
  4. * Copyright 2018-2022 whiteflare.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9. *
  10. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  14. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  15. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17.  
  18. #ifndef INC_UNLIT_WF_UNTOON_META
  19. #define INC_UNLIT_WF_UNTOON_META
  20.  
  21. ////////////////////////////
  22. // uniform variable
  23. ////////////////////////////
  24.  
  25. #include "../WF_INPUT_UnToon.cginc"
  26.  
  27. ////////////////////////////
  28. // main structure
  29. ////////////////////////////
  30.  
  31. struct appdata {
  32. float4 vertex : POSITION;
  33. float2 uv0 : TEXCOORD0;
  34. float2 uv1 : TEXCOORD1;
  35. float2 uv2 : TEXCOORD2;
  36. #ifdef _V2F_HAS_VERTEXCOLOR
  37. float4 vertex_color : COLOR0;
  38. #endif
  39. };
  40.  
  41. struct v2f_meta {
  42. float4 pos : SV_POSITION;
  43. float2 uv : TEXCOORD0;
  44. #ifdef _V2F_HAS_VERTEXCOLOR
  45. float4 vertex_color : COLOR0;
  46. #endif
  47. };
  48.  
  49. ////////////////////////////
  50. // Unity Meta function
  51. ////////////////////////////
  52.  
  53. #if UNITY_VERSION < 201904
  54. #include "Packages/com.unity.render-pipelines.lightweight/ShaderLibrary/MetaInput.hlsl"
  55. #else
  56. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/MetaInput.hlsl"
  57. #endif
  58.  
  59. ////////////////////////////
  60. // vertex&fragment shader
  61. ////////////////////////////
  62.  
  63. v2f_meta vert_meta(appdata i) {
  64. v2f_meta o;
  65. UNITY_INITIALIZE_OUTPUT(v2f_meta, o);
  66.  
  67. #ifdef UNIVERSAL_META_INPUT_INCLUDED
  68. o.pos = MetaVertexPosition(i.vertex, i.uv1, i.uv2, unity_LightmapST, unity_DynamicLightmapST);
  69. #else
  70. o.pos = MetaVertexPosition(i.vertex, i.uv1, i.uv2, unity_LightmapST);
  71. #endif
  72.  
  73. o.uv = TRANSFORM_TEX(i.uv0, _MainTex);
  74. #ifdef _V2F_HAS_VERTEXCOLOR
  75. o.vertex_color = i.vertex_color;
  76. #endif
  77.  
  78. return o;
  79. }
  80.  
  81. float4 frag_meta(v2f_meta i) : SV_Target {
  82. MetaInput o;
  83. UNITY_INITIALIZE_OUTPUT(MetaInput, o);
  84.  
  85. float2 uv_main = TRANSFORM_TEX(i.uv, _MainTex);
  86.  
  87. float4 color = _Color * PICK_MAIN_TEX2D(_MainTex, uv_main);
  88. #ifdef _VC_ENABLE
  89. color *= lerp(ONE_VEC4, i.vertex_color, _UseVertexColor);
  90. #endif
  91.  
  92. // 単色化
  93. color.rgb = max(ZERO_VEC3, lerp(AVE_RGB(color.rgb).xxx, color.rgb, lerp(1, _GI_IndirectChroma, _GI_Enable)));
  94.  
  95. o.Albedo = color.rgb * lerp(1, _GI_IndirectMultiplier, _GI_Enable);
  96. o.Emission = ZERO_VEC3; // 初期化
  97.  
  98. #ifdef _ES_ENABLE
  99.  
  100. FEATURE_TGL_ON_BEGIN(_ES_Enable)
  101. float4 es_mask = PICK_SUB_TEX2D(_EmissionMap, _MainTex, uv_main).rgba;
  102. float4 es_color = _EmissionColor * es_mask;
  103. o.Emission = es_color.rgb * es_color.a * lerp(1, _GI_EmissionMultiplier, _GI_Enable);
  104. FEATURE_TGL_END
  105.  
  106. #endif
  107.  
  108. return MetaFragment(o);
  109. }
  110.  
  111. float4 frag_meta_black(v2f_meta i) : SV_Target {
  112. MetaInput o;
  113. UNITY_INITIALIZE_OUTPUT(MetaInput, o);
  114.  
  115. o.Albedo = ZERO_VEC3;
  116. o.Emission = ZERO_VEC3;
  117.  
  118. return MetaFragment(o);
  119. }
  120.  
  121. #endif
  122.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement