feat: water rendering (#13)

* refactor: update water texture

* feat(gameplay): implement transparent block rendering with depth sorting

* fix(world): use camera pos for distance calculations, make water passable

* refactor(player): use ivec3 for block pass check

* feat(camera): add underwater detection

* feat(renderer): add underwater effect with framebuffer post-processing

* feat(block): add gas property and refactor solid block check

* fix(assets): set leaf block transparency to false

* fix(block): set leaf as transparent
This commit is contained in:
zhenyan121
2026-05-30 15:11:40 +08:00
committed by GitHub
parent a0139dd315
commit 2906106597
37 changed files with 393 additions and 69 deletions

View File

@@ -1,5 +1,6 @@
id = 0
is_cross_plane = false
is_gas = true
is_liquid = false
is_passable = true
is_transparent = true

View File

@@ -1,5 +1,6 @@
id = 2
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,5 +1,6 @@
id = 9
is_cross_plane = true
is_gas = false
is_liquid = false
is_passable = true
is_transparent = true

View File

@@ -1,5 +1,6 @@
id = 1
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,5 +1,6 @@
id = 6
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = true

View File

@@ -1,5 +1,6 @@
id = 5
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,5 +1,6 @@
id = 4
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,5 +1,6 @@
id = 8
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,5 +1,6 @@
id = 3
is_cross_plane = false
is_gas = false
is_liquid = false
is_passable = false
is_transparent = false

View File

@@ -1,6 +1,7 @@
name = "template"
id = 0
is_liquid = false
is_gas = false
is_passable = false
is_cross_plane = false
is_transparent = false

View File

@@ -1,6 +1,7 @@
id = 7
is_cross_plane = false
is_gas = false
is_liquid = true
is_passable = false
is_transparent = false
is_passable = true
is_transparent = true
name = 'water'

View File

@@ -0,0 +1,35 @@
#version 460
in vec2 TexCoord;
out vec4 FragColor;
uniform sampler2D u_sceneTexture;
uniform float u_time;
uniform bool u_underwater;
uniform vec3 u_waterColor;
uniform float u_fogDensity;
void main() {
vec4 original = texture(u_sceneTexture, TexCoord);
if (!u_underwater) {
FragColor = original;
return;
}
vec2 distoredUV = TexCoord;
float strength = 0.003;
distoredUV.x += sin(TexCoord.y * 15.0 + u_time * 5.0) * strength;
distoredUV.y += cos(TexCoord.x * 15.0 + u_time * 4.3) * strength;
distoredUV = clamp(distoredUV, 0.001, 0.999);
vec4 distorted = texture(u_sceneTexture, distoredUV);
float caustic = 0.9 + 0.1 * sin(TexCoord.x * 20.0 + u_time) * cos(TexCoord.y * 20.0 + u_time * 1.2);
vec3 causticLight = vec3(caustic, caustic * 0.95, caustic * 0.9);
//vec3 causticLight = vec3(1.0);
float fogFactor = clamp(1.0 - (TexCoord.y * u_fogDensity * 10.0), 0.0, 1.0);
vec3 mixed = mix(u_waterColor, distorted.rgb * causticLight, fogFactor);
FragColor = vec4(mixed, 1.0);
}

View File

@@ -0,0 +1,11 @@
#version 460
layout (location = 0) in vec2 pos;
layout (location = 1) in vec2 texCoord;
out vec2 TexCoord;
void main() {
gl_Position = vec4(pos.x, pos.y, 0.0, 1.0);
TexCoord = texCoord;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 262 B

After

Width:  |  Height:  |  Size: 261 B