forked from BrianSharpe/Wombat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValue2D.glsl
More file actions
42 lines (38 loc) · 1.29 KB
/
Value2D.glsl
File metadata and controls
42 lines (38 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// Wombat
// An efficient texture-free GLSL procedural noise library
// Source: https://github.com/BrianSharpe/Wombat
// Derived from: https://github.com/BrianSharpe/GPU-Noise-Lib
//
// I'm not one for copyrights. Use the code however you wish.
// All I ask is that credit be given back to the blog or myself when appropriate.
// And also to let me know if you come up with any changes, improvements, thoughts or interesting uses for this stuff. :)
// Thanks!
//
// Brian Sharpe
// brisharpe CIRCLE_A yahoo DOT com
// http://briansharpe.wordpress.com
// https://github.com/BrianSharpe
//
//
// Value Noise 2D
// Return value range of 0.0->1.0
//
float Value2D( vec2 P )
{
// https://github.com/BrianSharpe/Wombat/blob/master/Value2D.glsl
// establish our grid cell and unit position
vec2 Pi = floor(P);
vec2 Pf = P - Pi;
// calculate the hash.
vec4 Pt = vec4( Pi.xy, Pi.xy + 1.0 );
Pt = Pt - floor(Pt * ( 1.0 / 71.0 )) * 71.0;
Pt += vec2( 26.0, 161.0 ).xyxy;
Pt *= Pt;
Pt = Pt.xzxz * Pt.yyww;
vec4 hash = fract( Pt * ( 1.0 / 951.135664 ) );
// blend the results and return
vec2 blend = Pf * Pf * Pf * (Pf * (Pf * 6.0 - 15.0) + 10.0);
vec4 blend2 = vec4( blend, vec2( 1.0 - blend ) );
return dot( hash, blend2.zxzx * blend2.wwyy );
}