-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters