1 line
17 KiB
Plaintext
1 line
17 KiB
Plaintext
|
|
{"version":3,"file":"Water.cjs","sources":["../../src/objects/Water.js"],"sourcesContent":["import {\n Color,\n FrontSide,\n Matrix4,\n Mesh,\n PerspectiveCamera,\n Plane,\n ShaderMaterial,\n UniformsLib,\n UniformsUtils,\n Vector3,\n Vector4,\n WebGLRenderTarget,\n} from 'three'\nimport { version } from '../_polyfill/constants'\n\n/**\n * Work based on :\n * https://github.com/Slayvin: Flat mirror for three.js\n * https://home.adelphi.edu/~stemkoski/ : An implementation of water shader based on the flat mirror\n * http://29a.ch/ && http://29a.ch/slides/2012/webglwater/ : Water shader explanations in WebGL\n */\n\nclass Water extends Mesh {\n constructor(geometry, options = {}) {\n super(geometry)\n\n this.isWater = true\n\n const scope = this\n\n const textureWidth = options.textureWidth !== undefined ? options.textureWidth : 512\n const textureHeight = options.textureHeight !== undefined ? options.textureHeight : 512\n\n const clipBias = options.clipBias !== undefined ? options.clipBias : 0.0\n const alpha = options.alpha !== undefined ? options.alpha : 1.0\n const time = options.time !== undefined ? options.time : 0.0\n const normalSampler = options.waterNormals !== undefined ? options.waterNormals : null\n const sunDirection = options.sunDirection !== undefined ? options.sunDirection : new Vector3(0.70707, 0.70707, 0.0)\n const sunColor = new Color(options.sunColor !== undefined ? options.sunColor : 0xffffff)\n const waterColor = new Color(options.waterColor !== undefined ? options.waterColor : 0x7f7f7f)\n const eye = options.eye !== undefined ? options.eye : new Vector3(0, 0, 0)\n const distortionScale = options.distortionScale !== undefined ? options.distortionScale : 20.0\n const side = options.side !== undefined ? options.side : FrontSide\n const fog = options.fog !== undefined ? options.fog : false\n\n //\n\n const mirrorPlane = new Plane()\n const normal = new Vector3()\n const mirrorWorldPosition = new Vector3()\n const cameraWorldPosition = new Vector3()\n const rotationMatrix = new Matrix4()\n const lookAtPosition = new Vector3(0, 0, -1)\n const clipPlane = new Vector4()\n\n const view = new Vector3()\n const target = new Vector3()\n const q = new Vector4()\n\n const textureMatrix = new Matrix4()\n\n const mirrorCamera = new PerspectiveCamera()\n\n const renderTarget = new WebGLRenderTarget(textureWidth, textureHeight)\n\n const mirrorShader = {\n uniforms: UniformsUtils.merge([\n UniformsLib['fog'],\n UniformsLib['lights'],\n {\n normalSampler: { value: null },\n mirrorSampler: { value: null },\n alpha: { value: 1.0 },\n time: { value: 0.0 },\n size: { value: 1.0 },\n distortionScale: { value: 20.0 },\n textureMatrix: { value: new Matrix4() },\n sunColor: { value: new Color(0x7f7f7f) },\n sunDirection: { value: new Vector3(0.70707, 0.70707, 0) },\n eye: { value: new Vector3() },\n waterColor: { value: new Color(0x555555) },\n },\n ]),\n\n vertexShader: /* glsl */ `\n\t\t\t\tuniform mat4 textureMatrix;\n\t\t\t\tuniform float time;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <fog_pars_vertex>\n\t\t\t\t#include <shadowmap_pars_vertex>\n\t\t\t\t#include <logdepthbuf_pars_vertex>\n\n\t\t\t\tvoid main() {\n\t\t\t\t\tmirrorCoord = modelMatrix * vec4( position, 1.0 );\n\t\t\t\t\tworldPosition = mirrorCoord.xyzw;\n\t\t\t\t\tmirrorCoord = textureMatrix * mirrorCoord;\n\t\t\t\t\tvec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\t\t\t\t\tgl_Position = projectionMatrix * mvPosition;\n\n\t\t\t\t#include <beginnormal_vertex>\n\t\t\t\t#include <defaultnormal_vertex>\n\t\t\t\t#include <logdepthbuf_vertex>\n\t\t\t\t#include <fog_vertex>\n\t\t\t\t#include <shadowmap_vertex>\n\t\t\t}`,\n\n fragmentShader: /* glsl */ `\n\t\t\t\tuniform sampler2D mirrorSampler;\n\t\t\t\tuniform float alpha;\n
|