1
\$\begingroup\$

so i have this compute shader in glsl that creates a heightmap:

#version 450 core

layout (local_size_x = 16, local_size_y = 16) in;

layout (rgba32f, binding = 0) uniform image2D hMap;


uniform vec2 resolution;




float random (in vec2 st) {
    return fract(sin(dot(st.xy,
                         vec2(12.9898,78.233)))*
        43758.5453123);
}


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;
}

float fbm (in vec2 st) {

    float value = 0.0;
    float amplitude = 0.5;
    float frequency = 1.0;


    for (int i = 0; i < 16; i++) {
        value += amplitude * noise(st);
        st *= 2.0;
        amplitude *= 0.5;
    }
    return value;
}






void main() {
    ivec2 texel_coord = ivec2(gl_GlobalInvocationID.xy);

    if (texel_coord.x >= resolution.x || texel_coord.y >= resolution.y) {
        return;
    }

    vec2 uv = vec2(gl_GlobalInvocationID.xy) / resolution.xy ;

    float height = 0.0;


    height = fbm(uv * 2.0);

   

    imageStore(hMap, texel_coord, vec4(height, height, height, 1.0));

}

and i get the result in the attached image.enter image description here

\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.