-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathskunami.min.js
121 lines (121 loc) · 61.1 KB
/
skunami.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
var SKUNAMI=SKUNAMI||{version:"1.0.2"};console.log("Using SKUNAMI "+SKUNAMI.version);
SKUNAMI.GpuHeightFieldWater=function(a){if("undefined"===typeof a.mesh)throw Error("mesh not specified");this.__mesh=a.mesh;if("undefined"===typeof a.renderer)throw Error("renderer not specified");this.__renderer=a.renderer;if("undefined"===typeof a.size)throw Error("size not specified");this.__size=a.size;if("undefined"===typeof a.scene)throw Error("scene not specified");this.__scene=a.scene;if("undefined"===typeof a.res)throw Error("res not specified");this.__res=a.res;if("undefined"===typeof a.dampingFactor)throw Error("dampingFactor not specified");
this.__dampingFactor=a.dampingFactor;this.__multisteps=a.multisteps||1;this.__shouldDisplayObstaclesTexture=this.__shouldDisplayWaterTexture=!1;this.__gravity=9.81;this.__density=a.density||1E3;this.__halfSize=this.__size/2;this.__segmentSize=this.__size/this.__res;this.__segmentSizeSquared=this.__segmentSize*this.__segmentSize;this.__texelSize=1/this.__res;this.__isDisturbing=this.__disturbMapHasUpdated=!1;this.__disturbUvPos=new THREE.Vector2;this.__disturbAmount=0;this.__disturbRadius=0.0025*this.__size;
this.__linearFloatRgbaParams={minFilter:THREE.LinearFilter,magFilter:THREE.LinearFilter,wrapS:THREE.ClampToEdgeWrapping,wrapT:THREE.ClampToEdgeWrapping,format:THREE.RGBAFormat,stencilBuffer:!1,depthBuffer:!1,type:THREE.FloatType};this.__nearestFloatRgbaParams={minFilter:THREE.NearestFilter,magFilter:THREE.NearestFilter,wrapS:THREE.ClampToEdgeWrapping,wrapT:THREE.ClampToEdgeWrapping,format:THREE.RGBAFormat,stencilBuffer:!1,depthBuffer:!1,type:THREE.FloatType};this.__boundaryData=new Float32Array(4*
this.__res*this.__res);this.__rttObstaclesCameraRange=50;this.__pixelByteData=new Uint8Array(4*this.__res*this.__res);this.__staticObstacles=[];this.__dynObstacles=[];this.__shouldUpdateStaticObstacle=!1;this.__callbacks={};this.__initCounter=5;this.__init();this.__setupObstaclesScene()};SKUNAMI.GpuHeightFieldWater.prototype.getShouldDisplayWaterTexture=function(){return this.__shouldDisplayWaterTexture};
SKUNAMI.GpuHeightFieldWater.prototype.setShouldDisplayWaterTexture=function(a){this.__shouldDisplayWaterTexture=a};SKUNAMI.GpuHeightFieldWater.prototype.getShouldDisplayObstaclesTexture=function(){return this.__shouldDisplayObstaclesTexture};SKUNAMI.GpuHeightFieldWater.prototype.setShouldDisplayObstaclesTexture=function(a){this.__shouldDisplayObstaclesTexture=a};
SKUNAMI.GpuHeightFieldWater.prototype.__init=function(){this.__checkExtensions();this.__setupRttScene();this.__resetMaterial=new THREE.ShaderMaterial({uniforms:{uColor:{type:"v4",value:new THREE.Vector4}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.setColor});this.__emptyTexture=this.__supportsTextureFloatLinear?new THREE.WebGLRenderTarget(this.__res,this.__res,this.__linearFloatRgbaParams):new THREE.WebGLRenderTarget(this.__res,this.__res,this.__nearestFloatRgbaParams);
this.__emptyTexture.generateMipmaps=!1;this.__clearRenderTarget(this.__emptyTexture,0,0,0,0);this.__supportsTextureFloatLinear?(this.__boundaryTexture=new THREE.DataTexture(null,this.__res,this.__res,THREE.RGBAFormat,THREE.FloatType),this.__boundaryTexture.generateMipmaps=!0):(this.__boundaryTexture=new THREE.DataTexture(null,this.__res,this.__res,THREE.RGBAFormat,THREE.FloatType,void 0,THREE.ClampToEdgeWrapping,THREE.ClampToEdgeWrapping,THREE.NearestFilter,THREE.NearestFilter),this.__boundaryTexture.generateMipmaps=
!1);this.__initDataAndTextures();this.__setupRttRenderTargets();this.__setupShaders();this.__setupVtf();this.__pr=new SKPR.ParallelReducer(this.__renderer,this.__res,1)};SKUNAMI.GpuHeightFieldWater.prototype.__getWaterFragmentShaderContent=function(){throw Error("Abstract method not implemented");};
SKUNAMI.GpuHeightFieldWater.prototype.__shaders={vert:{pass:"void main() {\ngl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}",passUv:"varying vec2 vUv;\nvoid main() {\nvUv = vec2(uv.x, uv.y);\ngl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}",heightMap:["uniform sampler2D uTexture;\nuniform vec2 uTexelSize;\nuniform vec2 uTexelWorldSize;\nuniform float uHeightMultiplier;\nvarying vec3 vViewPos;\nvarying vec3 vViewNormal;\nvarying vec2 vUv;",THREE.ShaderChunk.shadowmap_pars_vertex,
"void main() {\nvUv = uv;\nvec4 t = texture2D(uTexture, vUv) * uHeightMultiplier;\nvec3 displacedPos = vec3(position.x, t.r, position.z);\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nvec3 vecPosU = vec3(displacedPos.x + uTexelWorldSize.r,\ntexture2D(uTexture, vUv + du).r * uHeightMultiplier,\ndisplacedPos.z) - displacedPos;\nvec3 vecNegU = vec3(displacedPos.x - uTexelWorldSize.r,\ntexture2D(uTexture, vUv - du).r * uHeightMultiplier,\ndisplacedPos.z) - displacedPos;\nvec3 vecPosV = vec3(displacedPos.x,\ntexture2D(uTexture, vUv + dv).r * uHeightMultiplier,\ndisplacedPos.z - uTexelWorldSize.g) - displacedPos;\nvec3 vecNegV = vec3(displacedPos.x,\ntexture2D(uTexture, vUv - dv).r * uHeightMultiplier,\ndisplacedPos.z + uTexelWorldSize.g) - displacedPos;\nvViewNormal = normalize(normalMatrix * 0.25 * (cross(vecPosU, vecPosV) + cross(vecPosV, vecNegU) + cross(vecNegU, vecNegV) + cross(vecNegV, vecPosU)));\nvec4 worldPosition = modelMatrix * vec4(displacedPos, 1.0);\nvec4 viewPos = modelViewMatrix * vec4(displacedPos, 1.0);\nvViewPos = viewPos.rgb;\ngl_Position = projectionMatrix * viewPos;",
THREE.ShaderChunk.shadowmap_vertex,"}"].join("\n")},frag:{lambert:["uniform vec3 uBaseColor;\nuniform vec3 uAmbientLightColor;\nuniform float uAmbientLightIntensity;\nvarying vec3 vViewPos;\nvarying vec3 vViewNormal;\nvarying vec2 vUv;\n#if MAX_DIR_LIGHTS > 0\nuniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\nuniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n#endif",THREE.ShaderChunk.shadowmap_pars_fragment,"void main() {\nvec3 ambient = uAmbientLightColor * uAmbientLightIntensity;\nvec3 diffuse = vec3(0.0);\n#if MAX_DIR_LIGHTS > 0\nfor (int i = 0; i < MAX_DIR_LIGHTS; i++) {\nvec4 lightVector = viewMatrix * vec4(directionalLightDirection[i], 0.0);\nfloat normalModulator = dot(normalize(vViewNormal), normalize(lightVector.xyz));\ndiffuse += normalModulator * directionalLightColor[i];\n}\n#endif\ngl_FragColor = vec4(uBaseColor * (ambient + diffuse), 1.0);",
THREE.ShaderChunk.shadowmap_fragment,"}"].join("\n"),hfWater_disturb:"uniform sampler2D uTexture;\nuniform sampler2D uStaticObstaclesTexture;\nuniform sampler2D uDisturbTexture;\nuniform int uUseObstacleTexture;\nuniform int uIsDisturbing;\nuniform float uDisturbAmount;\nuniform float uDisturbRadius;\nuniform vec2 uDisturbPos;\nuniform int uIsSourcing;\nuniform float uSourceAmount;\nuniform float uSourceRadius;\nuniform vec2 uSourcePos;\nuniform int uIsFlooding;\nuniform float uFloodAmount;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\nfloat inObstacle;\nif (uUseObstacleTexture == 1) {\nvec4 tObstacles = texture2D(uStaticObstaclesTexture, vUv);\ninObstacle = tObstacles.r;\n} else {\ninObstacle = float(t.r < 0.0);\n}\nif (uIsDisturbing == 1) {\nfloat len = length(vUv - vec2(uDisturbPos.x, 1.0 - uDisturbPos.y));\nt.r += uDisturbAmount * (1.0 - smoothstep(0.0, uDisturbRadius, len)) * (1.0 - inObstacle);\n}\nif (uIsSourcing == 1) {\nfloat len = length(vUv - vec2(uSourcePos.x, 1.0 - uSourcePos.y));\nt.r += uSourceAmount * (1.0 - smoothstep(0.0, uSourceRadius, len));\n}\nvec4 tDisturb = texture2D(uDisturbTexture, vUv);\nt.r += tDisturb.r;\nif (uIsFlooding == 1) {\nt.r += uFloodAmount;\n}\ngl_FragColor = t;\n}",
hfWater_muellerGdc2008:"uniform sampler2D uTexture;\nuniform vec2 uTexelSize;\nuniform vec2 uTexelWorldSize;\nuniform float uDampingFactor;\nuniform float uHorizontalSpeed;\nuniform float uDt;\nuniform float uMeanHeight;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\nt.r -= t.a;\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nfloat acc = uHorizontalSpeed * uHorizontalSpeed * (\ntexture2D(uTexture,vUv+du).r\n+ texture2D(uTexture,vUv-du).r\n+ texture2D(uTexture,vUv+dv).r\n+ texture2D(uTexture,vUv-dv).r\n- 4.0 * t.a - 4.0 * t.r) / (uTexelWorldSize.x * uTexelWorldSize.x);\nt.g += acc * uDt;\nt.g *= uDampingFactor;\nt.r += t.g * uDt;\nt.r += uMeanHeight;\nt.a = uMeanHeight;\ngl_FragColor = t;\n}",
hfWater_muellerGdc2008Hw:"uniform sampler2D uTexture;\nuniform vec2 uTexelSize;\nuniform float uDampingFactor;\nuniform float uMeanHeight;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\nt.r -= t.a;\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nt.g += 0.25 * (texture2D(uTexture,vUv+du).r\n+ texture2D(uTexture,vUv-du).r\n+ texture2D(uTexture,vUv+dv).r\n+ texture2D(uTexture,vUv-dv).r - 4.0 * t.a) - t.r;\nt.g *= uDampingFactor;\nt.r += t.g;\nt.r += uMeanHeight;\nt.a = uMeanHeight;\ngl_FragColor = t;\n}",
hfWater_xWater:"uniform sampler2D uTexture;\nuniform vec2 uTexelSize;\nuniform float uDampingFactor;\nuniform float uMeanHeight;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\nt.r -= t.a;\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nt.b = 0.5 * (texture2D(uTexture,vUv+du).r\n+ texture2D(uTexture,vUv-du).r\n+ texture2D(uTexture,vUv+dv).r\n+ texture2D(uTexture,vUv-dv).r - 4.0 * t.a) - t.b;\nt.b *= uDampingFactor;\nt.r = t.b;\nt.r += uMeanHeight;\nt.a = uMeanHeight;\nfloat temp = t.g;\nt.g = t.b;\nt.b = temp;\ngl_FragColor = t;\n}",
hfWater_tessendorfIWave_convolve:"#define KERNEL_RADIUS 2\n#define KERNEL_WIDTH (2 * (KERNEL_RADIUS) + 1)\nuniform sampler2D uWaterTexture;\nuniform vec2 uTexelSize;\nuniform float uKernel[KERNEL_WIDTH * KERNEL_WIDTH];\nvarying vec2 vUv;\nvoid main() {\nvec4 tWater = texture2D(uWaterTexture, vUv);\ntWater.b = 0.0;\nfloat fk, fl;\nvec4 tWaterNeighbour;\nfor (int k = -KERNEL_RADIUS; k <= KERNEL_RADIUS; k++) {\nfk = float(k);\nfor (int l = -KERNEL_RADIUS; l <= KERNEL_RADIUS; l++) {\nfl = float(l);\ntWaterNeighbour = texture2D(uWaterTexture, vec2(vUv.r + fk * uTexelSize.r, vUv.g + fl * uTexelSize.g));\ntWater.b += uKernel[(k + KERNEL_RADIUS) * KERNEL_WIDTH + (l + KERNEL_RADIUS)] * (tWaterNeighbour.r - tWaterNeighbour.a);\n}\n}\ngl_FragColor = tWater;\n}",
hfWater_tessendorfIWave:"uniform sampler2D uWaterTexture;\nuniform float uTwoMinusDampTimesDt;\nuniform float uOnePlusDampTimesDt;\nuniform float uGravityTimesDtTimesDt;\nuniform float uMeanHeight;\nvarying vec2 vUv;\nvoid main() {\nvec4 tWater = texture2D(uWaterTexture, vUv);\ntWater.r -= tWater.a;\nfloat temp = tWater.r;\ntWater.r = (tWater.r * uTwoMinusDampTimesDt\n- tWater.g\n- tWater.b * uGravityTimesDtTimesDt) / uOnePlusDampTimesDt;\ntWater.g = temp;\ntWater.r += uMeanHeight;\ntWater.a = uMeanHeight;\ngl_FragColor = tWater;\n}",
hfWater_pipeModel_calcFlux:"uniform sampler2D uTerrainTexture;\nuniform sampler2D uWaterTexture;\nuniform sampler2D uFluxTexture;\nuniform sampler2D uStaticObstaclesTexture;\nuniform sampler2D uBoundaryTexture;\nuniform vec2 uTexelSize;\nuniform float uDampingFactor;\nuniform float uHeightToFluxFactor;\nuniform float uSegmentSizeSquared;\nuniform float uDt;\nuniform float uMinWaterHeight;\nvarying vec2 vUv;\nvoid main() {\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nvec4 tTerrain = texture2D(uTerrainTexture, vUv);\nvec4 tWater = texture2D(uWaterTexture, vUv);\nvec4 tObstacle = texture2D(uStaticObstaclesTexture, vUv);\nfloat waterHeight = tWater.r;\nfloat totalHeight = max(tTerrain.r, tObstacle.r) + waterHeight;\nvec4 tFlux = texture2D(uFluxTexture, vUv);\ntFlux *= uDampingFactor;\nvec4 neighbourTotalHeights = vec4(texture2D(uWaterTexture, vUv + du).r + max(texture2D(uTerrainTexture, vUv + du).r, texture2D(uStaticObstaclesTexture, vUv + du).r),\ntexture2D(uWaterTexture, vUv - du).r + max(texture2D(uTerrainTexture, vUv - du).r, texture2D(uStaticObstaclesTexture, vUv - du).r),\ntexture2D(uWaterTexture, vUv - dv).r + max(texture2D(uTerrainTexture, vUv - dv).r, texture2D(uStaticObstaclesTexture, vUv - dv).r),\ntexture2D(uWaterTexture, vUv + dv).r + max(texture2D(uTerrainTexture, vUv + dv).r, texture2D(uStaticObstaclesTexture, vUv + dv).r));\ntFlux += (totalHeight - neighbourTotalHeights) * uHeightToFluxFactor;\ntFlux = max(vec4(0.0), tFlux);\nvec4 tBoundary = texture2D(uBoundaryTexture, vUv);\ntFlux *= tBoundary;\nfloat currVol = (waterHeight - uMinWaterHeight) * uSegmentSizeSquared;\nfloat outVol = uDt * (tFlux.r + tFlux.g + tFlux.b + tFlux.a);\ntFlux *= min(1.0, currVol / outVol);\ngl_FragColor = tFlux;\n}",
hfWater_pipeModel:"uniform sampler2D uWaterTexture;\nuniform sampler2D uFluxTexture;\nuniform vec2 uTexelSize;\nuniform float uSegmentSize;\nuniform float uDt;\nuniform float uMinWaterHeight;\nvarying vec2 vUv;\nvoid main() {\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nvec4 tWater = texture2D(uWaterTexture, vUv);\nvec4 tFlux = texture2D(uFluxTexture, vUv);\nvec4 tFluxPixelLeft = texture2D(uFluxTexture, vUv-du);\nvec4 tFluxPixelRight = texture2D(uFluxTexture, vUv+du);\nvec4 tFluxPixelTop = texture2D(uFluxTexture, vUv+dv);\nvec4 tFluxPixelBottom = texture2D(uFluxTexture, vUv-dv);\nfloat avgWaterHeight = tWater.r;\nfloat fluxOut = tFlux.r + tFlux.g + tFlux.b + tFlux.a;\nfloat fluxIn = tFluxPixelLeft.r + tFluxPixelRight.g + tFluxPixelTop.b + tFluxPixelBottom.a;\ntWater.r += (fluxIn - fluxOut) * uDt / (uSegmentSize * uSegmentSize);\ntWater.r = max(uMinWaterHeight, tWater.r);\navgWaterHeight = 0.5 * (avgWaterHeight + tWater.r);\nif (avgWaterHeight == 0.0) {\ntWater.g = 0.0;\ntWater.b = 0.0;\n} else {\nfloat threshold = float(tWater.r > 0.2);\nfloat segmentSizeTimesAvgWaterHeight = uSegmentSize * avgWaterHeight;\ntWater.g = threshold * 0.5 * (tFluxPixelLeft.r - tFlux.g + tFlux.r - tFluxPixelRight.g) / segmentSizeTimesAvgWaterHeight;\ntWater.b = threshold * 0.5 * (tFluxPixelTop.b - tFlux.a + tFlux.b - tFluxPixelBottom.a) / segmentSizeTimesAvgWaterHeight;\n}\ngl_FragColor = tWater;\n}",
setColor:"uniform vec4 uColor;\nvoid main() {\ngl_FragColor = uColor;\n}",setColorMasked:"uniform sampler2D uTexture;\nuniform vec4 uColor;\nuniform vec4 uChannelMask;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\ngl_FragColor = (vec4(1.0) - uChannelMask) * t + uChannelMask * uColor;\n}",setSolidAlpha:"uniform sampler2D uTexture;\nvarying vec2 vUv;\nvoid main() {\ngl_FragColor = vec4(texture2D(uTexture, vUv).rgb, 1.0);\n}",hfWater_obstacles_static:"uniform sampler2D uObstacleTopTexture;\nuniform float uHalfRange;\nvarying vec2 vUv;\nvoid main() {\nvec4 tTop = texture2D(uObstacleTopTexture, vUv);\nfloat topHeight = (uHalfRange - tTop.r) * tTop.a;\ngl_FragColor = vec4(topHeight, 0.0, 0.0, 1.0);\n}",
hfWater_obstacles_dynamic:"uniform sampler2D uObstaclesTexture;\nuniform sampler2D uObstacleTopTexture;\nuniform sampler2D uObstacleBottomTexture;\nuniform sampler2D uWaterTexture;\nuniform sampler2D uTerrainTexture;\nuniform float uHalfRange;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uObstaclesTexture, vUv);\nvec4 tTop = texture2D(uObstacleTopTexture, vUv);\nvec4 tBottom = texture2D(uObstacleBottomTexture, vec2(vUv.x, 1.0-vUv.y));\nvec4 tWater = texture2D(uWaterTexture, vUv);\nvec4 tTerrain = texture2D(uTerrainTexture, vUv);\nfloat waterHeight = tWater.r + tTerrain.r;\nfloat bottomHeight = (tBottom.r - uHalfRange - waterHeight) * tBottom.a;\nfloat topHeight = (uHalfRange - waterHeight - tTop.r) * tTop.a;\nbool inObstacle = bottomHeight < 0.0 && topHeight > 0.0;\nfloat displacedHeight;\nif (bottomHeight > 0.0) {\ndisplacedHeight = 0.0;\n} else if (topHeight < 0.0) {\ndisplacedHeight = topHeight - bottomHeight;\n} else {\ndisplacedHeight = -bottomHeight;\n}\ngl_FragColor = vec4(max(t.r, float(inObstacle)), t.g + displacedHeight, t.b, displacedHeight);\n}",
encodeFloat:"uniform sampler2D uTexture;\nuniform vec4 uChannelMask;\nvarying vec2 vUv;\nfloat shift_right(float v, float amt) {\nv = floor(v) + 0.5;\nreturn floor(v / exp2(amt));\n}\nfloat shift_left(float v, float amt) {\nreturn floor(v * exp2(amt) + 0.5);\n}\nfloat mask_last(float v, float bits) {\nreturn mod(v, shift_left(1.0, bits));\n}\nfloat extract_bits(float num, float from, float to) {\nfrom = floor(from + 0.5);\nto = floor(to + 0.5);\nreturn mask_last(shift_right(num, from), to - from);\n}\nvec4 encode_float(float val) {\nif (val == 0.0) {\nreturn vec4(0.0, 0.0, 0.0, 0.0);\n}\nfloat sign = val > 0.0 ? 0.0 : 1.0;\nval = abs(val);\nfloat exponent = floor(log2(val));\nfloat biased_exponent = exponent + 127.0;\nfloat fraction = ((val / exp2(exponent)) - 1.0) * 8388608.0;\nfloat t = biased_exponent / 2.0;\nfloat last_bit_of_biased_exponent = fract(t) * 2.0;\nfloat remaining_bits_of_biased_exponent = floor(t);\nfloat byte4 = extract_bits(fraction, 0.0, 8.0) / 255.0;\nfloat byte3 = extract_bits(fraction, 8.0, 16.0) / 255.0;\nfloat byte2 = (last_bit_of_biased_exponent * 128.0 + extract_bits(fraction, 16.0, 23.0)) / 255.0;\nfloat byte1 = (sign * 128.0 + remaining_bits_of_biased_exponent) / 255.0;\nreturn vec4(byte4, byte3, byte2, byte1);\n}\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\ngl_FragColor = encode_float(dot(t, uChannelMask));\n}",
copyChannels:"uniform sampler2D uTexture;\nuniform vec4 uOriginChannelId;\nuniform vec4 uDestChannelId;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = texture2D(uTexture, vUv);\nfloat data = dot(t, uOriginChannelId);\ngl_FragColor = (vec4(1.0) - uDestChannelId) * t + uDestChannelId * data;\n}",hfWater_calcDisturbMap:"uniform sampler2D uTexture;\nuniform vec2 uTexelSize;\nvarying vec2 vUv;\nvoid main() {\nvec2 du = vec2(uTexelSize.r, 0.0);\nvec2 dv = vec2(0.0, uTexelSize.g);\nvec4 tLeft = texture2D(uTexture, vUv-du);\nvec4 tRight = texture2D(uTexture, vUv+du);\nvec4 tTop = texture2D(uTexture, vUv+dv);\nvec4 tBottom = texture2D(uTexture, vUv-dv);\nfloat result = 0.25 * ( (tLeft.g-tLeft.b) + (tRight.g-tRight.b) + (tTop.g-tTop.b) + (tBottom.g-tBottom.b) );\ngl_FragColor = vec4(result, -result, 0.0, 1.0);\n}",
gaussianBlurX:"uniform sampler2D uTexture;\nuniform float uTexelSize;\nvarying vec2 vUv;\nvoid main() {\nvec4 sum = vec4(0.0);\nsum += texture2D(uTexture, vec2(vUv.x - 4.0 * uTexelSize, vUv.y)) * 0.05;\nsum += texture2D(uTexture, vec2(vUv.x - 3.0 * uTexelSize, vUv.y)) * 0.09;\nsum += texture2D(uTexture, vec2(vUv.x - 2.0 * uTexelSize, vUv.y)) * 0.12;\nsum += texture2D(uTexture, vec2(vUv.x - uTexelSize, vUv.y)) * 0.15;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y)) * 0.16;\nsum += texture2D(uTexture, vec2(vUv.x + uTexelSize, vUv.y)) * 0.15;\nsum += texture2D(uTexture, vec2(vUv.x + 2.0 * uTexelSize, vUv.y)) * 0.12;\nsum += texture2D(uTexture, vec2(vUv.x + 3.0 * uTexelSize, vUv.y)) * 0.09;\nsum += texture2D(uTexture, vec2(vUv.x + 4.0 * uTexelSize, vUv.y)) * 0.05;\ngl_FragColor = sum;\n}",
gaussianBlurY:"uniform sampler2D uTexture;\nuniform float uTexelSize;\nvarying vec2 vUv;\nvoid main() {\nvec4 sum = vec4(0.0);\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y - 4.0 * uTexelSize)) * 0.05;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y - 3.0 * uTexelSize)) * 0.09;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y - 2.0 * uTexelSize)) * 0.12;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y - uTexelSize)) * 0.15;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y)) * 0.16;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y + uTexelSize)) * 0.15;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y + 2.0 * uTexelSize)) * 0.12;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y + 3.0 * uTexelSize)) * 0.09;\nsum += texture2D(uTexture, vec2(vUv.x, vUv.y + 4.0 * uTexelSize)) * 0.05;\ngl_FragColor = sum;\n}",
combineTextures:"uniform sampler2D uTexture1;\nuniform sampler2D uTexture2;\nvarying vec2 vUv;\nvoid main() {\ngl_FragColor = texture2D(uTexture1, vUv) + texture2D(uTexture2, vUv);\n}",combineTexturesMask:"uniform sampler2D uTexture1;\nuniform sampler2D uTexture2;\nvarying vec2 vUv;\nvoid main() {\nvec4 t1 = texture2D(uTexture1, vUv);\nvec4 t2 = texture2D(uTexture2, vUv);\nt1 *= t2.a;\ngl_FragColor = t1;\n}",erode:"uniform sampler2D uTexture;\nuniform float uTexelSize;\nvarying vec2 vUv;\nvoid main() {\nvec2 du = vec2(uTexelSize, 0.0);\nvec2 dv = vec2(0.0, uTexelSize);\nfloat curr = texture2D(uTexture, vUv).r;\nfloat right = texture2D(uTexture, vUv + du).r;\nfloat left = texture2D(uTexture, vUv - du).r;\nfloat bottom = texture2D(uTexture, vUv - dv).r;\nfloat top = texture2D(uTexture, vUv + dv).r;\nfloat result = min(curr, min(right, min(left, min(bottom, top))));\ngl_FragColor = vec4(result, 0.0, 0.0, 1.0);\n}",
depth:"uniform float uNear;\nuniform float uFar;\nvoid main() {\nfloat color = mix(uFar, uNear, gl_FragCoord.z/gl_FragCoord.w);\ngl_FragColor = vec4(vec3(color), 1.0);\n}",hfWater_pipeModel_calcFinalWaterHeight:"uniform sampler2D uTerrainTexture;\nuniform sampler2D uStaticObstaclesTexture;\nuniform sampler2D uWaterTexture;\nuniform sampler2D uMultiplyTexture;\nuniform float uMaskOffset;\nvarying vec2 vUv;\nvoid main() {\nvec4 t = max(texture2D(uTerrainTexture, vUv), texture2D(uStaticObstaclesTexture, vUv)) + texture2D(uWaterTexture, vUv);\nvec4 tMultiply = texture2D(uMultiplyTexture, vUv);\nt *= tMultiply;\nt += (1.0 - tMultiply) * uMaskOffset;\ngl_FragColor = t;\n}"}};
SKUNAMI.GpuHeightFieldWater.prototype.__setupShaders=function(){this.__disturbAndSourceMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uStaticObstaclesTexture:{type:"t",value:this.__emptyTexture},uDisturbTexture:{type:"t",value:this.__emptyTexture},uUseObstacleTexture:{type:"i",value:1},uIsDisturbing:{type:"i",value:0},uDisturbPos:{type:"v2",value:new THREE.Vector2(0.5,0.5)},uDisturbAmount:{type:"f",value:this.__disturbAmount},uDisturbRadius:{type:"f",value:this.__disturbRadius},
uIsSourcing:{type:"i",value:0},uSourcePos:{type:"v2",value:new THREE.Vector2(0.5,0.5)},uSourceAmount:{type:"f",value:this.__sourceAmount},uSourceRadius:{type:"f",value:this.__sourceRadius},uIsFlooding:{type:"i",value:0},uFloodAmount:{type:"f",value:0}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_disturb});this.__waterSimMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,
this.__texelSize)},uTexelWorldSize:{type:"v2",value:new THREE.Vector2(this.__size/this.__res,this.__size/this.__res)},uDampingFactor:{type:"f",value:this.__dampingFactor},uDt:{type:"f",value:0},uMeanHeight:{type:"f",value:this.__meanHeight}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__getWaterFragmentShaderContent()});this.__resetMaskedMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uColor:{type:"v4",value:new THREE.Vector4},uChannelMask:{type:"v4",
value:new THREE.Vector4}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.setColorMasked});this.__setSolidAlphaMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.setSolidAlpha});this.__staticObstaclesMaterial=new THREE.ShaderMaterial({uniforms:{uObstacleTopTexture:{type:"t",value:this.__emptyTexture},uHalfRange:{type:"f",value:this.__rttObstaclesCameraRange/
2}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_obstacles_static});this.__dynObstaclesMaterial=new THREE.ShaderMaterial({uniforms:{uObstaclesTexture:{type:"t",value:this.__emptyTexture},uObstacleTopTexture:{type:"t",value:this.__emptyTexture},uObstacleBottomTexture:{type:"t",value:this.__emptyTexture},uWaterTexture:{type:"t",value:this.__emptyTexture},uTerrainTexture:{type:"t",value:this.__emptyTexture},uHalfRange:{type:"f",value:this.__rttObstaclesCameraRange/
2}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_obstacles_dynamic});this.__rttEncodeFloatMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uChannelMask:{type:"v4",value:new THREE.Vector4}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.encodeFloat});this.__copyChannelsMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uOriginChannelId:{type:"v4",value:new THREE.Vector4},
uDestChannelId:{type:"v4",value:new THREE.Vector4}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.copyChannels});this.__calcDisturbMapMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,this.__texelSize)}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_calcDisturbMap});this.__gaussianBlurXMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",
value:this.__emptyTexture},uTexelSize:{type:"f",value:this.__texelSize}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.gaussianBlurX});this.__gaussianBlurYMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"f",value:this.__texelSize}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.gaussianBlurY});this.__combineTexturesMaterial=new THREE.ShaderMaterial({uniforms:{uTexture1:{type:"t",value:this.__emptyTexture},
uTexture2:{type:"t",value:this.__emptyTexture}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.combineTextures});this.__erodeMaterial=new THREE.ShaderMaterial({uniforms:{uTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"f",value:this.__texelSize}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.erode});this.__channelVectors={r:new THREE.Vector4(1,0,0,0),g:new THREE.Vector4(0,1,0,0),b:new THREE.Vector4(0,0,1,0),a:new THREE.Vector4(0,
0,0,1)}};SKUNAMI.GpuHeightFieldWater.prototype.__setupRttScene=function(){this.__rttScene=new THREE.Scene;this.__rttCamera=new THREE.OrthographicCamera(-this.__halfSize,this.__halfSize,this.__halfSize,-this.__halfSize,-1E4,1E4);this.__rttQuadGeom=new THREE.PlaneGeometry(this.__size,this.__size);this.__rttQuadMesh=new THREE.Mesh(this.__rttQuadGeom,this.__waterSimMaterial);this.__rttScene.add(this.__rttQuadMesh)};
SKUNAMI.GpuHeightFieldWater.prototype.__setupRttRenderTargets=function(){this.__rttRenderTarget1=this.__supportsTextureFloatLinear?new THREE.WebGLRenderTarget(this.__res,this.__res,this.__linearFloatRgbaParams):new THREE.WebGLRenderTarget(this.__res,this.__res,this.__nearestFloatRgbaParams);this.__rttRenderTarget1.generateMipmaps=!1;this.__clearRenderTarget(this.__rttRenderTarget1,0,0,0,0);this.__rttRenderTarget2=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttRenderTarget2,0,0,
0,0);this.__rttWaterDisplay=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttWaterDisplay,0,0,0,1);this.__rttObstaclesDisplay=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttObstaclesDisplay,0,0,0,1);this.__rttFloatEncoderRenderTarget=new THREE.WebGLRenderTarget(this.__res,this.__res,this.__nearestFloatRgbaParams);this.__rttFloatEncoderRenderTarget.generateMipmaps=!1;this.__clearRenderTarget(this.__rttFloatEncoderRenderTarget,0,0,0,0);this.__rttCombinedHeightsBlurredRenderTarget=
this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttCombinedHeightsBlurredRenderTarget,0,0,0,0);this.__rttDynObstaclesBlurredRenderTarget=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttDynObstaclesBlurredRenderTarget,0,0,0,0);this.__rttDisturbMapRenderTarget=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttDisturbMapRenderTarget,0,0,0,0)};
SKUNAMI.GpuHeightFieldWater.prototype.__clearRenderTarget=function(a,b,c,e,d){this.__rttQuadMesh.material=this.__resetMaterial;this.__resetMaterial.uniforms.uColor.value.set(b,c,e,d);this.__renderer.render(this.__rttScene,this.__rttCamera,a,!1)};
SKUNAMI.GpuHeightFieldWater.prototype.__setupVtf=function(){this.__mesh.material=new THREE.ShaderMaterial({uniforms:THREE.UniformsUtils.merge([THREE.UniformsLib.lights,THREE.UniformsLib.shadowmap,{uTexture:{type:"t",value:this.__rttRenderTarget1},uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,this.__texelSize)},uTexelWorldSize:{type:"v2",value:new THREE.Vector2(this.__segmentSize,this.__segmentSize)},uHeightMultiplier:{type:"f",value:1},uBaseColor:{type:"v3",value:new THREE.Vector3(0.45,
0.95,1)}}]),vertexShader:this.__shaders.vert.heightMap,fragmentShader:this.__shaders.frag.lambert,lights:!0})};
SKUNAMI.GpuHeightFieldWater.prototype.__checkExtensions=function(a){a=this.__renderer.context;if(!a.getExtension("OES_texture_float"))throw a="No support for floating point textures. Extension not available: OES_texture_float",alert(a),Error(a);this.__supportsTextureFloatLinear=null!==a.getExtension("OES_texture_float_linear");console.log("Texture float linear filtering support: "+this.__supportsTextureFloatLinear);if(!a.getParameter(a.MAX_VERTEX_TEXTURE_IMAGE_UNITS))throw a="Vertex textures not supported on your graphics card",
alert(a),Error(a);};
SKUNAMI.GpuHeightFieldWater.prototype.__initDataAndTextures=function(){var a,b,c;a=0;for(b=this.__boundaryData.length;a<b;a++)this.__boundaryData[a]=1;for(a=b=0;a<this.__res;a++)c=4*(a+this.__res*b),this.__boundaryData[c]=0,this.__boundaryData[c+1]=0,this.__boundaryData[c+2]=0,this.__boundaryData[c+3]=0;b=this.__res-1;for(a=0;a<this.__res;a++)c=4*(a+this.__res*b),this.__boundaryData[c]=0,this.__boundaryData[c+1]=0,this.__boundaryData[c+2]=0,this.__boundaryData[c+3]=0;for(b=a=0;b<this.__res;b++)c=
4*(a+this.__res*b),this.__boundaryData[c]=0,this.__boundaryData[c+1]=0,this.__boundaryData[c+2]=0,this.__boundaryData[c+3]=0;a=this.__res-1;for(b=0;b<this.__res;b++)c=4*(a+this.__res*b),this.__boundaryData[c]=0,this.__boundaryData[c+1]=0,this.__boundaryData[c+2]=0,this.__boundaryData[c+3]=0;this.__boundaryTexture.image.data=this.__boundaryData;this.__boundaryTexture.needsUpdate=!0};
SKUNAMI.GpuHeightFieldWater.prototype.__setupObstaclesScene=function(){this.__rttObstaclesTopCamera=new THREE.OrthographicCamera(-this.__halfSize,this.__halfSize,-this.__halfSize,this.__halfSize,0,this.__rttObstaclesCameraRange);this.__rttObstaclesTopCamera.position.y=-this.__rttObstaclesCameraRange/2;this.__rttObstaclesTopCamera.rotation.x=THREE.Math.degToRad(90);this.__rttObstaclesBottomCamera=new THREE.OrthographicCamera(-this.__halfSize,this.__halfSize,-this.__halfSize,this.__halfSize,0,this.__rttObstaclesCameraRange);
this.__rttObstaclesBottomCamera.position.y=this.__rttObstaclesCameraRange/2;this.__rttObstaclesBottomCamera.rotation.x=THREE.Math.degToRad(-90);this.__rttStaticObstaclesRenderTarget=this.__rttRenderTarget1.clone();this.__rttDynObstaclesRenderTarget=this.__rttRenderTarget1.clone();this.__rttObstacleTopRenderTarget=this.__rttRenderTarget1.clone();this.__rttObstacleBottomRenderTarget=this.__rttRenderTarget1.clone();this.__rttMaskedWaterRenderTarget=this.__rttRenderTarget1.clone();this.__rttObstaclesDepthMaterial=
new THREE.ShaderMaterial({uniforms:{uNear:{type:"f",value:0},uFar:{type:"f",value:this.__rttObstaclesCameraRange}},vertexShader:this.__shaders.vert.pass,fragmentShader:this.__shaders.frag.depth});this.__maskWaterMaterial=new THREE.ShaderMaterial({uniforms:{uTexture1:{type:"t",value:this.__emptyTexture},uTexture2:{type:"t",value:this.__emptyTexture}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.combineTexturesMask})};
SKUNAMI.GpuHeightFieldWater.prototype.reset=function(){this.__initCounter=5};SKUNAMI.GpuHeightFieldWater.prototype.__resetPass=function(){this.__clearRenderTarget(this.__rttRenderTarget2,this.__meanHeight,0,0,this.__meanHeight);this.__swapRenderTargets()};SKUNAMI.GpuHeightFieldWater.prototype.disturb=function(a,b,c){this.__isDisturbing=!0;this.__disturbUvPos.x=(a.x+this.__halfSize)/this.__size;this.__disturbUvPos.y=(a.z+this.__halfSize)/this.__size;this.__disturbAmount=b;this.__disturbRadius=c};
SKUNAMI.GpuHeightFieldWater.prototype.flood=function(a){throw Error("Abstract method not implemented");};
SKUNAMI.GpuHeightFieldWater.prototype.__disturbPass=function(){var a=!1;this.__disturbMapHasUpdated&&(this.__disturbAndSourceMaterial.uniforms.uDisturbTexture.value=this.__rttDisturbMapRenderTarget,a=!0);this.__isDisturbing&&0!==this.__disturbAmount&&(this.__disturbAndSourceMaterial.uniforms.uIsDisturbing.value=this.__isDisturbing,this.__disturbAndSourceMaterial.uniforms.uDisturbPos.value.copy(this.__disturbUvPos),this.__disturbAndSourceMaterial.uniforms.uDisturbAmount.value=this.__disturbAmount,
this.__disturbAndSourceMaterial.uniforms.uDisturbRadius.value=this.__disturbRadius/this.__size,a=!0);a&&(this.__rttQuadMesh.material=this.__disturbAndSourceMaterial,this.__disturbAndSourceMaterial.uniforms.uTexture.value=this.__rttRenderTarget2,this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1),this.__swapRenderTargets(),this.__isDisturbing=!1,this.__rttQuadMesh.material.uniforms.uIsDisturbing.value=!1)};
SKUNAMI.GpuHeightFieldWater.prototype.__waterSimPass=function(a){this.__rttQuadMesh.material=this.__waterSimMaterial;this.__waterSimMaterial.uniforms.uTexture.value=this.__rttRenderTarget2;this.__waterSimMaterial.uniforms.uDt.value=a;this.__waterSimMaterial.uniforms.uMeanHeight.value=this.__meanHeight;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1);this.__swapRenderTargets()};
SKUNAMI.GpuHeightFieldWater.prototype.__displayPass=function(){this.__shouldDisplayWaterTexture&&(this.__rttQuadMesh.material=this.__setSolidAlphaMaterial,this.__setSolidAlphaMaterial.uniforms.uTexture.value=this.__rttRenderTarget2,this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttWaterDisplay,!1),this.__swapRenderTargets());this.__shouldDisplayObstaclesTexture&&(this.__rttQuadMesh.material=this.__setSolidAlphaMaterial,this.__setSolidAlphaMaterial.uniforms.uTexture.value=this.__rttDynObstaclesBlurredRenderTarget,
this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttObstaclesDisplay,!1),this.__swapRenderTargets())};SKUNAMI.GpuHeightFieldWater.prototype.__calculateSubsteps=function(a){return 1};
SKUNAMI.GpuHeightFieldWater.prototype.update=function(a){if(0<this.__initCounter)this.__resetPass(),this.__initCounter-=1;else{a=1/60;this.__shouldUpdateStaticObstacle&&(this.__updateStaticObstacleTexture(a),this.__shouldUpdateStaticObstacle=!1);0<this.__dynObstacles.length&&this.__updateDynObstacleTexture(a);var b;for(b=0;b<this.__multisteps;b++)this.__step(a);this.__postStepPass();this.__displayPass()}};
SKUNAMI.GpuHeightFieldWater.prototype.__step=function(a){var b=this.__calculateSubsteps(a);a/=b;this.__disturbPass();var c;for(c=0;c<b;c++)this.__waterSimPass(a)};SKUNAMI.GpuHeightFieldWater.prototype.__postStepPass=function(){this.__mesh.material.uniforms.uTexture.value=this.__rttRenderTarget1};SKUNAMI.GpuHeightFieldWater.prototype.__swapRenderTargets=function(){var a=this.__rttRenderTarget1;this.__rttRenderTarget1=this.__rttRenderTarget2;this.__rttRenderTarget2=a};
SKUNAMI.GpuHeightFieldWater.prototype.addStaticObstacle=function(a){if(!(a instanceof THREE.Mesh))throw Error("mesh must be of type THREE.Mesh");a.__skunami||(a.__skunami={});a.__skunami.isObstacle=!0;a.__skunami.isDynamic=!1;a.__skunami.mass=0;this.__staticObstacles.push(a);this.__shouldUpdateStaticObstacle=!0};
SKUNAMI.GpuHeightFieldWater.prototype.addDynamicObstacle=function(a,b){if(!(a instanceof THREE.Mesh))throw Error("mesh must be of type THREE.Mesh");if("undefined"===typeof b)throw Error("mass not specified");a.__skunami||(a.__skunami={});a.__skunami.isObstacle=!0;a.__skunami.isDynamic=!0;a.__skunami.mass=b;this.__dynObstacles.push(a)};
SKUNAMI.GpuHeightFieldWater.prototype.removeObstacle=function(a){var b,c;b=0;for(c=this.__dynObstacles.length;b<c;b++)this.__dynObstacles[b]===a&&this.__dynObstacles.splice(b,1);var e=!1;b=0;for(c=this.__staticObstacles.length;b<c;b++)this.__staticObstacles[b]===a&&(this.__staticObstacles.splice(b,1),e=!0);e&&(this.__shouldUpdateStaticObstacle=!0)};
SKUNAMI.GpuHeightFieldWater.prototype.__updateStaticObstacleTexture=function(a){this.__clearRenderTarget(this.__rttStaticObstaclesRenderTarget,0,0,0,1);this.__clearRenderTarget(this.__rttObstacleTopRenderTarget,0,0,0,0);this.__scene.traverse(function(a){a.visibleStore=a.visible;a.visible=!1});this.__scene.overrideMaterial=this.__rttObstaclesDepthMaterial;var b;a=0;for(b=this.__staticObstacles.length;a<b;a++)this.__staticObstacles[a].visible=!0;this.__renderer.render(this.__scene,this.__rttObstaclesTopCamera,
this.__rttObstacleTopRenderTarget,!1);this.__rttQuadMesh.material=this.__staticObstaclesMaterial;this.__staticObstaclesMaterial.uniforms.uObstacleTopTexture.value=this.__rttObstacleTopRenderTarget;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttStaticObstaclesRenderTarget,!1);this.__rttQuadMesh.material=this.__erodeMaterial;this.__erodeMaterial.uniforms.uTexture.value=this.__rttStaticObstaclesRenderTarget;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttStaticObstaclesRenderTarget,
!1);this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttStaticObstaclesRenderTarget,!1);this.__scene.overrideMaterial=null;this.__scene.traverse(function(a){a.visible=a.visibleStore})};
SKUNAMI.GpuHeightFieldWater.prototype.__updateDynObstacleTexture=function(a){this.__rttQuadMesh.material=this.__copyChannelsMaterial;this.__copyChannelsMaterial.uniforms.uTexture.value=this.__rttDynObstaclesRenderTarget;this.__copyChannelsMaterial.uniforms.uOriginChannelId.value.copy(this.__channelVectors.g);this.__copyChannelsMaterial.uniforms.uDestChannelId.value.copy(this.__channelVectors.b);this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttDynObstaclesRenderTarget,!1);this.__rttQuadMesh.material=
this.__resetMaskedMaterial;this.__resetMaskedMaterial.uniforms.uTexture.value=this.__rttDynObstaclesRenderTarget;this.__resetMaskedMaterial.uniforms.uColor.value.set(0,0,0,0);this.__resetMaskedMaterial.uniforms.uChannelMask.value.set(1,1,0,1);this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttDynObstaclesRenderTarget,!1);this.__rttQuadMesh.material=this.__combineTexturesMaterial;this.__combineTexturesMaterial.uniforms.uTexture1.value=this.__rttRenderTarget2;this.__combineTexturesMaterial.uniforms.uTexture2.value=
this.__terrainTexture;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttCombinedHeightsBlurredRenderTarget,!1);this.__rttQuadMesh.material=this.__gaussianBlurXMaterial;this.__gaussianBlurXMaterial.uniforms.uTexture.value=this.__rttCombinedHeightsBlurredRenderTarget;this.__gaussianBlurXMaterial.uniforms.uTexelSize.value=1/this.__res;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttCombinedHeightsBlurredRenderTarget,!1);this.__rttQuadMesh.material=this.__gaussianBlurYMaterial;
this.__gaussianBlurYMaterial.uniforms.uTexture.value=this.__rttCombinedHeightsBlurredRenderTarget;this.__gaussianBlurYMaterial.uniforms.uTexelSize.value=1/this.__res;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttCombinedHeightsBlurredRenderTarget,!1);var b=this;this.__scene.traverse(function(a){a.visibleStore=a.visible;a.visible=!1});this.__scene.overrideMaterial=this.__rttObstaclesDepthMaterial;this.__scene.traverse(function(c){if(c instanceof THREE.Mesh&&c.__skunami&&c.__skunami.isObstacle&&
c.__skunami.isDynamic){c.visible=!0;b.__clearRenderTarget(b.__rttObstacleTopRenderTarget,0,0,0,0);b.__clearRenderTarget(b.__rttObstacleBottomRenderTarget,0,0,0,0);b.__renderer.render(b.__scene,b.__rttObstaclesTopCamera,b.__rttObstacleTopRenderTarget,!1);b.__renderer.render(b.__scene,b.__rttObstaclesBottomCamera,b.__rttObstacleBottomRenderTarget,!1);b.__rttQuadMesh.material=b.__dynObstaclesMaterial;b.__dynObstaclesMaterial.uniforms.uObstaclesTexture.value=b.__rttDynObstaclesRenderTarget;b.__dynObstaclesMaterial.uniforms.uObstacleTopTexture.value=
b.__rttObstacleTopRenderTarget;b.__dynObstaclesMaterial.uniforms.uObstacleBottomTexture.value=b.__rttObstacleBottomRenderTarget;b.__dynObstaclesMaterial.uniforms.uWaterTexture.value=b.__rttCombinedHeightsBlurredRenderTarget;b.__dynObstaclesMaterial.uniforms.uTerrainTexture.value=b.__emptyTexture;b.__renderer.render(b.__rttScene,b.__rttCamera,b.__rttDynObstaclesRenderTarget,!1);b.__pr.reduce(b.__rttDynObstaclesRenderTarget,"sum","a");c.__skunami.totalDisplacedVol=b.__pr.getPixelFloatData("a")[0]*b.__segmentSizeSquared;
b.__rttQuadMesh.material=b.__maskWaterMaterial;b.__maskWaterMaterial.uniforms.uTexture1.value=b.__rttRenderTarget1;b.__maskWaterMaterial.uniforms.uTexture2.value=b.__rttObstacleTopRenderTarget;b.__renderer.render(b.__rttScene,b.__rttCamera,b.__rttMaskedWaterRenderTarget,!1);b.__pr.reduce(b.__rttMaskedWaterRenderTarget,"sum","g");c.__skunami.totalVelocityX=b.__pr.getPixelFloatData("g")[0];b.__pr.reduce(b.__rttMaskedWaterRenderTarget,"sum","b");c.__skunami.totalVelocityZ=b.__pr.getPixelFloatData("b")[0];
b.__pr.reduce(b.__rttObstacleTopRenderTarget,"sum","a");c.__skunami.totalArea=b.__pr.getPixelFloatData("a")[0];0===c.__skunami.totalArea?(c.__skunami.averageVelocityX=0,c.__skunami.averageVelocityZ=0):(c.__skunami.averageVelocityX=c.__skunami.totalVelocityX/c.__skunami.totalArea,c.__skunami.averageVelocityZ=c.__skunami.totalVelocityZ/c.__skunami.totalArea);c.__skunami.forceX=c.__skunami.averageVelocityX/a*c.__skunami.mass;c.__skunami.forceY=c.__skunami.totalDisplacedVol*b.__density*b.__gravity;c.__skunami.forceZ=
c.__skunami.averageVelocityZ/a*c.__skunami.mass;if(b.__callbacks.hasOwnProperty("exertForce")){var e=b.__callbacks.exertForce,d,f;d=0;for(f=e.length;d<f;d++)e[d](c,new THREE.Vector3(c.__skunami.forceX,c.__skunami.forceY,c.__skunami.forceZ))}c.visible=!1}});this.__scene.overrideMaterial=null;this.__scene.traverse(function(a){a.visible=a.visibleStore});this.__rttQuadMesh.material=this.__gaussianBlurXMaterial;this.__gaussianBlurXMaterial.uniforms.uTexture.value=this.__rttDynObstaclesRenderTarget;this.__gaussianBlurXMaterial.uniforms.uTexelSize.value=
1/this.__res;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttDynObstaclesBlurredRenderTarget,!1);this.__rttQuadMesh.material=this.__gaussianBlurYMaterial;this.__gaussianBlurYMaterial.uniforms.uTexture.value=this.__rttDynObstaclesBlurredRenderTarget;this.__gaussianBlurYMaterial.uniforms.uTexelSize.value=1/this.__res;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttDynObstaclesBlurredRenderTarget,!1);this.__rttQuadMesh.material=this.__calcDisturbMapMaterial;this.__calcDisturbMapMaterial.uniforms.uTexture.value=
this.__rttDynObstaclesBlurredRenderTarget;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttDisturbMapRenderTarget,!1);this.__disturbMapHasUpdated=!0};SKUNAMI.GpuHeightFieldWater.prototype.__getPixelByteDataForRenderTarget=function(a,b,c,e){var d=this.__renderer.getContext();d.bindFramebuffer(d.FRAMEBUFFER,a.__webglFramebuffer);d.readPixels(0,0,c,e,d.RGBA,d.UNSIGNED_BYTE,b);d.bindFramebuffer(d.FRAMEBUFFER,null)};
SKUNAMI.GpuHeightFieldWater.prototype.__getPixelEncodedByteData=function(a,b,c,e,d){this.__rttQuadMesh.material=this.__rttEncodeFloatMaterial;this.__rttEncodeFloatMaterial.uniforms.uTexture.value=a;this.__rttEncodeFloatMaterial.uniforms.uChannelMask.value.copy(this.__channelVectors[c]);this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttFloatEncoderRenderTarget,!1);this.__getPixelByteDataForRenderTarget(this.__rttFloatEncoderRenderTarget,b,e,d)};
SKUNAMI.GpuHeightFieldWater.prototype.getPixelFloatData=function(){this.__getPixelEncodedByteData(this.__rttRenderTarget1,this.__pixelByteData,"r",this.__res,this.__res);return new Float32Array(this.__pixelByteData.buffer)};
SKUNAMI.GpuHeightFieldWater.prototype.addCallback=function(a,b){this.__callbacks.hasOwnProperty(a)||(this.__callbacks[a]=[]);if(b)if("function"===typeof b)this.__callbacks[a].push(b);else throw Error("Specified callbackFn is not a function");else throw Error("Callback function not defined");};SKUNAMI.GpuHeightFieldWater.prototype.getWaterDisplayTexture=function(){return this.__rttWaterDisplay};SKUNAMI.GpuHeightFieldWater.prototype.getObstaclesDisplayTexture=function(){return this.__rttObstaclesDisplay};
SKUNAMI.GpuHeightFieldSurfaceWater=function(a){this.__meanHeight=a.meanHeight||0;SKUNAMI.GpuHeightFieldWater.call(this,a)};SKUNAMI.GpuHeightFieldSurfaceWater.prototype=Object.create(SKUNAMI.GpuHeightFieldWater.prototype);SKUNAMI.GpuHeightFieldSurfaceWater.prototype.constructor=SKUNAMI.GpuHeightFieldSurfaceWater;SKUNAMI.GpuHeightFieldSurfaceWater.prototype.flood=function(a){this.__meanHeight+=a/(this.__size*this.__size)};SKUNAMI.GpuHeightFieldSurfaceWater.prototype.getMeanHeight=function(){return this.__meanHeight};
SKUNAMI.GpuHeightFieldSurfaceWater.prototype.setMeanHeight=function(a){this.__meanHeight=a};SKUNAMI.GpuMuellerGdc2008Water=function(a){if("undefined"===typeof a.horizontalSpeed)throw Error("horizontalSpeed not specified");this.__horizontalSpeed=a.horizontalSpeed;SKUNAMI.GpuHeightFieldSurfaceWater.call(this,a);this.__maxDt=this.__segmentSize/this.__horizontalSpeed};SKUNAMI.GpuMuellerGdc2008Water.prototype=Object.create(SKUNAMI.GpuHeightFieldSurfaceWater.prototype);
SKUNAMI.GpuMuellerGdc2008Water.prototype.constructor=SKUNAMI.GpuMuellerGdc2008Water;SKUNAMI.GpuMuellerGdc2008Water.prototype.__getWaterFragmentShaderContent=function(){return this.__shaders.frag.hfWater_muellerGdc2008};SKUNAMI.GpuMuellerGdc2008Water.prototype.__setupShaders=function(){SKUNAMI.GpuHeightFieldSurfaceWater.prototype.__setupShaders.call(this);this.__waterSimMaterial.uniforms.uHorizontalSpeed={type:"f",value:this.__horizontalSpeed}};
SKUNAMI.GpuMuellerGdc2008Water.prototype.__calculateSubsteps=function(a){return Math.ceil(1.5*a/this.__maxDt)};SKUNAMI.GpuMuellerGdc2008HwWater=function(a){SKUNAMI.GpuHeightFieldSurfaceWater.call(this,a)};SKUNAMI.GpuMuellerGdc2008HwWater.prototype=Object.create(SKUNAMI.GpuHeightFieldSurfaceWater.prototype);SKUNAMI.GpuMuellerGdc2008HwWater.prototype.constructor=SKUNAMI.GpuMuellerGdc2008HwWater;SKUNAMI.GpuMuellerGdc2008HwWater.prototype.__getWaterFragmentShaderContent=function(){return this.__shaders.frag.hfWater_muellerGdc2008Hw};
SKUNAMI.GpuXWater=function(a){SKUNAMI.GpuHeightFieldSurfaceWater.call(this,a)};SKUNAMI.GpuXWater.prototype=Object.create(SKUNAMI.GpuHeightFieldSurfaceWater.prototype);SKUNAMI.GpuXWater.prototype.constructor=SKUNAMI.GpuXWater;SKUNAMI.GpuXWater.prototype.__getWaterFragmentShaderContent=function(){return this.__shaders.frag.hfWater_xWater};SKUNAMI.GpuTessendorfIWaveWater=function(a){this.__kernelRadius=2;SKUNAMI.GpuHeightFieldSurfaceWater.call(this,a);this.__loadKernelTexture()};
SKUNAMI.GpuTessendorfIWaveWater.prototype=Object.create(SKUNAMI.GpuHeightFieldSurfaceWater.prototype);SKUNAMI.GpuTessendorfIWaveWater.prototype.constructor=SKUNAMI.GpuTessendorfIWaveWater;SKUNAMI.GpuTessendorfIWaveWater.prototype.__getWaterFragmentShaderContent=function(){return this.__shaders.frag.hfWater_tessendorfIWave};
SKUNAMI.GpuTessendorfIWaveWater.prototype.__setupShaders=function(){SKUNAMI.GpuHeightFieldSurfaceWater.prototype.__setupShaders.call(this);this.__convolveMaterial=new THREE.ShaderMaterial({uniforms:{uWaterTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,this.__texelSize)},uKernel:{type:"fv1",value:this.__kernelData}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_tessendorfIWave_convolve});this.__waterSimMaterial=
new THREE.ShaderMaterial({uniforms:{uWaterTexture:{type:"t",value:this.__emptyTexture},uTwoMinusDampTimesDt:{type:"f",value:0},uOnePlusDampTimesDt:{type:"f",value:0},uGravityTimesDtTimesDt:{type:"f",value:0},uMeanHeight:{type:"f",value:this.__meanHeight}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__getWaterFragmentShaderContent()})};
SKUNAMI.GpuTessendorfIWaveWater.prototype.__waterSimPass=function(a){this.__rttQuadMesh.material=this.__convolveMaterial;this.__convolveMaterial.uniforms.uWaterTexture.value=this.__rttRenderTarget2;this.__convolveMaterial.uniforms.uKernel.value=this.__kernelData;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1);this.__swapRenderTargets();this.__rttQuadMesh.material=this.__waterSimMaterial;this.__waterSimMaterial.uniforms.uWaterTexture.value=this.__rttRenderTarget2;
this.__waterSimMaterial.uniforms.uTwoMinusDampTimesDt.value=2-this.__dampingFactor*a;this.__waterSimMaterial.uniforms.uOnePlusDampTimesDt.value=1+this.__dampingFactor*a;this.__waterSimMaterial.uniforms.uGravityTimesDtTimesDt.value=-this.__gravity*a*a;this.__waterSimMaterial.uniforms.uMeanHeight.value=this.__meanHeight;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1);this.__swapRenderTargets()};
SKUNAMI.GpuTessendorfIWaveWater.prototype.__kernels={2:{0:{0:1,1:0.6782766063331379,2:0.15642080318487095,"-1":0.6782766063331379,"-2":0.15642080318487095},1:{0:0.6782766063331379,1:0.4445648954185427,2:0.07225753616898249,"-1":0.4445648954185427,"-2":0.07225753616898249},2:{0:0.15642080318487095,1:0.07225753616898249,2:-0.04993877689422348,"-1":0.07225753616898249,"-2":-0.04993877689422348},"-1":{0:0.6782766063331379,1:0.4445648954185427,2:0.07225753616898249,"-1":0.4445648954185427,"-2":0.07225753616898249},
"-2":{0:0.15642080318487095,1:0.07225753616898249,2:-0.04993877689422348,"-1":0.07225753616898249,"-2":-0.04993877689422348}},6:{0:{0:1,1:0.6782766063331379,2:0.15642080318487095,3:-0.06532739057096157,4:-0.06444781066526209,5:-0.031433210050842826,6:-0.014956820349629208,"-2":0.15642080318487095,"-6":-0.014956820349629208,"-5":-0.031433210050842826,"-4":-0.06444781066526209,"-3":-0.06532739057096157,"-1":0.6782766063331379},1:{0:0.6782766063331379,1:0.4445648954185427,2:0.07225753616898249,3:-0.07377485074364465,
4:-0.059964799734097914,5:-0.029072820004281557,6:-0.014159108191184992,"-2":0.07225753616898249,"-6":-0.014159108191184992,"-5":-0.029072820004281557,"-4":-0.059964799734097914,"-3":-0.07377485074364465,"-1":0.4445648954185427},2:{0:0.15642080318487095,1:0.07225753616898249,2:-0.04993877689422348,3:-0.07593786512383575,4:-0.04726251879247821,5:-0.02327690200919993,6:-0.012144644038531688,"-2":-0.04993877689422348,"-6":-0.012144644038531688,"-5":-0.02327690200919993,"-4":-0.04726251879247821,"-3":-0.07593786512383575,
"-1":0.07225753616898249},3:{0:-0.06532739057096157,1:-0.07377485074364465,2:-0.07593786512383575,3:-0.05553701410671365,4:-0.031433210050842826,5:-0.01678961595296967,6:-0.009704215484535582,"-2":-0.07593786512383575,"-6":-0.009704215484535582,"-5":-0.01678961595296967,"-4":-0.031433210050842826,"-3":-0.05553701410671365,"-1":-0.07377485074364465},4:{0:-0.06444781066526209,1:-0.059964799734097914,2:-0.04726251879247821,3:-0.031433210050842826,4:-0.019006732548424117,5:-0.011577903734318462,6:-0.007455793802651235,
"-2":-0.04726251879247821,"-6":-0.007455793802651235,"-5":-0.011577903734318462,"-4":-0.019006732548424117,"-3":-0.031433210050842826,"-1":-0.059964799734097914},5:{0:-0.031433210050842826,1:-0.029072820004281557,2:-0.02327690200919993,3:-0.01678961595296967,4:-0.011577903734318462,5:-0.007999069393190969,6:-0.005640889038955295,"-2":-0.02327690200919993,"-6":-0.005640889038955295,"-5":-0.007999069393190969,"-4":-0.011577903734318462,"-3":-0.01678961595296967,"-1":-0.029072820004281557},6:{0:-0.014956820349629208,
1:-0.014159108191184992,2:-0.012144644038531688,3:-0.009704215484535582,4:-0.007455793802651235,5:-0.005640889038955295,6:-0.004262207043249518,"-2":-0.012144644038531688,"-6":-0.004262207043249518,"-5":-0.005640889038955295,"-4":-0.007455793802651235,"-3":-0.009704215484535582,"-1":-0.014159108191184992},"-2":{0:0.15642080318487095,1:0.07225753616898249,2:-0.04993877689422348,3:-0.07593786512383575,4:-0.04726251879247821,5:-0.02327690200919993,6:-0.012144644038531688,"-2":-0.04993877689422348,"-6":-0.012144644038531688,
"-5":-0.02327690200919993,"-4":-0.04726251879247821,"-3":-0.07593786512383575,"-1":0.07225753616898249},"-6":{0:-0.014956820349629208,1:-0.014159108191184992,2:-0.012144644038531688,3:-0.009704215484535582,4:-0.007455793802651235,5:-0.005640889038955295,6:-0.004262207043249518,"-2":-0.012144644038531688,"-6":-0.004262207043249518,"-5":-0.005640889038955295,"-4":-0.007455793802651235,"-3":-0.009704215484535582,"-1":-0.014159108191184992},"-5":{0:-0.031433210050842826,1:-0.029072820004281557,2:-0.02327690200919993,
3:-0.01678961595296967,4:-0.011577903734318462,5:-0.007999069393190969,6:-0.005640889038955295,"-2":-0.02327690200919993,"-6":-0.005640889038955295,"-5":-0.007999069393190969,"-4":-0.011577903734318462,"-3":-0.01678961595296967,"-1":-0.029072820004281557},"-4":{0:-0.06444781066526209,1:-0.059964799734097914,2:-0.04726251879247821,3:-0.031433210050842826,4:-0.019006732548424117,5:-0.011577903734318462,6:-0.007455793802651235,"-2":-0.04726251879247821,"-6":-0.007455793802651235,"-5":-0.011577903734318462,
"-4":-0.019006732548424117,"-3":-0.031433210050842826,"-1":-0.059964799734097914},"-3":{0:-0.06532739057096157,1:-0.07377485074364465,2:-0.07593786512383575,3:-0.05553701410671365,4:-0.031433210050842826,5:-0.01678961595296967,6:-0.009704215484535582,"-2":-0.07593786512383575,"-6":-0.009704215484535582,"-5":-0.01678961595296967,"-4":-0.031433210050842826,"-3":-0.05553701410671365,"-1":-0.07377485074364465},"-1":{0:0.6782766063331379,1:0.4445648954185427,2:0.07225753616898249,3:-0.07377485074364465,
4:-0.059964799734097914,5:-0.029072820004281557,6:-0.014159108191184992,"-2":0.07225753616898249,"-6":-0.014159108191184992,"-5":-0.029072820004281557,"-4":-0.059964799734097914,"-3":-0.07377485074364465,"-1":0.4445648954185427}}};
SKUNAMI.GpuTessendorfIWaveWater.prototype.__loadKernelTexture=function(){this.__G=this.__kernels[this.__kernelRadius];if("undefined"===typeof this.__G)throw Error("Unable to load iWave kernel with radius: "+this.__kernelRadius);var a=2*this.__kernelRadius+1;this.__kernelData=new Float32Array(a*a);var b,c,e,d,f;for(c in this.__G)if(this.__G.hasOwnProperty(c))for(b in f=this.__G[c],f)f.hasOwnProperty(b)&&(d=f[b],e=(parseInt(c,10)+this.__kernelRadius)*a+(parseInt(b,10)+this.__kernelRadius),this.__kernelData[e]=
d)};
SKUNAMI.GpuPipeModelWater=function(a){this.__minWaterHeight=-0.05;this.__initialWaterHeight=a.initialWaterHeight||0;this.__initialWaterHeight+=this.__minWaterHeight;SKUNAMI.GpuHeightFieldWater.call(this,a);this.__terrainTexture=a.terrainTexture||this.__emptyTexture;this.__isSourcing=!1;this.__sourceUvPos=new THREE.Vector2;this.__sourceAmount=0;this.__sourceRadius=0.0025*this.__size;this.__atmosPressure=0;this.__pipeLength=this.__segmentSize;this.__pipeCrossSectionArea=this.__pipeLength*this.__pipeLength;this.__pipeCrossSectionArea*=
this.__res/10;this.__heightToFluxFactorNoDt=this.__pipeCrossSectionArea*this.__gravity/this.__pipeLength;this.__maxHorizontalSpeed=10;this.__maxDt=this.__segmentSize/this.__maxHorizontalSpeed};SKUNAMI.GpuPipeModelWater.prototype=Object.create(SKUNAMI.GpuHeightFieldWater.prototype);SKUNAMI.GpuPipeModelWater.prototype.constructor=SKUNAMI.GpuPipeModelWater;SKUNAMI.GpuPipeModelWater.prototype.__getWaterFragmentShaderContent=function(){return this.__shaders.frag.hfWater_pipeModel};
SKUNAMI.GpuPipeModelWater.prototype.__setupShaders=function(){SKUNAMI.GpuHeightFieldWater.prototype.__setupShaders.call(this);this.__waterSimMaterial=new THREE.ShaderMaterial({uniforms:{uTerrainTexture:{type:"t",value:this.__emptyTexture},uWaterTexture:{type:"t",value:this.__emptyTexture},uFluxTexture:{type:"t",value:this.__emptyTexture},uStaticObstaclesTexture:{type:"t",value:this.__emptyTexture},uBoundaryTexture:{type:"t",value:this.__emptyTexture},uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,
this.__texelSize)},uDampingFactor:{type:"f",value:this.__dampingFactor},uHeightToFluxFactor:{type:"f",value:0},uSegmentSizeSquared:{type:"f",value:this.__segmentSizeSquared},uDt:{type:"f",value:0},uMinWaterHeight:{type:"f",value:this.__minWaterHeight}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_pipeModel_calcFlux});this.__waterSimMaterial2=new THREE.ShaderMaterial({uniforms:{uWaterTexture:{type:"t",value:this.__emptyTexture},uFluxTexture:{type:"t",value:this.__emptyTexture},
uTexelSize:{type:"v2",value:new THREE.Vector2(this.__texelSize,this.__texelSize)},uSegmentSize:{type:"f",value:this.__segmentSize},uDt:{type:"f",value:0},uMinWaterHeight:{type:"f",value:this.__minWaterHeight}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__getWaterFragmentShaderContent()});this.__calcFinalWaterHeightMaterial=new THREE.ShaderMaterial({uniforms:{uTerrainTexture:{type:"t",value:this.__emptyTexture},uStaticObstaclesTexture:{type:"t",value:this.__emptyTexture},uWaterTexture:{type:"t",
value:this.__emptyTexture},uMultiplyTexture:{type:"t",value:this.__emptyTexture},uMaskOffset:{type:"f",value:this.__minWaterHeight}},vertexShader:this.__shaders.vert.passUv,fragmentShader:this.__shaders.frag.hfWater_pipeModel_calcFinalWaterHeight});this.__disturbAndSourceMaterial.uniforms.uUseObstacleTexture.value=!1;this.__disturbAndSourceMaterial.uniforms.uIsFlooding={type:"i",value:0};this.__disturbAndSourceMaterial.uniforms.uFloodAmount={type:"f",value:this.__floodAmount}};
SKUNAMI.GpuPipeModelWater.prototype.__setupRttRenderTargets=function(){SKUNAMI.GpuHeightFieldWater.prototype.__setupRttRenderTargets.call(this);this.__rttRenderTargetFlux1=this.__supportsTextureFloatLinear?new THREE.WebGLRenderTarget(this.__res,this.__res,this.__linearFloatRgbaParams):new THREE.WebGLRenderTarget(this.__res,this.__res,this.__nearestFloatRgbaParams);this.__rttRenderTargetFlux1.generateMipmaps=!1;this.__clearRenderTarget(this.__rttRenderTargetFlux1,0,0,0,0);this.__rttRenderTargetFlux2=
this.__rttRenderTargetFlux1.clone();this.__clearRenderTarget(this.__rttRenderTargetFlux2,0,0,0,0);this.__rttCombinedHeight=this.__rttRenderTarget1.clone();this.__clearRenderTarget(this.__rttCombinedHeight,0,0,0,0)};SKUNAMI.GpuPipeModelWater.prototype.source=function(a,b,c){this.__isSourcing=!0;this.__sourceUvPos.x=(a.x+this.__halfSize)/this.__size;this.__sourceUvPos.y=(a.z+this.__halfSize)/this.__size;this.__sourceAmount=b;this.__sourceRadius=c};
SKUNAMI.GpuPipeModelWater.prototype.flood=function(a){this.__isFlooding=!0;this.__floodAmount=a/(this.__size*this.__size)};
SKUNAMI.GpuPipeModelWater.prototype.__disturbPass=function(){var a=!1;this.__disturbMapHasUpdated&&(this.__disturbAndSourceMaterial.uniforms.uDisturbTexture.value=this.__rttDisturbMapRenderTarget,a=!0);this.__isDisturbing&&0!==this.__disturbAmount&&(this.__disturbAndSourceMaterial.uniforms.uIsDisturbing.value=this.__isDisturbing,this.__disturbAndSourceMaterial.uniforms.uDisturbPos.value.copy(this.__disturbUvPos),this.__disturbAndSourceMaterial.uniforms.uDisturbAmount.value=this.__disturbAmount,this.__disturbAndSourceMaterial.uniforms.uDisturbRadius.value=
this.__disturbRadius/this.__size,a=!0);this.__isSourcing&&0!==this.__sourceAmount&&(this.__disturbAndSourceMaterial.uniforms.uIsSourcing.value=this.__isSourcing,this.__disturbAndSourceMaterial.uniforms.uSourcePos.value.copy(this.__sourceUvPos),this.__disturbAndSourceMaterial.uniforms.uSourceAmount.value=this.__sourceAmount,this.__disturbAndSourceMaterial.uniforms.uSourceRadius.value=this.__sourceRadius/this.__size,a=!0);this.__isFlooding&&0!==this.__floodAmount&&(this.__disturbAndSourceMaterial.uniforms.uIsFlooding.value=
this.__isFlooding,this.__disturbAndSourceMaterial.uniforms.uFloodAmount.value=this.__floodAmount,a=!0);a&&(this.__rttQuadMesh.material=this.__disturbAndSourceMaterial,this.__disturbAndSourceMaterial.uniforms.uTexture.value=this.__rttRenderTarget2,this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1),this.__swapRenderTargets(),this.__disturbMapHasUpdated=!1,this.__disturbAndSourceMaterial.uniforms.uDisturbTexture.value=this.__emptyTexture,this.__isDisturbing=!1,this.__isSourcing=
this.__disturbAndSourceMaterial.uniforms.uIsDisturbing.value=!1,this.__isFlooding=this.__disturbAndSourceMaterial.uniforms.uIsSourcing.value=!1,this.__disturbAndSourceMaterial.uniforms.uIsFlooding.value=!1)};SKUNAMI.GpuPipeModelWater.prototype.__calculateSubsteps=function(a){return Math.ceil(5*a/this.__maxDt)};
SKUNAMI.GpuPipeModelWater.prototype.__resetPass=function(){this.__clearRenderTarget(this.__rttRenderTarget2,this.__initialWaterHeight,this.__initialWaterHeight,this.__initialWaterHeight,this.__initialWaterHeight);this.__clearRenderTarget(this.__rttRenderTargetFlux2,0,0,0,0)};
SKUNAMI.GpuPipeModelWater.prototype.__waterSimPass=function(a){this.__rttQuadMesh.material=this.__waterSimMaterial;this.__waterSimMaterial.uniforms.uTerrainTexture.value=this.__terrainTexture;this.__waterSimMaterial.uniforms.uWaterTexture.value=this.__rttRenderTarget2;this.__waterSimMaterial.uniforms.uFluxTexture.value=this.__rttRenderTargetFlux2;this.__waterSimMaterial.uniforms.uStaticObstaclesTexture.value=this.__rttStaticObstaclesRenderTarget;this.__waterSimMaterial.uniforms.uBoundaryTexture.value=
this.__boundaryTexture;this.__waterSimMaterial.uniforms.uHeightToFluxFactor.value=this.__heightToFluxFactorNoDt*a;this.__waterSimMaterial.uniforms.uDt.value=a;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTargetFlux1,!1);this.__swapFluxRenderTargets();this.__rttQuadMesh.material=this.__waterSimMaterial2;this.__waterSimMaterial2.uniforms.uWaterTexture.value=this.__rttRenderTarget2;this.__waterSimMaterial2.uniforms.uFluxTexture.value=this.__rttRenderTargetFlux2;this.__waterSimMaterial2.uniforms.uDt.value=
a;this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttRenderTarget1,!1);this.__swapRenderTargets()};
SKUNAMI.GpuPipeModelWater.prototype.__postStepPass=function(){this.__rttQuadMesh.material=this.__calcFinalWaterHeightMaterial;this.__calcFinalWaterHeightMaterial.uniforms.uTerrainTexture.value=this.__terrainTexture;this.__calcFinalWaterHeightMaterial.uniforms.uStaticObstaclesTexture.value=this.__rttStaticObstaclesRenderTarget;this.__calcFinalWaterHeightMaterial.uniforms.uWaterTexture.value=this.__rttRenderTarget2;this.__calcFinalWaterHeightMaterial.uniforms.uMultiplyTexture.value=this.__boundaryTexture;
this.__renderer.render(this.__rttScene,this.__rttCamera,this.__rttCombinedHeight,!1);this.__mesh.material.uniforms.uTexture.value=this.__rttCombinedHeight};SKUNAMI.GpuPipeModelWater.prototype.__swapFluxRenderTargets=function(){var a=this.__rttRenderTargetFlux1;this.__rttRenderTargetFlux1=this.__rttRenderTargetFlux2;this.__rttRenderTargetFlux2=a};