#version 430 core float PI = 3.14159f; uniform sampler2D colorTexture; uniform float exposition; in vec3 vecNormal; in vec3 worldPos; in vec2 vtc; out vec4 outColor; in vec3 viewDirTS; in vec3 lightDirTS; in vec3 sunDirTS; uniform float u_time; float pi = 3.14159; // 2D Random float random (in vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123); } // 2D Noise based on Morgan McGuire @morgan3d // https://www.shadertoy.com/view/4dS3Wd float noise (in vec2 st) { vec2 i = floor(st); vec2 f = fract(st); // Four corners in 2D of a tile float a = random(i); float b = random(i + vec2(1.0, 0.0)); float c = random(i + vec2(0.0, 1.0)); float d = random(i + vec2(1.0, 1.0)); vec2 randA = vec2(a *2.0 *pi); vec2 randB = vec2(b *2.0 *pi); vec2 randC = vec2(c *2.0 *pi); vec2 randD = vec2(d *2.0 *pi); vec2 offsetA = a-st; vec2 offsetB = b-st; vec2 offsetC = c-st; vec2 offsetD = d-st; offsetA = offsetA*randA; offsetB = offsetB*randB; offsetC = offsetC*randC; offsetD = offsetD*randD; float resA = smoothstep(offsetA.x,offsetA.y, f.y); float resB = smoothstep(offsetB.x,offsetB.y, f.y); float resC = smoothstep(offsetC.x,offsetC.y, f.y); float resD = smoothstep(offsetD.x,offsetD.y, f.y); vec2 u = smoothstep(0.,1.,f); float ab= mix(a, b, u.x); float cd = mix(c, d, u.x); return mix(ab,cd,u.y); } void main() { vec2 st = vtc; vec2 pos = vec2(st*3.776); // Use the noise function float n = 1.836 * 0.676*noise(pos*2.576); n = smoothstep(-0.096, 1.176, n); outColor = vec4(vec3(n), 1); }