48 lines
1.3 KiB
GLSL
48 lines
1.3 KiB
GLSL
precision highp float;
|
|
precision highp int;
|
|
|
|
#include <utils>
|
|
|
|
uniform float wallOpacity;
|
|
uniform float wallMode;
|
|
uniform vec3 volumeColor;
|
|
uniform sampler2D sceneTexture;
|
|
uniform vec2 resolution;
|
|
uniform float useSceneRefraction;
|
|
uniform float surfaceTransmittance;
|
|
uniform float normalStrength;
|
|
uniform float refractionStrength;
|
|
|
|
in vec3 pos;
|
|
|
|
out vec4 fragColor;
|
|
|
|
void main() {
|
|
vec3 baseColor = wallMode > 0.5 ? volumeColor : getWallColor(pos) * volumeColor;
|
|
|
|
vec4 info = texture(water, pos.xz * 0.5 + 0.5);
|
|
vec2 screenUV = gl_FragCoord.xy / resolution;
|
|
vec2 offset = info.ba * normalStrength * refractionStrength;
|
|
|
|
vec3 mixedColor = baseColor;
|
|
if (useSceneRefraction > 0.5) {
|
|
vec2 refractedUV = clamp(screenUV + offset, 0.0, 1.0);
|
|
vec3 sceneColor = texture(sceneTexture, refractedUV).rgb;
|
|
mixedColor = mix(baseColor, sceneColor, surfaceTransmittance);
|
|
}
|
|
|
|
float depth = 0.0;
|
|
if (pos.y < info.r) {
|
|
depth = clamp((info.r - pos.y) / max(poolHeight, 0.0001), 0.0, 1.0);
|
|
float atten = wallMode > 0.5 ? mix(0.95, 0.35, depth) : mix(0.98, 0.6, depth);
|
|
mixedColor *= atten;
|
|
}
|
|
|
|
float alpha = wallOpacity;
|
|
if (wallMode > 0.5 && pos.y < info.r) {
|
|
alpha = mix(wallOpacity * 0.6, min(1.0, wallOpacity + 0.5), depth);
|
|
}
|
|
|
|
fragColor = vec4(mixedColor, alpha);
|
|
}
|