Skip to content

Commit

Permalink
feat: watereffect
Browse files Browse the repository at this point in the history
  • Loading branch information
drcmda committed Feb 11, 2024
1 parent 7f6e394 commit d230437
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/effects/Water.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Uniform } from 'three'
import { BlendFunction, Effect, EffectAttribute } from 'postprocessing'
import { wrapEffect } from '../util'

const WaterShader = {
fragmentShader: `
uniform float factor;
void mainImage(const in vec4 inputColor, const in vec2 uv, out vec4 outputColor) {
vec2 vUv = uv;
float frequency = 6.0 * factor;
float amplitude = 0.015 * factor;
float x = vUv.y * frequency + time * .7;
float y = vUv.x * frequency + time * .3;
vUv.x += cos(x+y) * amplitude * cos(y);
vUv.y += sin(x-y) * amplitude * cos(y);
vec4 rgba = texture2D(inputBuffer, vUv);
outputColor = rgba;
}`
}

export class WaterEffectImpl extends Effect {
constructor({ blendFunction = BlendFunction.NORMAL, factor = 0 } = {}) {
super('WaterEffect', WaterShader.fragmentShader, {
blendFunction,
attributes: EffectAttribute.CONVOLUTION,
uniforms: new Map<string, Uniform<number | number[]>>([['factor', new Uniform(factor)]])
})
}
}

export const WaterEffect = wrapEffect(WaterEffectImpl, { blendFunction: BlendFunction.NORMAL })
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export * from './effects/LUT'
export * from './effects/TiltShift'
export * from './effects/TiltShift2'
export * from './effects/ASCII'
export * from './effects/Water'

// These are not effect passes
export * from './effects/SSR'
Expand Down

0 comments on commit d230437

Please sign in to comment.