NormalOverlay.shader 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. Shader "Unlit/NormalOverlay"
  2. {
  3. Properties
  4. {
  5. _Transparency ("Transparency", Range(0, 1)) = 0.5
  6. }
  7. // URP SubShader
  8. SubShader
  9. {
  10. PackageRequirements
  11. {
  12. "com.unity.render-pipelines.universal"
  13. }
  14. Blend SrcAlpha OneMinusSrcAlpha
  15. Tags
  16. {
  17. "Queue" = "AlphaTest"
  18. "RenderType" = "Transparent"
  19. "ForceNoShadowCasting" = "True"
  20. "RenderPipeline" = "UniversalPipeline"
  21. }
  22. Pass
  23. {
  24. ZTest LEqual
  25. ZWrite On
  26. Lighting Off
  27. LOD 100
  28. Tags
  29. {
  30. "LightMode" = "UniversalForward"
  31. }
  32. HLSLPROGRAM
  33. #pragma vertex vert
  34. #pragma fragment frag
  35. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  36. struct appdata
  37. {
  38. float3 position : POSITION;
  39. float3 normal : NORMAL;
  40. UNITY_VERTEX_INPUT_INSTANCE_ID
  41. };
  42. struct v2f
  43. {
  44. float4 position : SV_POSITION;
  45. half3 worldNormal : TEXCOORD0;
  46. UNITY_VERTEX_OUTPUT_STEREO
  47. };
  48. struct fragment_output
  49. {
  50. half4 color : SV_Target;
  51. };
  52. v2f vert (appdata v)
  53. {
  54. v2f o;
  55. UNITY_SETUP_INSTANCE_ID(v);
  56. ZERO_INITIALIZE(v2f, o);
  57. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  58. o.position = TransformObjectToHClip(v.position);
  59. o.worldNormal = TransformObjectToWorldNormal(v.normal);
  60. return o;
  61. }
  62. float _Transparency;
  63. fragment_output frag (v2f i)
  64. {
  65. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  66. fragment_output o;
  67. o.color.xyz = i.worldNormal * 0.5f + 0.5f;
  68. o.color.w = _Transparency;
  69. return o;
  70. }
  71. ENDHLSL
  72. }
  73. }
  74. // Built-in Render Pipeline SubShader
  75. SubShader
  76. {
  77. Blend SrcAlpha OneMinusSrcAlpha
  78. Tags
  79. {
  80. "Queue" = "AlphaTest"
  81. "RenderType" = "Transparent"
  82. "ForceNoShadowCasting" = "True"
  83. }
  84. Pass
  85. {
  86. ZTest LEqual
  87. ZWrite On
  88. Lighting Off
  89. LOD 100
  90. Tags
  91. {
  92. "LightMode" = "Always"
  93. }
  94. HLSLPROGRAM
  95. #pragma vertex vert
  96. #pragma fragment frag
  97. #include "UnityCG.cginc"
  98. struct appdata
  99. {
  100. float3 position : POSITION;
  101. float3 normal : NORMAL;
  102. UNITY_VERTEX_INPUT_INSTANCE_ID
  103. };
  104. struct v2f
  105. {
  106. float4 position : SV_POSITION;
  107. half3 worldNormal : TEXCOORD0;
  108. UNITY_VERTEX_OUTPUT_STEREO
  109. };
  110. struct fragment_output
  111. {
  112. half4 color : SV_Target;
  113. };
  114. v2f vert (appdata v)
  115. {
  116. v2f o;
  117. UNITY_SETUP_INSTANCE_ID(v);
  118. UNITY_INITIALIZE_OUTPUT(v2f, o);
  119. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  120. o.position = UnityObjectToClipPos(v.position);
  121. o.worldNormal = UnityObjectToWorldNormal(v.normal);
  122. return o;
  123. }
  124. float _Transparency;
  125. fragment_output frag (v2f i)
  126. {
  127. UNITY_SETUP_STEREO_EYE_INDEX_POST_VERTEX(i);
  128. fragment_output o;
  129. o.color.xyz = i.worldNormal * 0.5f + 0.5f;
  130. o.color.w = _Transparency;
  131. return o;
  132. }
  133. ENDHLSL
  134. }
  135. }
  136. Fallback Off
  137. }