Teaching_Hand2.shader 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld'
  2. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  3. Shader "Teaching_Hand2" {
  4. Properties {
  5. [Header(Displacement)]
  6. _Displacement_("Displacement", Range(0,1)) = 0.0001
  7. [Header(Color)]
  8. _Color_("Color", Color) = (1,1,1,1)
  9. _Intensity_("Intensity", Range(0,5)) = 2.5
  10. [Header(Edge)]
  11. _Exponent_("Exponent", Range(0,10)) = 2
  12. _Soften_("Soften", Range(0.001,1)) = 0.3
  13. [Header(Fade In)]
  14. _Fade_In_Start_("Fade In Start", Range(0,1)) = 0.25
  15. _Fade_In_End_("Fade In End", Range(0,1)) = 0.5
  16. [Header(Soften Hold Out)]
  17. [Toggle(_ENABLE_)] _Enable_("Enable", Float) = 0
  18. _Center_("Center", Vector) = (0.5,0.5,0,0)
  19. _Radius_("Radius", Range(0,1)) = 0.071
  20. _Blur_("Blur", Range(0,1)) = 0.061
  21. }
  22. SubShader {
  23. Tags { "RenderType" = "Transparent" "Queue" = "Transparent" }
  24. Blend One One
  25. ZWrite Off
  26. LOD 100
  27. Pass {
  28. ColorMask 0
  29. ZWrite On
  30. CGPROGRAM
  31. #pragma vertex vert
  32. #pragma fragment frag
  33. #include "UnityCG.cginc"
  34. struct v2f {
  35. float4 vertex : SV_POSITION;
  36. UNITY_VERTEX_OUTPUT_STEREO
  37. };
  38. v2f vert (appdata_img v)
  39. {
  40. UNITY_SETUP_INSTANCE_ID(v);
  41. v2f o;
  42. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  43. o.vertex = UnityObjectToClipPos(v.vertex);
  44. return o;
  45. }
  46. fixed4 frag (v2f i) : SV_Target
  47. {
  48. return 0;
  49. }
  50. ENDCG
  51. }
  52. Pass
  53. {
  54. CGPROGRAM
  55. #pragma vertex vert
  56. #pragma fragment frag
  57. #pragma multi_compile_instancing
  58. #pragma target 4.0
  59. #pragma multi_compile _ _ENABLE_
  60. #include "UnityCG.cginc"
  61. float _Displacement_;
  62. float _Fade_In_Start_;
  63. float _Fade_In_End_;
  64. half4 _Color_;
  65. half _Intensity_;
  66. //bool _Enable_;
  67. float2 _Center_;
  68. half _Radius_;
  69. half _Blur_;
  70. half _Exponent_;
  71. half _Soften_;
  72. struct VertexInput {
  73. float4 vertex : POSITION;
  74. half3 normal : NORMAL;
  75. float2 uv0 : TEXCOORD0;
  76. UNITY_VERTEX_INPUT_INSTANCE_ID
  77. };
  78. struct VertexOutput {
  79. float4 pos : SV_POSITION;
  80. half4 normalWorld : TEXCOORD5;
  81. float2 uv : TEXCOORD0;
  82. float3 posWorld : TEXCOORD7;
  83. UNITY_VERTEX_OUTPUT_STEREO
  84. };
  85. // declare parm vars here
  86. VertexOutput vert(VertexInput vertInput)
  87. {
  88. UNITY_SETUP_INSTANCE_ID(vertInput);
  89. VertexOutput o;
  90. UNITY_INITIALIZE_VERTEX_OUTPUT_STEREO(o);
  91. // Object_To_World_Dir
  92. float3 Dir_World_Q47=(mul((float3x3)unity_ObjectToWorld, vertInput.normal));
  93. // Object_To_World_Pos
  94. float3 Pos_World_Q48=(mul(unity_ObjectToWorld, float4(vertInput.vertex.xyz, 1)));
  95. // Scale3
  96. float3 Result_Q23 = _Displacement_ * Dir_World_Q47;
  97. // Add3
  98. float3 Sum3_Q24 = Pos_World_Q48 + Result_Q23;
  99. float3 Position = Sum3_Q24;
  100. float3 Normal = Dir_World_Q47;
  101. float2 UV = vertInput.uv0;
  102. float3 Tangent = float3(0,0,0);
  103. float3 Binormal = float3(0,0,0);
  104. float4 Color = float4(1,1,1,1);
  105. o.pos = UnityObjectToClipPos(vertInput.vertex);
  106. o.pos = mul(UNITY_MATRIX_VP, float4(Position,1));
  107. o.posWorld = Position;
  108. o.normalWorld.xyz = Normal; o.normalWorld.w=1.0;
  109. o.uv = UV;
  110. return o;
  111. }
  112. //fixed4 frag(VertexOutput fragInput, fixed facing : VFACE) : SV_Target
  113. half4 frag(VertexOutput fragInput) : SV_Target
  114. {
  115. half4 result;
  116. // To_XY
  117. float X_Q34;
  118. float Y_Q34;
  119. X_Q34 = fragInput.uv.x;
  120. Y_Q34 = fragInput.uv.y;
  121. // Soften_Hold_Out
  122. half Result_Q46;
  123. #if defined(_ENABLE_)
  124. Result_Q46 = saturate((distance(fragInput.uv,_Center_)-_Radius_)/_Blur_);
  125. #else
  126. Result_Q46 = 1.0;
  127. #endif
  128. // Incident3
  129. float3 Incident_Q25 = normalize(fragInput.posWorld - _WorldSpaceCameraPos);
  130. // Normalize3
  131. float3 Normalized_Q26 = normalize(fragInput.normalWorld.xyz);
  132. // Ramp
  133. half Ramp_Q45 = clamp((Y_Q34-_Fade_In_Start_)/(_Fade_In_End_-_Fade_In_Start_),0,1);
  134. // DotProduct3
  135. half Dot_Q30 = dot(Incident_Q25, Normalized_Q26);
  136. // Abs
  137. half AbsA_Q31 = abs(Dot_Q30);
  138. // SoftenEdges
  139. half Result_Q43 = 1.0-(1.0-saturate(-Dot_Q30/_Soften_))*Result_Q46;
  140. // One_Minus
  141. half One_Minus_F_Q32 = 1.0 - AbsA_Q31;
  142. // Power
  143. half Power_Q44 = pow(One_Minus_F_Q32, _Exponent_);
  144. // Multiply
  145. half Product_Q33 = Power_Q44 * Result_Q43;
  146. // Multiply
  147. half Product_Q37 = Ramp_Q45 * Product_Q33;
  148. // Multiply
  149. half Product_Q38 = _Intensity_ * Product_Q37;
  150. // Scale_Color
  151. half4 Result_Q40 = Product_Q38 * _Color_;
  152. float4 Out_Color = Result_Q40;
  153. float Clip_Threshold = 0;
  154. result = Out_Color;
  155. return result;
  156. }
  157. ENDCG
  158. }
  159. }
  160. }