2024-03-01 22:48:09 -05:00
|
|
|
float waterCaustics(vec3 worldPos, vec3 sunVec) {
|
|
|
|
|
|
|
|
vec3 projectedPos = worldPos - (sunVec/sunVec.y*worldPos.y);
|
|
|
|
vec2 pos = projectedPos.xz;
|
|
|
|
|
|
|
|
float heightSum = 0.0;
|
2024-03-02 18:03:05 -05:00
|
|
|
float movement = frameTimeCounter*0.035 * WATER_WAVE_SPEED;
|
2024-03-01 22:48:09 -05:00
|
|
|
// movement = 0.0;
|
2023-04-16 16:18:26 -04:00
|
|
|
|
|
|
|
float radiance = 2.39996;
|
2023-01-12 15:00:14 -05:00
|
|
|
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
|
2024-03-01 22:48:09 -05:00
|
|
|
|
|
|
|
vec2 wave_size[3] = vec2[](
|
2023-04-16 16:18:26 -04:00
|
|
|
vec2(48.,12.),
|
|
|
|
vec2(12.,48.),
|
2024-03-01 22:48:09 -05:00
|
|
|
vec2(32.,32.)
|
2023-01-12 15:00:14 -05:00
|
|
|
);
|
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float WavesLarge = max(texture2D(noisetex, pos / 600.0 ).b,0.1);
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2023-04-16 16:18:26 -04:00
|
|
|
for (int i = 0; i < 3; i++){
|
2024-03-01 22:48:09 -05:00
|
|
|
pos = rotationMatrix * pos;
|
|
|
|
heightSum += pow(abs(abs(texture2D(noisetex, pos / wave_size[i] + WavesLarge*0.5 + movement).b * 2.0 - 1.0) * 2.0 - 1.0), 2.0) ;
|
2023-01-12 15:00:14 -05:00
|
|
|
}
|
2023-10-23 17:15:56 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float FinalCaustics = exp((1.0 + 5.0 * pow(WavesLarge,0.5)) * (heightSum / 3.0 - 0.5));
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
return FinalCaustics;
|
|
|
|
}
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float getWaterHeightmap(vec2 posxz) {
|
|
|
|
|
|
|
|
vec2 pos = posxz;
|
|
|
|
float heightSum = 0.0;
|
2024-03-02 18:03:05 -05:00
|
|
|
float movement = frameTimeCounter*0.035 * WATER_WAVE_SPEED;
|
2024-03-01 22:48:09 -05:00
|
|
|
// movement = 0.0;
|
|
|
|
|
|
|
|
float radiance = 2.39996;
|
|
|
|
mat2 rotationMatrix = mat2(vec2(cos(radiance), -sin(radiance)), vec2(sin(radiance), cos(radiance)));
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
vec2 wave_size[3] = vec2[](
|
|
|
|
vec2(48.,12.),
|
|
|
|
vec2(12.,48.),
|
|
|
|
vec2(32.,32.)
|
|
|
|
);
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float WavesLarge = max(texture2D(noisetex, pos / 600.0 ).b,0.1);
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
for (int i = 0; i < 3; i++){
|
|
|
|
pos = rotationMatrix * pos;
|
|
|
|
heightSum += texture2D(noisetex, pos / wave_size[i] + WavesLarge*0.5 + movement).b;
|
|
|
|
}
|
2023-04-16 16:18:26 -04:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
return (heightSum / 60.0) * WavesLarge;
|
|
|
|
}
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
vec3 getWaveNormal(vec3 posxz, bool isLOD){
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
// vary the normal's "smooth" factor as distance changes, to avoid noise from too much details.
|
|
|
|
float range = pow(clamp(1.0 - length(posxz - cameraPosition)/(32*4),0.0,1.0),2.0);
|
|
|
|
float deltaPos = mix(0.5, 0.1, range);
|
2024-03-02 18:53:51 -05:00
|
|
|
float normalMult = 10.0 * WATER_WAVE_STRENGTH;
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
if(isLOD){
|
|
|
|
normalMult = mix(5.0, normalMult, range);
|
|
|
|
deltaPos = mix(0.9, deltaPos, range);
|
|
|
|
}
|
2024-03-12 17:16:30 -04:00
|
|
|
// added detail for snells window
|
|
|
|
// if(isEyeInWater == 1) deltaPos = 0.025;
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-02 18:53:51 -05:00
|
|
|
#ifdef HYPER_DETAILED_WAVES
|
|
|
|
deltaPos = 0.025;
|
|
|
|
#endif
|
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
vec2 coord = posxz.xz;// - posxz.y;
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float h0 = getWaterHeightmap(coord);
|
|
|
|
float h1 = getWaterHeightmap(coord + vec2(deltaPos,0.0));
|
|
|
|
float h3 = getWaterHeightmap(coord + vec2(0.0,deltaPos));
|
2023-01-12 15:00:14 -05:00
|
|
|
|
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
float xDelta = ((h1-h0)/deltaPos)*normalMult;
|
|
|
|
float yDelta = ((h3-h0)/deltaPos)*normalMult;
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
vec3 wave = normalize(vec3(xDelta,yDelta,1.0-pow(abs(xDelta+yDelta),2.0)));
|
2023-01-12 15:00:14 -05:00
|
|
|
|
2024-03-01 22:48:09 -05:00
|
|
|
return wave ;
|
2023-04-16 16:18:26 -04:00
|
|
|
}
|