mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-01-19 20:25:01 +00:00
1 line
8.8 KiB
JavaScript
1 line
8.8 KiB
JavaScript
|
|
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,42585,e=>{"use strict";e.s(["WaterBlock",()=>p,"WaterMaterial",()=>v,"WaterSurfaceMaterial",()=>c],42585);var n=e.i(43476),a=e.i(71645),t=e.i(47071),i=e.i(5230),r=e.i(90072),o=e.i(12979),l=e.i(62395),s=e.i(75567),u=e.i(79123);function c(e){let{surfaceTexture:l,envMapTexture:c,opacity:v=.75,waveMagnitude:p=1,envMapIntensity:d=1,attach:f}=e,m=(0,o.textureToUrl)(l),g=(0,o.textureToUrl)(null!=c?c:"special/lush_env"),[h,T]=(0,t.useTexture)([m,g],e=>{(Array.isArray(e)?e:[e]).forEach(e=>{(0,s.setupColor)(e),e.wrapS=r.RepeatWrapping,e.wrapT=r.RepeatWrapping})}),{animationEnabled:x}=(0,u.useSettings)(),b=(0,a.useMemo)(()=>{var e,n,a,t,i,o;return e={opacity:v,waveMagnitude:p,envMapIntensity:d,baseTexture:h,envMapTexture:T},new r.ShaderMaterial({uniforms:{uTime:{value:0},uOpacity:{value:null!=(n=null==e?void 0:e.opacity)?n:.75},uWaveMagnitude:{value:null!=(a=null==e?void 0:e.waveMagnitude)?a:1},uEnvMapIntensity:{value:null!=(t=null==e?void 0:e.envMapIntensity)?t:1},uBaseTexture:{value:null!=(i=null==e?void 0:e.baseTexture)?i:null},uEnvMapTexture:{value:null!=(o=null==e?void 0:e.envMapTexture)?o:null},fogColor:{value:new r.Color},fogNear:{value:1},fogFar:{value:2e3}},vertexShader:"\n #include <fog_pars_vertex>\n\n uniform float uTime;\n uniform float uWaveMagnitude;\n\n varying vec3 vWorldPosition;\n varying vec3 vViewVector;\n varying float vDistance;\n\n // Wave function matching Tribes 2 engine\n // Z = surfaceZ + (sin(X*0.05 + time) + sin(Y*0.05 + time)) * waveFactor\n // waveFactor = waveAmplitude * 0.25\n // Note: Using xz for Three.js Y-up (Torque uses XY with Z-up)\n float getWaveHeight(vec3 worldPos) {\n float waveFactor = uWaveMagnitude * 0.25;\n return (sin(worldPos.x * 0.05 + uTime) + sin(worldPos.z * 0.05 + uTime)) * waveFactor;\n }\n\n void main() {\n // Get world position for wave calculation\n vec4 worldPos = modelMatrix * vec4(position, 1.0);\n vWorldPosition = worldPos.xyz;\n\n // Apply wave displacement to Y (vertical axis in Three.js)\n vec3 displaced = position;\n displaced.y += getWaveHeight(worldPos.xyz);\n\n // Calculate view vector for environment mapping\n vViewVector = cameraPosition - worldPos.xyz;\n vDistance = length(vViewVector);\n\n vec4 mvPosition = viewMatrix * modelMatrix * vec4(displaced, 1.0);\n gl_Position = projectionMatrix * mvPosition;\n\n #include <fog_vertex>\n }\n",fragmentShader:"\n #include <fog_pars_fragment>\n\n uniform float uTime;\n uniform float uOpacity;\n uniform float uEnvMapIntensity;\n uniform sampler2D uBaseTexture;\n uniform sampler2D uEnvMapTexture;\n\n varying vec3 vWorldPosition;\n varying vec3 vViewVector;\n varying float vDistance;\n\n #define TWO_PI 6.283185307179586\n\n // Constants from Tribes 2 engine\n #define BASE_DRIFT_CYCLE_TIME 8.0\n #define BASE_DRIFT_RATE 0.02\n #define BASE_DRIFT_SCALAR 0.03\n #define TEXTURE_SCALE (1.0 / 48.0)\n\n // Environment map UV wobble constants\n #define Q1 150.0\n #define Q2 2.0\n #define Q3 0.01\n\n // Rotate UV coordinates\n vec2 rotateUV(vec2 uv, float angle) {\n float c = cos(angle);\n float s = sin(angle);\n return vec2(\n uv.x * c - uv.y * s,\n uv.x * s + uv.y * c\n );\n }\n\n void main() {\n // Calculate base texture UVs using world position (1/48 tiling)\n // Note: In Three.js Y-up coordinates, the water surface is on the XZ plane\n // Torque uses Z-up where the surface is XY, so we use xz here\n vec2 baseUV = vWorldPosition.xz * TEXTURE_SCALE;\n\n // Phase (time in radians for drift cycle)\n float phase = mod(uTime * (TWO_PI / BASE_DRIFT_CYCLE_TIME), TWO_PI);\n\n // Base texture drift\n float baseDriftX = uTime * BASE_DRIFT_RATE;\n float baseDriftY = cos(phase) * BASE_DRIFT_SCALAR;\n\n // === Phase 1a: First base texture pass (rotated 30 degrees) ===\n vec2 uv1a = rotateUV(baseUV, radians(30.0));\n\n // === Phase 1b: Second base texture pass (rotated 60 degrees total, with drift
|