Modern-Apps.git
Publicgit clone https://git.maproj.org/Modern-Apps.gitModern-Apps.git / games / voxels / src / main / rust / shaders / water.vert
water.vert35 lines · 1.3 KiBRaw
| 1 | #version 450 |
| 2 | layout(location=0) in vec3 inPos; |
| 3 | layout(location=1) in vec2 inUv; |
| 4 | layout(location=2) in vec3 inColor; |
| 5 | layout(location=3) in float inAo; |
| 6 | layout(location=4) in float inTileIdx; |
| 7 | layout(location=5) in vec3 inNormal; |
| 8 | |
| 9 | layout(binding=0) uniform Ubo { |
| 10 | mat4 viewProj; |
| 11 | vec3 sunDir; |
| 12 | float time; |
| 13 | vec3 fogColor; |
| 14 | float fogDensity; |
| 15 | vec4 playerPos; // .w = underwater flag |
| 16 | float dayFactor; |
| 17 | }; |
| 18 | |
| 19 | layout(location=0) out vec3 fragWorldPos; |
| 20 | layout(location=1) out float fragDist; |
| 21 | layout(location=2) out vec3 fragNormal; |
| 22 | |
| 23 | void main() { |
| 24 | // Keep the surface geometrically flat (uniform sink below the block top) so greedy-mesh |
| 25 | // T-junctions don't crack; the wave lives entirely in the shading normal (+ frag ripples). |
| 26 | vec3 p = inPos; |
| 27 | p.y -= 0.1; |
| 28 | // Analytic wave normal from a virtual height field (shading only, no vertex displacement). |
| 29 | float dhx = 0.6 * cos(inPos.x * 0.6 + time * 1.5) * 0.06 + 0.3 * cos((inPos.x + inPos.z) * 0.3 + time * 0.7) * 0.04; |
| 30 | float dhz = 0.5 * cos(inPos.z * 0.5 + time * 1.1) * 0.06 + 0.3 * cos((inPos.x + inPos.z) * 0.3 + time * 0.7) * 0.04; |
| 31 | fragNormal = normalize(vec3(-dhx, 1.0, -dhz)); |
| 32 | fragWorldPos = p; |
| 33 | fragDist = length(p - playerPos.xyz); |
| 34 | gl_Position = viewProj * vec4(p, 1.0); |
| 35 | } |