generated from AfonsoCMSousa/CPP-Template
Initial Commit.
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
#version 410 core
|
||||
layout(local_size_x = 1) in;
|
||||
|
||||
void main() {
|
||||
// Compute shader code goes here
|
||||
}
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
#version 410 core
|
||||
|
||||
#ifdef GL_ES
|
||||
precision mediump float;
|
||||
#endif
|
||||
|
||||
out vec4 FragColor; // Output to screen
|
||||
|
||||
uniform vec2 u_resolution; // <-- screen resolution from CPU
|
||||
uniform float u_time; // <-- time from CPU
|
||||
uniform float u_oscilator; // <-- oscislator from CPU
|
||||
uniform float u_direction; // <-- direction from CPU
|
||||
|
||||
vec3 hsv2rgb(vec3 c) {
|
||||
vec3 rgb = clamp(
|
||||
abs(mod(c.x*6.0 + vec3(0.0,4.0,2.0),
|
||||
6.0) - 3.0) - 1.0,
|
||||
0.0,
|
||||
1.0
|
||||
);
|
||||
return c.z * mix(vec3(1.0), rgb, c.y);
|
||||
}
|
||||
|
||||
vec3 getPaletteColor(float idx, float seed) {
|
||||
float baseHue = fract(seed); // 0..1 base hue
|
||||
float sat = 0.9;
|
||||
float val = 0.9;
|
||||
|
||||
// Shift hue across palette (idx ensures difference)
|
||||
float hue = fract(baseHue + (idx * 0.33));
|
||||
|
||||
return hsv2rgb(vec3(hue, sat, val));
|
||||
}
|
||||
|
||||
|
||||
vec2 random(vec2 p) {
|
||||
return normalize(vec2(
|
||||
fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453),
|
||||
fract(sin(dot(p, vec2(269.5, 183.3))) * 43758.5453)
|
||||
) * 2.0 - 1.0);
|
||||
}
|
||||
|
||||
int randomInt(int x, int y) {
|
||||
return int(fract(sin(float(x * 12 + y * 78)) * 43758.5453) * 256.0);
|
||||
}
|
||||
|
||||
float perlinNoise(vec2 st) {
|
||||
vec2 i = floor(st);
|
||||
vec2 f = fract(st);
|
||||
|
||||
// Corners
|
||||
vec2 g00 = random(i + vec2(0.0,0.0));
|
||||
vec2 g10 = random(i + vec2(1.0,0.0));
|
||||
vec2 g01 = random(i + vec2(0.0,1.0));
|
||||
vec2 g11 = random(i + vec2(1.0,1.0));
|
||||
|
||||
// Offsets
|
||||
float n00 = dot(g00, f - vec2(0.0,0.0));
|
||||
float n10 = dot(g10, f - vec2(1.0,0.0));
|
||||
float n01 = dot(g01, f - vec2(0.0,1.0));
|
||||
float n11 = dot(g11, f - vec2(1.0,1.0));
|
||||
|
||||
// Interpolation
|
||||
vec2 u = f*f*(3.0-2.0*f);
|
||||
return mix(mix(n00, n10, u.x), mix(n01, n11, u.x), u.y);
|
||||
}
|
||||
|
||||
mat2 rotate2d(float angle){
|
||||
return mat2(cos(angle),-sin(angle),
|
||||
sin(angle),cos(angle));
|
||||
}
|
||||
|
||||
void main() {
|
||||
|
||||
vec2 st = gl_FragCoord.xy / u_resolution; // Normalize coordinates
|
||||
st += 13.0 + (u_oscilator * 0.001); // Center the coordinates
|
||||
|
||||
vec2 pos = st * (3.0);
|
||||
|
||||
pos = rotate2d(perlinNoise(pos)) * pos;
|
||||
pos -= (u_time * (float(u_oscilator) * 0.5) * 0.2);
|
||||
|
||||
float n = perlinNoise(pos);
|
||||
vec3 color;
|
||||
|
||||
if (n > 0.4) {
|
||||
color = vec3((n + 0.4), (n + 0.4), (n + 0.4));
|
||||
// color = getPaletteColor(u_oscilator, (n + 0.5));
|
||||
} else if (n > 0.1) {
|
||||
color = vec3(n + 0.5, n + 0.1 , 0.0);
|
||||
// color = getPaletteColor(u_oscilator + 1, (n + 0.5));
|
||||
} else {
|
||||
color = vec3(n + 0.05, n + 0.05, n + 0.05);
|
||||
// color = getPaletteColor(u_oscilator + 2, (n + 0.5));
|
||||
// color = vec3(0.0);
|
||||
}
|
||||
FragColor = vec4(color, 1.0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
#version 410 core
|
||||
|
||||
layout(location = 0) in vec3 aPos; // Vertex position
|
||||
|
||||
uniform mat4 model;
|
||||
uniform mat4 view;
|
||||
uniform mat4 projection;
|
||||
|
||||
|
||||
void main() {
|
||||
gl_Position = projection * view * model * vec4(aPos, 1.0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user