DefaultShader(MultiLight).shader 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. Shader "Scene/DefaultShader(MultiLight)" {
  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. }
  10. SubShader {
  11. Tags { "RenderType"="Opaque" }
  12. LOD 150
  13. CGPROGRAM
  14. #pragma surface surf CustomLight noforwardadd
  15. sampler2D _MainTex;
  16. fixed4 _Color;
  17. fixed _Strength;
  18. fixed _ClrStrength;
  19. fixed _ShadowStrength;
  20. struct Input {
  21. float2 uv_MainTex;
  22. };
  23. void surf (Input IN, inout SurfaceOutput o) {
  24. fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color * _ClrStrength;
  25. o.Albedo = c.rgb;
  26. o.Alpha = c.a;
  27. }
  28. // 自定义光照模型
  29. fixed4 LightingCustomLight(SurfaceOutput s, UnityGI gi)
  30. {
  31. fixed4 c;
  32. c = UnityLambertLight (s, gi.light);
  33. #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
  34. // 为了让阴影表现明显一些, 使用HSV值的v值来判断阴影部分
  35. fixed3 col = s.Albedo * gi.indirect.diffuse;
  36. fixed3 mixCol = s.Albedo + col;
  37. fixed v = max(max(col.r, col.g), col.b);
  38. fixed3 shadowCol = lerp(col, mixCol, v);
  39. c.rgb = lerp(mixCol, shadowCol, _ShadowStrength) + c.rgb;
  40. #endif
  41. c.rgb *= _Strength;
  42. return c;
  43. }
  44. half4 LightingCustomLight_Deferred (SurfaceOutput s, UnityGI gi, out half4 outGBuffer0, out half4 outGBuffer1, out half4 outGBuffer2)
  45. {
  46. UnityStandardData data;
  47. data.diffuseColor = s.Albedo;
  48. data.occlusion = 1;
  49. data.specularColor = 0;
  50. data.smoothness = 0;
  51. data.normalWorld = s.Normal;
  52. UnityStandardDataToGbuffer(data, outGBuffer0, outGBuffer1, outGBuffer2);
  53. half4 emission = half4(s.Emission, 1);
  54. #ifdef UNITY_LIGHT_FUNCTION_APPLY_INDIRECT
  55. // 为了让阴影表现明显一些, 使用HSV值的v值来判断阴影部分
  56. fixed3 col = s.Albedo * gi.indirect.diffuse;
  57. fixed3 mixCol = s.Albedo + col;
  58. fixed v = max(max(col.r, col.g), col.b);
  59. fixed3 shadowCol = lerp(col, mixCol, v);
  60. emission.rgb = lerp(mixCol, shadowCol, _ShadowStrength) + emission.rgb;
  61. emission.rgb += s.Albedo * gi.indirect.diffuse;
  62. #endif
  63. return emission;
  64. }
  65. fixed4 LightingCustomLight_PrePass (SurfaceOutput s, half4 light)
  66. {
  67. fixed4 c;
  68. c.rgb = s.Albedo * light.rgb;
  69. c.a = s.Alpha;
  70. return c;
  71. }
  72. void LightingCustomLight_GI (
  73. SurfaceOutput s,
  74. UnityGIInput data,
  75. inout UnityGI gi)
  76. {
  77. gi = UnityGlobalIllumination (data, 1.0, s.Normal);
  78. }
  79. ENDCG
  80. }
  81. FallBack "Mobile/Diffuse"
  82. }