@@ -77,16 +77,30 @@ void main(void){
7777const getEnvFragment = ( underwater : String ) => `
7878uniform vec3 light;
7979uniform sampler2D caustics;
80+ // TODO Make this a uniform
81+ const vec2 resolution = vec2(1024.);
8082
8183varying vec3 lightPosition;
8284varying vec3 worldPosition;
8385varying float v${ underwater } ;
8486
85- const float bias = 0.005 ;
87+ const float bias = 0.001 ;
8688
8789const vec3 underwaterColor = vec3(0.4, 0.9, 1.0);
8890const vec3 overwaterColor = vec3(1.);
8991
92+ float blur(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
93+ float intensity = 0.;
94+ vec2 off1 = vec2(1.3846153846) * direction;
95+ vec2 off2 = vec2(3.2307692308) * direction;
96+ intensity += texture2D(image, uv).x * 0.2270270270;
97+ intensity += texture2D(image, uv + (off1 / resolution)).x * 0.3162162162;
98+ intensity += texture2D(image, uv - (off1 / resolution)).x * 0.3162162162;
99+ intensity += texture2D(image, uv + (off2 / resolution)).x * 0.0702702703;
100+ intensity += texture2D(image, uv - (off2 / resolution)).x * 0.0702702703;
101+ return intensity;
102+ }
103+
90104
91105void main() {
92106 // Compute flat shading normal (inefficient, should be computed on CPU once)
@@ -104,9 +118,13 @@ void main() {
104118 if (v${ underwater } > 0.) {
105119 // Retrieve caustics information
106120 vec2 causticsInfo = texture2D(caustics, lightPosition.xy).zw;
107- float causticsIntensity = causticsInfo.x;
108121 float causticsDepth = causticsInfo.y;
109122
123+ float causticsIntensity = 0.5 * (
124+ blur(caustics, lightPosition.xy, resolution, vec2(0., 0.5)) +
125+ blur(caustics, lightPosition.xy, resolution, vec2(0.5, 0.))
126+ );
127+
110128 if (causticsDepth > lightPosition.z - bias) {
111129 computedLightIntensity += causticsIntensity;
112130 }
@@ -229,7 +247,7 @@ class UnderWater extends Effect {
229247 return 1 ;
230248 }
231249
232- static readonly envMapSize : number = 256 ;
250+ static readonly envMapSize : number = 1024 ;
233251 static envMappingTarget : THREE . WebGLRenderTarget = new THREE . WebGLRenderTarget ( UnderWater . envMapSize , UnderWater . envMapSize , { type : THREE . FloatType } ) ;
234252 private envMappingMaterial : THREE . ShaderMaterial ;
235253 private envMappingMeshes : THREE . Mesh [ ] ;
0 commit comments