diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-01-26 18:42:26 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2024-01-26 18:42:32 +0100 |
commit | c47a562e00488575cfde58fd1d2f84c3ab66883f (patch) | |
tree | de24ada201bfadc487d9ff6ec940202438ba63a9 /assets/wood.glsl | |
download | juxtapos-c47a562e00488575cfde58fd1d2f84c3ab66883f.tar.xz |
init
Diffstat (limited to 'assets/wood.glsl')
-rw-r--r-- | assets/wood.glsl | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/assets/wood.glsl b/assets/wood.glsl new file mode 100644 index 0000000..5ec6265 --- /dev/null +++ b/assets/wood.glsl @@ -0,0 +1,40 @@ +#version 430 +layout(local_size_x = 1, local_size_y = 1) in; +layout(rgba32f, binding = 0) uniform image2D texture; + +// perlin noise taken from https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83 + +#define M_PI 3.14159265358979323846 + +float rand(vec2 co){return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453);} +float rand (vec2 co, float l) {return rand(vec2(rand(co), l));} +float rand (vec2 co, float l, float t) {return rand(vec2(rand(co, l), t));} + +float perlin(vec2 p, float dim, float time) { + vec2 pos = floor(p * dim); + vec2 posx = pos + vec2(1.0, 0.0); + vec2 posy = pos + vec2(0.0, 1.0); + vec2 posxy = pos + vec2(1.0); + + float c = rand(pos, dim, time); + float cx = rand(posx, dim, time); + float cy = rand(posy, dim, time); + float cxy = rand(posxy, dim, time); + + vec2 d = fract(p * dim); + d = -0.5 * cos(d * M_PI) + 0.5; + + float ccx = mix(c, cx, d.x); + float cycxy = mix(cy, cxy, d.x); + float center = mix(ccx, cycxy, d.y); + + return center * 2.0 - 1.0; +} + +void main() { + ivec2 pixelCoords = ivec2(gl_GlobalInvocationID.xy); + vec2 coords = vec2(pixelCoords) / vec2(512); + + // TODO: proper wood texture generation + imageStore(texture, pixelCoords, (0.5+perlin(coords / 25, 512.0, 0.0)) * vec4(110, 51, 7, 255) / 255); +} |