Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Unity built-in shader source. Copyright (c) 2016 Unity Technologies. MIT license (see license.txt)
- // MODIFIED BY MEGAN FOX to include Voronoi noise anti-tiling, algorithm from: http://www.iquilezles.org/www/articles/texturerepetition/texturerepetition.htm
- Shader "Bumped Specular Voronoi" {
- Properties {
- _Color ("Main Color", Color) = (1,1,1,1)
- _MainTex ("Base (RGB)", 2D) = "white" {}
- _BumpMap ("Normalmap", 2D) = "bump" {}
- }
- SubShader {
- Tags { "RenderType"="Opaque" }
- LOD 300
- CGPROGRAM
- #pragma surface surf Lambert
- sampler2D _MainTex;
- sampler2D _BumpMap;
- fixed4 _Color;
- struct Input {
- float2 uv_MainTex;
- float2 uv_BumpMap;
- };
- // (random number sub for non-existent hash4, which is ShaderToy)
- float simple_rand(float2 uv)
- {
- return frac(sin(dot(uv,float2(12.9898,78.233)))*43758.5453123);
- }
- float4 textureNoTile( sampler2D samp, in float2 uv )
- {
- float2 uv_whole = floor( uv );
- float2 uv_fract = uv - uv_whole; // (fract)
- // derivatives (for correct mipmapping)
- float2 uv_ddx = ddx( uv );
- float2 uv_ddy = ddy( uv );
- // voronoi contribution
- float4 color_avg = float4( 0.0, 0.0, 0.0, 0.0 );
- float color_wgt = 0.0;
- float4 normal_avg = float4( 0.0, 0.0, 0.0, 0.0 );
- float normal_wgt = 0.0;
- for( int j=-1; j<=1; j++ )
- for( int i=-1; i<=1; i++ )
- {
- float2 grid_index = float2( float(i), float(j) );
- float4 offset_uv = simple_rand( uv_whole + grid_index );
- float2 random_offset = grid_index - uv_fract + offset_uv.xy;
- float random_dot = dot(random_offset,random_offset);
- float random_weight = exp(-5.0 * random_dot );
- float4 color = tex2Dgrad( samp, uv + offset_uv.zw, uv_ddx, uv_ddy );
- color_avg += random_weight * color;
- color_wgt += random_weight;
- }
- // normalization
- return color_avg/color_wgt;
- }
- void surf (Input IN, inout SurfaceOutput o) {
- fixed4 c = textureNoTile(_MainTex, IN.uv_MainTex) * _Color;
- o.Albedo = c.rgb;
- o.Alpha = c.a;
- o.Normal = UnpackNormal(textureNoTile(_BumpMap, IN.uv_BumpMap));
- }
- ENDCG
- }
- FallBack "Legacy Shaders/Bumped Diffuse"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement