~plainCterraindatashaders
42 itemsDownload ./*

..
frag_shader_clouds.glsl
frag_shader_cube.glsl
frag_shader_depth.glsl
frag_shader_fire.glsl
frag_shader_fireball.glsl
frag_shader_lava.glsl
frag_shader_line.glsl
frag_shader_main.glsl
frag_shader_moon.glsl
frag_shader_post.glsl
frag_shader_sky.glsl
frag_shader_stencil.glsl
frag_shader_sun.glsl
frag_shader_t3d.glsl
frag_shader_terrain.glsl
frag_shader_text.glsl
frag_shader_ui.glsl
frag_shader_vortex.glsl
frag_shader_water2.glsl
frag_shader_water_depth.glsl
frag_shader_water_height.glsl
vert_shader_clouds.glsl
vert_shader_cube.glsl
vert_shader_depth.glsl
vert_shader_fire.glsl
vert_shader_fireball.glsl
vert_shader_lava.glsl
vert_shader_line.glsl
vert_shader_main.glsl
vert_shader_moon.glsl
vert_shader_post.glsl
vert_shader_sky.glsl
vert_shader_stencil.glsl
vert_shader_sun.glsl
vert_shader_t3d.glsl
vert_shader_terrain.glsl
vert_shader_text.glsl
vert_shader_ui.glsl
vert_shader_vortex.glsl
vert_shader_water2.glsl
vert_shader_water_depth.glsl
vert_shader_water_height.glsl


shadersvert_shader_water2.glsl
2 KB• 9•  1 month ago•  DownloadRawClose
1 month ago•  9

{}
#version 330 core
layout (location = 0) in vec3 vPos;
//layout (location = 1) in vec2 vNormal;
layout (location = 1) in vec2 vTexCoord;
//varying vec3 color;
uniform mat4 MVP;
uniform vec3 data; // time offset scale

// water 1 makes procedural direct to mesh (old)
// water 2 (this) takes a premade texture map instead
// (vert/frag_shader_water_height genereate this map)
// (.._water_depth and water 1 is currently not used)
uniform sampler2D waterHeightTex;

out vec3 FragPos;
out vec3 ourNormal;
out vec2 TexCoord;
out float time;
out float height;

// Simple 2D noise function
float noise3(vec2 p) {
    // A basic pseudo-random function (not true Perlin noise, but sufficient for perturbation)
    return fract(sin(dot(p, vec2(12.9898, 78.233))) * 43758.5453);
}

// Smooth noise by interpolation (optional enhancement)
float smoothNoise(vec2 p) {
    vec2 i = floor(p);
    vec2 f = fract(p);
    vec2 u = f * f * (3.0 - 2.0 * f); // Smoothstep
    float a = noise3(i);
    float b = noise3(i + vec2(1.0, 0.0));
    float c = noise3(i + vec2(0.0, 1.0));
    float d = noise3(i + vec2(1.0, 1.0));
    return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
}

void main() {
    //vec3 pos = position;
    // Calculate relative position to origin

    float wlev = data.y-1.1;
    float heightScale = data.z * 2;
    float heightOffset = wlev;
    //heightOffset = 0;

    float phase=data.x;
    float scale=512.0;



    float twinkleSpeed = 86400.0 / 3;
   //-- float twinkle = sin(uTime * twinkleSpeed);

    //time = sin(phase * twinkleSpeed);

    time = phase / (2.0 * 3.14159) * twinkleSpeed;
    ///vec2 flame_uv = uv + vec2(0.0, offset_y);







    TexCoord = vTexCoord * scale - scale / 2.0;
    vec3 sPos = vec3(TexCoord.x, wlev, TexCoord.y);

    height = texture(waterHeightTex, vTexCoord).r;

    // Displace the vertex along the y-axis (assuming y-up)
    sPos.y += height * heightScale;

    // Compute approximate normal using finite differences
    float eps = 0.01;
    float h1 = 0.0, h2 = 0.0;
    vec3 dx = vec3(eps, h1 - height, 0.0);
    vec3 dz = vec3(0.0, h2 - height, eps);
    ourNormal = normalize(cross(dz, dx));

    gl_Position = MVP * vec4(sPos.x, sPos.y, sPos.z, 1.0);
    FragPos = vec3(MVP * vec4(sPos.x, sPos.y, sPos.z, 1.0));
}

Top
©twily.info 2013 - 2025
twily at twily dot info



2 272 938 visits
... ^ v