Advertisement
Guest User

Untitled

a guest
Oct 31st, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
  2. // MODIFIED BY MEGAN FOX to include Voronoi noise anti-tiling, algorithm from: http://www.iquilezles.org/www/articles/texturerepetition/texturerepetition.htm
  3.  
  4. Shader "Bumped Specular Voronoi" {
  5. Properties {
  6. _Color ("Main Color", Color) = (1,1,1,1)
  7. _MainTex ("Base (RGB)", 2D) = "white" {}
  8. _BumpMap ("Normalmap", 2D) = "bump" {}
  9. }
  10.  
  11. SubShader {
  12. Tags { "RenderType"="Opaque" }
  13. LOD 300
  14.  
  15. CGPROGRAM
  16. #pragma surface surf Lambert
  17.  
  18. sampler2D _MainTex;
  19. sampler2D _BumpMap;
  20. fixed4 _Color;
  21.  
  22. struct Input {
  23. float2 uv_MainTex;
  24. float2 uv_BumpMap;
  25. };
  26.  
  27. // (random number sub for non-existent hash4, which is ShaderToy)
  28. float simple_rand(float2 uv)
  29. {
  30. return frac(sin(dot(uv,float2(12.9898,78.233)))*43758.5453123);
  31. }
  32.  
  33. float4 textureNoTile( sampler2D samp, in float2 uv )
  34. {
  35. float2 uv_whole = floor( uv );
  36. float2 uv_fract = uv - uv_whole; // (fract)
  37.  
  38. // derivatives (for correct mipmapping)
  39. float2 uv_ddx = ddx( uv );
  40. float2 uv_ddy = ddy( uv );
  41.  
  42. // voronoi contribution
  43. float4 color_avg = float4( 0.0, 0.0, 0.0, 0.0 );
  44. float color_wgt = 0.0;
  45.  
  46. float4 normal_avg = float4( 0.0, 0.0, 0.0, 0.0 );
  47. float normal_wgt = 0.0;
  48.  
  49. for( int j=-1; j<=1; j++ )
  50. for( int i=-1; i<=1; i++ )
  51. {
  52. float2 grid_index = float2( float(i), float(j) );
  53. float4 offset_uv = simple_rand( uv_whole + grid_index );
  54. float2 random_offset = grid_index - uv_fract + offset_uv.xy;
  55. float random_dot = dot(random_offset,random_offset);
  56. float random_weight = exp(-5.0 * random_dot );
  57.  
  58. float4 color = tex2Dgrad( samp, uv + offset_uv.zw, uv_ddx, uv_ddy );
  59. color_avg += random_weight * color;
  60. color_wgt += random_weight;
  61. }
  62.  
  63. // normalization
  64. return color_avg/color_wgt;
  65. }
  66.  
  67. void surf (Input IN, inout SurfaceOutput o) {
  68. fixed4 c = textureNoTile(_MainTex, IN.uv_MainTex) * _Color;
  69. o.Albedo = c.rgb;
  70. o.Alpha = c.a;
  71. o.Normal = UnpackNormal(textureNoTile(_BumpMap, IN.uv_BumpMap));
  72. }
  73. ENDCG
  74. }
  75.  
  76. FallBack "Legacy Shaders/Bumped Diffuse"
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement