DefaultShader(Cutout)_createrole.shader 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Shader "Scene/Cutout/DefaultShader_createrole" {
  2. Properties
  3. {
  4. _Color("Main Color", Color) = (1,1,1,1)
  5. _MainTex("Main Texture", 2D) = "white" {}
  6. _Strength("Strength", Range(0, 2)) = 2
  7. _ClrStrength("ClrStrength", Range(0, 1.7)) = 1.7
  8. _ShadowStrength("ShadowStrength", Range(0, 1)) = 0
  9. _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
  10. }
  11. SubShader
  12. {
  13. Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
  14. Pass
  15. {
  16. Tags { "LightMode" = "ForwardBase" }
  17. CGPROGRAM
  18. #pragma vertex vert
  19. #pragma fragment frag
  20. #pragma multi_compile_fog
  21. #pragma multi_compile_fwdbase
  22. #include "HLSLSupport.cginc"
  23. #include "UnityCG.cginc"
  24. #include "Lighting.cginc"
  25. #include "AutoLight.cginc"
  26. sampler2D _MainTex;
  27. float4 _MainTex_ST;
  28. fixed4 _Color;
  29. fixed _Strength;
  30. half _ClrStrength;
  31. half _ShadowStrength;
  32. fixed _Cutoff;
  33. struct V2f {
  34. fixed4 pos : SV_POSITION;
  35. fixed2 uv0 : TEXCOORD0;
  36. #ifndef LIGHTMAP_ON
  37. fixed3 normal : TEXCOORD1;
  38. #endif
  39. #ifdef LIGHTMAP_ON
  40. float2 lmap : TEXCOORD2;
  41. #endif
  42. #ifndef LIGHTMAP_ON
  43. fixed3 vlight : TEXCOORD2;
  44. #endif
  45. LIGHTING_COORDS(3,4)
  46. UNITY_FOG_COORDS(5)
  47. UNITY_VERTEX_OUTPUT_STEREO
  48. };
  49. V2f vert(appdata_full v) {
  50. V2f o;
  51. o.uv0 = TRANSFORM_TEX(v.texcoord, _MainTex);
  52. float3 worldNormal = UnityObjectToWorldNormal(v.normal);
  53. fixed3 normalDir = worldNormal;
  54. o.pos = UnityObjectToClipPos(v.vertex);
  55. #ifdef LIGHTMAP_ON
  56. o.lmap.xy = v.texcoord1.xy * unity_LightmapST.xy + unity_LightmapST.zw;
  57. #endif
  58. #ifndef LIGHTMAP_ON
  59. o.normal = worldNormal;
  60. #endif
  61. #ifndef LIGHTMAP_ON
  62. fixed3 lightDirection = _WorldSpaceLightPos0.xyz;
  63. o.vlight = lerp(max(0,dot(lightDirection, normalDir))*_LightColor0,UNITY_LIGHTMODEL_AMBIENT.rgb,0.2 );
  64. #endif
  65. TRANSFER_VERTEX_TO_FRAGMENT(o);
  66. UNITY_TRANSFER_FOG(o,o.pos);
  67. return o;
  68. }
  69. fixed4 frag(V2f i) : SV_Target{
  70. fixed4 mainTextColor = tex2D(_MainTex, i.uv0) * _Color;
  71. fixed4 mainColor = mainTextColor * _ClrStrength;
  72. fixed atten = LIGHT_ATTENUATION(i);
  73. fixed4 col = 0;
  74. #ifdef LIGHTMAP_ON
  75. fixed3 lm = DecodeLightmap (UNITY_SAMPLE_TEX2D(unity_Lightmap, i.lmap.xy));
  76. #ifdef SHADOWS_SCREENqq
  77. col.rgb = mainColor.rgb * min(lm, atten*2);
  78. #else
  79. col.rgb = mainColor.rgb * lm;
  80. #endif
  81. fixed4 mixCol = mainColor + col;
  82. // 为了让阴影表现明显一些, 使用HSV值的v值来判断阴影部分
  83. half v = max(max(col.r, col.g), col.b);
  84. fixed4 shadowCol = lerp(col, mixCol, v);
  85. col.rgb = lerp(mixCol, shadowCol, _ShadowStrength).rgb;
  86. #else
  87. col.rgb = mainColor.rgb * i.vlight * atten;
  88. col.rgb = mainColor.rgb + col.rgb;
  89. #endif
  90. col.rgb = col.rgb * _Strength;
  91. col.a = mainTextColor.a;
  92. clip(col.a - _Cutoff);
  93. UNITY_APPLY_FOG(i.fogCoord, col);
  94. UNITY_OPAQUE_ALPHA(col.a);
  95. return col;
  96. }
  97. ENDCG
  98. } //normal pass
  99. }
  100. FallBack "Legacy Shaders/Transparent/Cutout/Diffuse"
  101. }