Advertisement
whiteflare

WF_UnToonURP_Meta.cginc

May 20th, 2022
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.97 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. o.pos = MetaVertexPosition(i.vertex, i.uv1, i.uv2, unity_LightmapST, unity_DynamicLightmapST);
  68.  
  69. o.uv = TRANSFORM_TEX(i.uv0, _MainTex);
  70. #ifdef _V2F_HAS_VERTEXCOLOR
  71. o.vertex_color = i.vertex_color;
  72. #endif
  73.  
  74. return o;
  75. }
  76.  
  77. float4 frag_meta(v2f_meta i) : SV_Target {
  78. MetaInput o;
  79. UNITY_INITIALIZE_OUTPUT(MetaInput, o);
  80.  
  81. float2 uv_main = TRANSFORM_TEX(i.uv, _MainTex);
  82.  
  83. float4 color = _Color * PICK_MAIN_TEX2D(_MainTex, uv_main);
  84. #ifdef _VC_ENABLE
  85. color *= lerp(ONE_VEC4, i.vertex_color, _UseVertexColor);
  86. #endif
  87.  
  88. // 単色化
  89. color.rgb = max(ZERO_VEC3, lerp(AVE_RGB(color.rgb).xxx, color.rgb, lerp(1, _GI_IndirectChroma, _GI_Enable)));
  90.  
  91. o.Albedo = color.rgb * lerp(1, _GI_IndirectMultiplier, _GI_Enable);
  92. o.SpecularColor = o.Albedo;
  93. o.Emission = ZERO_VEC3; // 初期化
  94.  
  95. #ifdef _ES_ENABLE
  96.  
  97. FEATURE_TGL_ON_BEGIN(_ES_Enable)
  98. float4 es_mask = PICK_SUB_TEX2D(_EmissionMap, _MainTex, uv_main).rgba;
  99. float4 es_color = _EmissionColor * es_mask;
  100. o.Emission = es_color.rgb * es_color.a * lerp(1, _GI_EmissionMultiplier, _GI_Enable);
  101. FEATURE_TGL_END
  102.  
  103. #endif
  104.  
  105. return MetaFragment(o);
  106. }
  107.  
  108. float4 frag_meta_black(v2f_meta i) : SV_Target {
  109. MetaInput o;
  110. UNITY_INITIALIZE_OUTPUT(MetaInput, o);
  111.  
  112. o.Albedo = ZERO_VEC3;
  113. o.SpecularColor = ZERO_VEC3;
  114. o.Emission = ZERO_VEC3;
  115.  
  116. return MetaFragment(o);
  117. }
  118.  
  119. #endif
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement