PlanetEditor/grk/cw 6/shaders/shader_noise.frag

222 lines
4.9 KiB
GLSL
Raw Normal View History

2024-01-29 00:54:18 +01:00
#version 430 core
2024-01-29 19:41:22 +01:00
/*float PI = 3.14159f;
2024-01-29 00:54:18 +01:00
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);
2024-01-29 19:41:22 +01:00
pos.x -= u_time * 0.07;
2024-01-29 00:54:18 +01:00
// 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);
}
2024-01-29 19:41:22 +01:00
*/
out vec4 outColor;
uniform float u_time;
in vec2 vtc;
float random (in vec2 _st) {
return fract(sin(dot(_st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
// 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 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
#define NUM_OCTAVES 5
float fbm ( in vec2 _st) {
float v = 0.0;
float a = 0.5;
vec2 shift = vec2(100.0);
// Rotate to reduce axial bias
mat2 rot = mat2(cos(0.5), sin(0.5),
-sin(0.5), cos(0.50));
for (int i = 0; i < NUM_OCTAVES; ++i) {
v += a * noise(_st);
_st = rot * _st * 3.0 + shift;
a *= 0.6;
}
return v;
}
void main() {
vec2 st = vtc;
// st += st * abs(sin(u_time*0.1)*3.0);
vec3 color = vec3(0.0);
vec2 q = vec2(0.);
q.x = fbm( st + 0.00*u_time);
q.y = fbm( st + vec2(1.0));
vec2 r = vec2(0.);
r.x = fbm( st + 1.0*q + vec2(1.7,9.2)+ 0.15*u_time );
r.y = fbm( st + 1.0*q + vec2(8.3,2.8)+ 0.126*u_time);
float f = fbm(st+r);
color = mix(vec3(0.101961,0.619608,0.666667),
vec3(0.666667,0.666667,0.498039),
clamp((f*f)*4.0,0.0,1.0));
color = mix(color,
vec3(0.995,0.077,0.220),
clamp(length(q),0.0,1.0));
color = mix(color,
vec3(1.000,0.925,0.132),
clamp(length(r.x),0.0,1.0));
outColor = vec4((f*f*f+.9*f*f+.9*f)*color,1.);
}
/*
uniform float u_time;
out vec4 outColor;
in vec2 vtc;
in vec3 worldPos;
vec2 u_resolution = vec2(1024, 1024);
float random (in vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
// 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 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
#define OCTAVES 6
float fbm (in vec2 st) {
// Initial values
float value = 0.0;
float amplitude = .5;
float frequency = 0.;
//
// Loop of octaves
for (int i = 0; i < OCTAVES; i++) {
value += amplitude * noise(st);
st *= 2.;
amplitude *= .5;
}
return value;
}
void main() {
vec2 st = vtc;
//vec2 st = vtc.xy/worldPos.xy;
//st += st * abs(sin(u_time*0.1)*10.0);
//st.x *= worldPos.x/worldPos.y;
vec3 color = vec3(0.0);
color += fbm(st*3.0);
vec3 mixedColor = mix(vec3(0.4), color, color.r);
//color = mix(vec3(1.0), fbm(st*3.0), 0.1);
outColor = vec4(mixedColor,1.0);
}*/