Skip to content

Commit 7d09305

Browse files
Concrete procedural texture.
1 parent 9526045 commit 7d09305

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

concrete_texture.shader

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Assign material with this shader to any gameobject. You can also seamlessly join material instances with proper offsets.
2+
// For example add to 3D scene two cubes, both with default scale and rotation. Next, set position to first cube (0,0,0) and second cube (1,0,0).
3+
// To first cube assign material1 with shader parameters (Offset X=0,Offset Y=0).
4+
// To second cube assign material2 with shader parameters (Offset X=-2,Offset Y=0).
5+
// Source: https://www.shadertoy.com/view/XtsyRr
6+
Shader "Concrete"
7+
{
8+
Properties
9+
{
10+
_offsetX("Offset X", Float) = 0.0
11+
_offsetY("Offset Y", Float) = 0.0
12+
}
13+
Subshader
14+
{
15+
Pass
16+
{
17+
CGPROGRAM
18+
#pragma vertex vertex_shader
19+
#pragma fragment pixel_shader
20+
#pragma target 4.0
21+
22+
struct custom_type
23+
{
24+
float4 vertex : SV_POSITION;
25+
float2 uv : TEXCOORD0;
26+
};
27+
28+
float _offsetX, _offsetY;
29+
static const float rotation = 180.0;
30+
static const float offsetIntensity = 5.5;
31+
32+
float random (float2 n)
33+
{
34+
return frac(sin(dot(n.xy,float2(12.9898,78.233)))*43758.5453123);
35+
}
36+
37+
float noise (float2 st)
38+
{
39+
float2 i = floor(st);
40+
float2 f = frac(st);
41+
float a = random(i);
42+
float b = random(i + float2(1.0, 0.0));
43+
float c = random(i + float2(0.0, 1.0));
44+
float d = random(i + float2(1.0, 1.0));
45+
float2 u = f*f*(3.0-2.0*f);
46+
return lerp(a,b,u.x)+(c-a)*u.y*(1.0-u.x)+(d-b)*u.x*u.y;
47+
}
48+
49+
float fbm (float2 st)
50+
{
51+
float value = 0.0;
52+
float amplitude = 1.;
53+
float frequency = 2.;
54+
for (int i = 0; i <16; i++)
55+
{
56+
value += amplitude * noise(st);
57+
st *= 3.;
58+
amplitude *= .5;
59+
}
60+
return value;
61+
}
62+
63+
float4 mainNoise(float2 uv)
64+
{
65+
float d = fbm(uv+(fbm(uv)*offsetIntensity));
66+
return float4(d,d,d,1.0);
67+
}
68+
69+
float2 rotate(float2 uv, float a)
70+
{
71+
return float2(uv.x*cos(a)-uv.y*sin(a),uv.y*cos(a)+uv.x*sin(a));
72+
}
73+
74+
custom_type vertex_shader (float4 vertex : POSITION, float2 uv : TEXCOORD0)
75+
{
76+
custom_type vs;
77+
vs.vertex = UnityObjectToClipPos (vertex);
78+
vs.uv = uv;
79+
return vs;
80+
}
81+
82+
float4 pixel_shader (custom_type ps) : COLOR
83+
{
84+
float f = 0.0;
85+
float2 o = float2(_offsetX,_offsetY);
86+
float2 uv = float2(2.0*ps.uv.xy-1.0)+o;
87+
f = 0.5000 * mainNoise( 1.0*uv ).r; uv = rotate(uv, radians(-rotation * 0.1));
88+
f += 0.2500 * mainNoise( 4.0*uv ).r; uv = rotate(uv, radians(-rotation * 0.3));
89+
f += 0.02500 * mainNoise( 8.0*uv ).r; uv = rotate(uv, radians(rotation * 0.5));
90+
f += 0.00125 * mainNoise( 16.0*uv ).r; uv = rotate(uv, radians(rotation * 1.0));
91+
f += 0.0250 * mainNoise( 32.0*uv ).r; uv = rotate(uv, radians(rotation * 0.4));
92+
f += 0.0150 * mainNoise( 64.0*uv ).r; uv = rotate(uv, radians(rotation * 0.4));
93+
f = 0.8*f;
94+
return float4( float3(f,f,f), 1.0 );
95+
}
96+
97+
ENDCG
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)