Guest User

Sand.shader

a guest
Apr 3rd, 2015
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. // By Tim Volp
  2. // Updated 04/04/15
  3.  
  4. Shader "Custom/Sand" {
  5. Properties {
  6. _Color ("Main Color", Color) = (0.5,0.5,0.5,1)
  7. _MainTex ("Base (RGB)", 2D) = "white" {}
  8. _BumpMap ("Normalmap", 2D) = "bump" {}
  9. _Grain ("Grain", 2D) = "gray" {}
  10. _Graininess ("Graininess", Float) = 10.0
  11. _Shininess ("Shininess", Float) = 200.0
  12. _Reflectance ("Reflectance", Float) = 5.0
  13. }
  14.  
  15. SubShader {
  16. Tags { "RenderType"="Opaque" }
  17. LOD 200
  18.  
  19. CGPROGRAM
  20. #pragma surface surf Sand
  21.  
  22. sampler2D _Grain;
  23. half _Graininess;
  24. half _Shininess;
  25. half _Reflectance;
  26.  
  27. // Custom lighting model
  28. inline half4 LightingSand(SurfaceOutput s, half3 lightDir, half3 viewDir, half atten) {
  29. #ifndef USING_DIRECTIONAL_LIGHT
  30. lightDir = normalize(lightDir);
  31. #endif
  32.  
  33. viewDir = normalize(viewDir);
  34.  
  35. // Calculate lighting from angle between normal and light direction
  36. half NdotL = saturate(dot(s.Normal, lightDir));
  37.  
  38. // Calculate reflected light direction from light direction and normal
  39. lightDir = reflect(lightDir, s.Normal);
  40.  
  41. // Calculate specular lighting from absolute angle between reflected light direction and view direction
  42. half specular = saturate(abs(dot(lightDir, viewDir)));
  43.  
  44. // New detail based on detail texture and graininess
  45. half detail = tex2D(_Grain, half2(fmod(viewDir.z * _Graininess, 1.0), fmod(s.Normal.x * _Graininess, 1.0)));
  46.  
  47. // New specular based on shininess and detail
  48. specular = pow(specular, _Shininess) * floor(detail * _Reflectance);
  49.  
  50. half4 c;
  51. c.rgb = s.Albedo * _LightColor0.rgb * (atten * 2) * (NdotL + specular);
  52. c.a = s.Alpha;
  53. return c;
  54. }
  55.  
  56. sampler2D _MainTex;
  57. sampler2D _BumpMap;
  58. half4 _Color;
  59.  
  60. struct Input {
  61. half2 uv_MainTex;
  62. half2 uv_BumpMap;
  63. half2 uv_Grain;
  64. };
  65.  
  66. void surf (Input IN, inout SurfaceOutput o) {
  67. o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  68.  
  69. half4 c = tex2D(_MainTex, IN.uv_MainTex);
  70. o.Albedo = c.rgb * _Color;
  71. //o.Albedo *= tex2D (_Grain, IN.uv_Grain).rgb * 1.5;
  72. o.Alpha = c.a;
  73. }
  74. ENDCG
  75. }
  76. FallBack "Diffuse"
  77. }
Advertisement
Add Comment
Please, Sign In to add comment