UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

61 lines (60 loc) 2.25 kB
import { Color, Matrix4, ShaderMaterial, Vector3, BufferGeometry, Texture, WebGLRenderer, Scene, Camera, Side } from 'three'; import { IUniformColor, IUniformN, IUniformTexture, IUniformV3 } from '../../../engine/nodes/utils/code/gl/Uniforms'; import { BaseReflector, BaseReflectorOptions } from './_BaseReflector'; import { PolyScene } from '../../../engine/scene/PolyScene'; /** * Work based on : * http://slayvin.net : Flat mirror for three.js * http://www.adelphi.edu/~stemkoski : An implementation of water shader based on the flat mirror * http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL */ export interface WaterMaterial extends ShaderMaterial { uniforms: { sunDirection: IUniformV3; sunColor: IUniformColor; wavesHeight: IUniformN; waterColor: IUniformColor; reflectionColor: IUniformColor; reflectionFresnel: IUniformN; distortionScale: IUniformN; size: IUniformN; alpha: IUniformN; time: IUniformN; timeScale: IUniformN; direction: IUniformV3; normalBias: IUniformN; mirrorSampler: IUniformTexture; textureMatrix: { value: Matrix4; }; eye: IUniformV3; }; } export interface WaterOptions extends BaseReflectorOptions { polyScene: PolyScene; alpha?: number; timeScale?: number; size?: number; direction?: Vector3; sunDirection?: Vector3; sunColor?: Color; wavesHeight?: number; waterColor?: Color; reflectionColor?: Color; reflectionFresnel?: number; waterNormals?: Texture; distortionScale?: number; normalBias?: number; side?: Side; useFog?: boolean; } export declare class Water extends BaseReflector<BufferGeometry, WaterMaterial> { protected _options: WaterOptions; readonly isWater = true; protected _mirrorCameraMultipliedByMatrixWorld: boolean; constructor(geometry: BufferGeometry, _options: WaterOptions); protected _createMaterial(): WaterMaterial; protected _assignMaterialRenderTarget(): void; protected _onBeforeRender(renderer: WebGLRenderer, scene: Scene, anyCamera: Camera): void; setReflectionActive(state: boolean): void; }