File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { Uniform } from 'three'
2
+ import { BlendFunction , Effect , EffectAttribute } from 'postprocessing'
3
+ import { wrapEffect } from '../util'
4
+
5
+ const WaterShader = {
6
+ fragmentShader : `
7
+ uniform float factor;
8
+ void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
9
+ vec2 vUv = uv;
10
+ float frequency = 6.0 * factor;
11
+ float amplitude = 0.015 * factor;
12
+ float x = vUv.y * frequency + time * .7;
13
+ float y = vUv.x * frequency + time * .3;
14
+ vUv.x += cos(x+y) * amplitude * cos(y);
15
+ vUv.y += sin(x-y) * amplitude * cos(y);
16
+ vec4 rgba = texture2D(inputBuffer, vUv);
17
+ outputColor = rgba;
18
+ }`
19
+ }
20
+
21
+ export class WaterEffectImpl extends Effect {
22
+ constructor ( { blendFunction = BlendFunction . NORMAL , factor = 0 } = { } ) {
23
+ super ( 'WaterEffect' , WaterShader . fragmentShader , {
24
+ blendFunction,
25
+ attributes : EffectAttribute . CONVOLUTION ,
26
+ uniforms : new Map < string , Uniform < number | number [ ] > > ( [ [ 'factor' , new Uniform ( factor ) ] ] )
27
+ } )
28
+ }
29
+ }
30
+
31
+ export const WaterEffect = wrapEffect ( WaterEffectImpl , { blendFunction : BlendFunction . NORMAL } )
Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ export * from './effects/LUT'
33
33
export * from './effects/TiltShift'
34
34
export * from './effects/TiltShift2'
35
35
export * from './effects/ASCII'
36
+ export * from './effects/Water'
36
37
37
38
// These are not effect passes
38
39
export * from './effects/SSR'
You can’t perform that action at this time.
0 commit comments