improve water further
This commit is contained in:
parent
68828cb119
commit
4f7b7b20bc
BIN
resources/utiltex/water1.png
Normal file
BIN
resources/utiltex/water1.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 551 KiB |
File diff suppressed because it is too large
Load Diff
@ -76,15 +76,45 @@ vec3 fresnelSchlick(float cosTheta) {
|
|||||||
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float hash(vec2 p) {
|
||||||
|
return fract(sin(dot(p, vec2(127.1, 311.7))) * 43758.5453);
|
||||||
|
}
|
||||||
|
|
||||||
|
float noise(vec2 p) {
|
||||||
|
vec2 i = floor(p);
|
||||||
|
vec2 f = fract(p);
|
||||||
|
vec2 u = f * f * (3.0 - 2.0 * f);
|
||||||
|
return mix(mix(hash(i + vec2(0.0, 0.0)),
|
||||||
|
hash(i + vec2(1.0, 0.0)), u.x),
|
||||||
|
mix(hash(i + vec2(0.0, 1.0)),
|
||||||
|
hash(i + vec2(1.0, 1.0)), u.x), u.y);
|
||||||
|
}
|
||||||
|
|
||||||
|
float fbm(vec2 p) {
|
||||||
|
float value = 0.0;
|
||||||
|
float amplitude = 0.5;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
value += amplitude * noise(p);
|
||||||
|
p *= 2.0; // Double the frequency
|
||||||
|
amplitude *= 0.5; // Halve the amplitude
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
if(idx == 1) { // Second instance of the plane is the actual water surface.
|
if(idx == 1) { // Second instance of the plane is the actual water surface.
|
||||||
vec2 uv1 = pos.xz * 0.1 + time * 0.01;
|
vec2 uv1 = pos.xz * 0.4 + time * vec2(-0.005, -0.012) * 1.5;
|
||||||
vec2 uv2 = pos.xz * 0.1 + time * vec2(-0.005, -0.012);
|
vec2 uv2 = pos.xz * 0.1 + time * vec2(-0.005, -0.012) * 1.7;
|
||||||
|
vec2 uv3 = pos.xz * 1.0 + time * vec2(-0.005, -0.012) * 2.7;
|
||||||
|
vec2 uv4 = pos.xz * 0.02 + time * vec2(-0.005, -0.012) * 0.1;
|
||||||
|
|
||||||
vec3 normal1 = texture(sampler2D(normal_map, normalsmp), uv1).xzy * 2.0 - 1.0;
|
vec3 normal1 = texture(sampler2D(normal_map, normalsmp), uv1).xzy * 2.0 - 1.0;
|
||||||
vec3 normal2 = texture(sampler2D(normal_map, normalsmp), uv2).xzy * 2.0 - 1.0;
|
vec3 normal2 = texture(sampler2D(normal_map, normalsmp), uv2).xzy * 2.0 - 1.0;
|
||||||
|
vec3 normal3 = texture(sampler2D(normal_map, normalsmp), uv3).xzy * 2.0 - 1.0;
|
||||||
|
vec3 normal4 = texture(sampler2D(normal_map, normalsmp), uv4).xzy * 2.0 - 1.0;
|
||||||
|
|
||||||
vec3 normal = normalize(normal1 + normal2);
|
// vec3 normal = normalize(vec3(0.0, 1.0, 0.0));
|
||||||
|
vec3 normal = normalize(normal1 + normal2 + normal3 + normal4);
|
||||||
|
|
||||||
vec3 view_dir = normalize(cameraPosition - pos.xyz);
|
vec3 view_dir = normalize(cameraPosition - pos.xyz);
|
||||||
vec3 light_dir = normalize(sunPosition);
|
vec3 light_dir = normalize(sunPosition);
|
||||||
@ -99,20 +129,22 @@ void main() {
|
|||||||
vec3 specular_highlight = sunLightColor * sunIntensity * spec;
|
vec3 specular_highlight = sunLightColor * sunIntensity * spec;
|
||||||
|
|
||||||
vec2 screen_uv = gl_FragCoord.xy / vec2(screen_w, screen_h);
|
vec2 screen_uv = gl_FragCoord.xy / vec2(screen_w, screen_h);
|
||||||
vec2 distortion = normal.xz * 0.005;
|
|
||||||
screen_uv.y = 1.0 - screen_uv.y;
|
screen_uv.y = 1.0 - screen_uv.y;
|
||||||
vec3 reflected_color = texture(sampler2D(reftex, refsmp), screen_uv + distortion).rgb;
|
vec3 reflected_color = texture(sampler2D(reftex, refsmp), screen_uv).rgb;
|
||||||
|
|
||||||
vec3 surface_color = mix(refracted_color, reflected_color, fresnel);
|
vec3 surface_color = mix(refracted_color, reflected_color, fresnel);
|
||||||
vec3 final_color = (surface_color + specular_highlight) * shadow_factor;
|
vec3 final_color = (surface_color + specular_highlight) * shadow_factor;
|
||||||
float refraction_alpha = 0.3; // Base transparency when looking straight down
|
float refraction_alpha = 0.3;
|
||||||
float reflection_alpha = 0.5; // Surface is opaque where it's most reflective
|
float reflection_alpha = 0.5;
|
||||||
float alpha = mix(refraction_alpha, reflection_alpha, fresnel);
|
float alpha = mix(refraction_alpha, reflection_alpha, fresnel);
|
||||||
|
|
||||||
frag_color = vec4(final_color, alpha);
|
frag_color = vec4(final_color, alpha);
|
||||||
|
|
||||||
} else { // Deep water plane (unchanged)
|
} else { // Deep water plane
|
||||||
frag_color = vec4(deepColor, 1.0);
|
vec2 noise_uv = pos.xz * 0.05 + time * 0.01;
|
||||||
|
float noise_value = fbm(noise_uv);
|
||||||
|
vec3 noisy_deep_color = deepColor * mix(0.8, 1.2, noise_value);
|
||||||
|
frag_color = vec4(noisy_deep_color, 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user