UNPKG

lingo3d-vanilla

Version:

Lingo3D is a React/Vue 3d game development framework that ships with a complete visual editor

1 lines 7.25 kB
"use strict";(self.webpackChunklingo3d_vanilla=self.webpackChunklingo3d_vanilla||[]).push([[498],{3498:(t,e,r)=>{r.r(e),r.d(e,{Water:()=>o});var n=r(7002);class o extends n.Kj0{constructor(t,e={}){super(t),this.isWater=!0;const r=this,o=void 0!==e.textureWidth?e.textureWidth:512,i=void 0!==e.textureHeight?e.textureHeight:512,a=void 0!==e.clipBias?e.clipBias:0,l=void 0!==e.alpha?e.alpha:1,s=void 0!==e.time?e.time:0,u=void 0!==e.waterNormals?e.waterNormals:null,c=void 0!==e.sunDirection?e.sunDirection:new n.Pa4(.70707,.70707,0),m=new n.Ilk(void 0!==e.sunColor?e.sunColor:16777215),d=new n.Ilk(void 0!==e.waterColor?e.waterColor:8355711),v=void 0!==e.eye?e.eye:new n.Pa4(0,0,0),f=void 0!==e.distortionScale?e.distortionScale:20,p=void 0!==e.side?e.side:n.Wl3,x=void 0!==e.fog&&e.fog,g=new n.JOQ,w=new n.Pa4,h=new n.Pa4,y=new n.Pa4,C=new n.yGw,S=new n.Pa4(0,0,-1),_=new n.Ltg,M=new n.Pa4,P=new n.Pa4,D=new n.Ltg,b=new n.yGw,z=new n.cPb,k=new n.dd2(o,i),N={uniforms:n.rDY.merge([n.rBU.fog,n.rBU.lights,{normalSampler:{value:null},mirrorSampler:{value:null},alpha:{value:1},time:{value:0},size:{value:1},distortionScale:{value:20},textureMatrix:{value:new n.yGw},sunColor:{value:new n.Ilk(8355711)},sunDirection:{value:new n.Pa4(.70707,.70707,0)},eye:{value:new n.Pa4},waterColor:{value:new n.Ilk(5592405)}}]),vertexShader:"\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}",fragmentShader:"\n\t\t\t\tuniform sampler2D mirrorSampler;\n\t\t\t\tuniform float alpha;\n\t\t\t\tuniform float time;\n\t\t\t\tuniform float size;\n\t\t\t\tuniform float distortionScale;\n\t\t\t\tuniform sampler2D normalSampler;\n\t\t\t\tuniform vec3 sunColor;\n\t\t\t\tuniform vec3 sunDirection;\n\t\t\t\tuniform vec3 eye;\n\t\t\t\tuniform vec3 waterColor;\n\n\t\t\t\tvarying vec4 mirrorCoord;\n\t\t\t\tvarying vec4 worldPosition;\n\n\t\t\t\tvec4 getNoise( vec2 uv ) {\n\t\t\t\t\tvec2 uv0 = ( uv / 103.0 ) + vec2(time / 17.0, time / 29.0);\n\t\t\t\t\tvec2 uv1 = uv / 107.0-vec2( time / -19.0, time / 31.0 );\n\t\t\t\t\tvec2 uv2 = uv / vec2( 8907.0, 9803.0 ) + vec2( time / 101.0, time / 97.0 );\n\t\t\t\t\tvec2 uv3 = uv / vec2( 1091.0, 1027.0 ) - vec2( time / 109.0, time / -113.0 );\n\t\t\t\t\tvec4 noise = texture2D( normalSampler, uv0 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv1 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv2 ) +\n\t\t\t\t\t\ttexture2D( normalSampler, uv3 );\n\t\t\t\t\treturn noise * 0.5 - 1.0;\n\t\t\t\t}\n\n\t\t\t\tvoid sunLight( const vec3 surfaceNormal, const vec3 eyeDirection, float shiny, float spec, float diffuse, inout vec3 diffuseColor, inout vec3 specularColor ) {\n\t\t\t\t\tvec3 reflection = normalize( reflect( -sunDirection, surfaceNormal ) );\n\t\t\t\t\tfloat direction = max( 0.0, dot( eyeDirection, reflection ) );\n\t\t\t\t\tspecularColor += pow( direction, shiny ) * sunColor * spec;\n\t\t\t\t\tdiffuseColor += max( dot( sunDirection, surfaceNormal ), 0.0 ) * sunColor * diffuse;\n\t\t\t\t}\n\n\t\t\t\t#include <common>\n\t\t\t\t#include <packing>\n\t\t\t\t#include <bsdfs>\n\t\t\t\t#include <fog_pars_fragment>\n\t\t\t\t#include <logdepthbuf_pars_fragment>\n\t\t\t\t#include <lights_pars_begin>\n\t\t\t\t#include <shadowmap_pars_fragment>\n\t\t\t\t#include <shadowmask_pars_fragment>\n\n\t\t\t\tvoid main() {\n\n\t\t\t\t\t#include <logdepthbuf_fragment>\n\t\t\t\t\tvec4 noise = getNoise( worldPosition.xz * size );\n\t\t\t\t\tvec3 surfaceNormal = normalize( noise.xzy * vec3( 1.5, 1.0, 1.5 ) );\n\n\t\t\t\t\tvec3 diffuseLight = vec3(0.0);\n\t\t\t\t\tvec3 specularLight = vec3(0.0);\n\n\t\t\t\t\tvec3 worldToEye = eye-worldPosition.xyz;\n\t\t\t\t\tvec3 eyeDirection = normalize( worldToEye );\n\t\t\t\t\tsunLight( surfaceNormal, eyeDirection, 100.0, 2.0, 0.5, diffuseLight, specularLight );\n\n\t\t\t\t\tfloat distance = length(worldToEye);\n\n\t\t\t\t\tvec2 distortion = surfaceNormal.xz * ( 0.001 + 1.0 / distance ) * distortionScale;\n\t\t\t\t\tvec3 reflectionSample = vec3( texture2D( mirrorSampler, mirrorCoord.xy / mirrorCoord.w + distortion ) );\n\n\t\t\t\t\tfloat theta = max( dot( eyeDirection, surfaceNormal ), 0.0 );\n\t\t\t\t\tfloat rf0 = 0.3;\n\t\t\t\t\tfloat reflectance = rf0 + ( 1.0 - rf0 ) * pow( ( 1.0 - theta ), 5.0 );\n\t\t\t\t\tvec3 scatter = max( 0.0, dot( surfaceNormal, eyeDirection ) ) * waterColor;\n\t\t\t\t\tvec3 albedo = mix( ( sunColor * diffuseLight * 0.3 + scatter ) * getShadowMask(), ( vec3( 0.1 ) + reflectionSample * 0.9 + reflectionSample * specularLight ), reflectance);\n\t\t\t\t\tvec3 outgoingLight = albedo;\n\t\t\t\t\tgl_FragColor = vec4( outgoingLight, alpha );\n\n\t\t\t\t\t#include <tonemapping_fragment>\n\t\t\t\t\t#include <fog_fragment>\n\t\t\t\t}"},W=new n.jyz({fragmentShader:N.fragmentShader,vertexShader:N.vertexShader,uniforms:n.rDY.clone(N.uniforms),lights:!0,side:p,fog:x});W.uniforms.mirrorSampler.value=k.texture,W.uniforms.textureMatrix.value=b,W.uniforms.alpha.value=l,W.uniforms.time.value=s,W.uniforms.normalSampler.value=u,W.uniforms.sunColor.value=m,W.uniforms.waterColor.value=d,W.uniforms.sunDirection.value=c,W.uniforms.distortionScale.value=f,W.uniforms.eye.value=v,r.material=W,r.onBeforeRender=function(t,e,n){if(h.setFromMatrixPosition(r.matrixWorld),y.setFromMatrixPosition(n.matrixWorld),C.extractRotation(r.matrixWorld),w.set(0,0,1),w.applyMatrix4(C),M.subVectors(h,y),M.dot(w)>0)return;M.reflect(w).negate(),M.add(h),C.extractRotation(n.matrixWorld),S.set(0,0,-1),S.applyMatrix4(C),S.add(y),P.subVectors(h,S),P.reflect(w).negate(),P.add(h),z.position.copy(M),z.up.set(0,1,0),z.up.applyMatrix4(C),z.up.reflect(w),z.lookAt(P),z.far=n.far,z.updateMatrixWorld(),z.projectionMatrix.copy(n.projectionMatrix),b.set(.5,0,0,.5,0,.5,0,.5,0,0,.5,.5,0,0,0,1),b.multiply(z.projectionMatrix),b.multiply(z.matrixWorldInverse),g.setFromNormalAndCoplanarPoint(w,h),g.applyMatrix4(z.matrixWorldInverse),_.set(g.normal.x,g.normal.y,g.normal.z,g.constant);const o=z.projectionMatrix;D.x=(Math.sign(_.x)+o.elements[8])/o.elements[0],D.y=(Math.sign(_.y)+o.elements[9])/o.elements[5],D.z=-1,D.w=(1+o.elements[10])/o.elements[14],_.multiplyScalar(2/_.dot(D)),o.elements[2]=_.x,o.elements[6]=_.y,o.elements[10]=_.z+1-a,o.elements[14]=_.w,v.setFromMatrixPosition(n.matrixWorld);const i=t.getRenderTarget(),l=t.xr.enabled,s=t.shadowMap.autoUpdate;r.visible=!1,t.xr.enabled=!1,t.shadowMap.autoUpdate=!1,t.setRenderTarget(k),t.state.buffers.depth.setMask(!0),!1===t.autoClear&&t.clear(),t.render(e,z),r.visible=!0,t.xr.enabled=l,t.shadowMap.autoUpdate=s,t.setRenderTarget(i);const u=n.viewport;void 0!==u&&t.state.viewport(u)}}}}}]);