Skip to content

Commit d230437

Browse files
committed
feat: watereffect
1 parent 7f6e394 commit d230437

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/effects/Water.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 })

src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export * from './effects/LUT'
3333
export * from './effects/TiltShift'
3434
export * from './effects/TiltShift2'
3535
export * from './effects/ASCII'
36+
export * from './effects/Water'
3637

3738
// These are not effect passes
3839
export * from './effects/SSR'

0 commit comments

Comments
 (0)