mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-01-19 20:25:01 +00:00
1 line
8.3 KiB
JavaScript
1 line
8.3 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,42585,e=>{"use strict";e.s(["WaterBlock",()=>m,"WaterMaterial",()=>p,"WaterSurfaceMaterial",()=>d],42585);var n=e.i(43476),a=e.i(71645),t=e.i(47071),o=e.i(5230),i=e.i(90072),r=e.i(12979),l=e.i(62395),s=e.i(75567),u=e.i(48066),c=e.i(47021);let v="\n #include <fog_pars_fragment>\n\n // Enable volumetric fog (must be defined before fog uniforms)\n #ifdef USE_FOG\n #define USE_VOLUMETRIC_FOG\n #define USE_FOG_WORLD_POSITION\n #endif\n\n uniform float uTime;\n uniform float uOpacity;\n uniform float uEnvMapIntensity;\n uniform sampler2D uBaseTexture;\n uniform sampler2D uEnvMapTexture;\n\n // Volumetric fog uniforms\n #ifdef USE_FOG\n uniform float fogVolumeData[12];\n uniform float cameraHeight;\n varying vec3 vFogWorldPosition;\n #endif\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 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) ===\n vec2 uv1b = rotateUV(baseUV + vec2(baseDriftX, baseDriftY), radians(60.0));\n\n // Calculate cross-fade swing value\n float A1 = cos(((vWorldPosition.x / Q1) + (uTime / Q2)) * 6.0);\n float A2 = sin(((vWorldPosition.z / Q1) + (uTime / Q2)) * TWO_PI);\n float swing = (A1 + A2) * 0.15 + 0.5;\n\n // Cross-fade alpha calculation from engine\n float alpha1a = ((1.0 - swing) * uOpacity) / max(1.0 - (swing * uOpacity), 0.001);\n float alpha1b = swing * uOpacity;\n\n // Sample base texture for both passes\n vec4 texColor1a = texture2D(uBaseTexture, uv1a);\n vec4 texColor1b = texture2D(uBaseTexture, uv1b);\n\n // Combined alpha and color\n float combinedAlpha = 1.0 - (1.0 - alpha1a) * (1.0 - alpha1b);\n vec3 baseColor = (texColor1a.rgb * alpha1a * (1.0 - alpha1b) + texColor1b.rgb * alpha1b) / max(combinedAlpha, 0.001);\n\n // === Phase 3: Environment map / specular ===\n vec3 reflectVec = -vViewVector;\n reflectVec.y = abs(reflectVec.y);\n if (reflectVec.y < 0.001) reflectVec.y = 0.001;\n\n vec2 envUV;\n if (vDistance < 0.001) {\n envUV = vec2(0.0);\n } else {\n float value = (vDistance - reflectVec.y) / (vDistance * vDistance);\n envUV.x = reflectVec.x * value;\n envUV.y = reflectVec.z * value;\n }\n\n envUV = envUV * 0.5 + 0.5;\n envUV.x += A1 * Q3;\n envUV.y += A2 * Q3;\n\n vec4 envColor = texture2D(uEnvMapTexture, envUV);\n vec3 finalColor = baseColor + envColor.rgb * envColor.a * uEnvMapIntensity;\n\n // Note: Tribes 2 water does NOT use lighting - Phase 2 (lightmap) is disabled\n // in the original engine. Water colors come directly from textures.\n\n gl_FragColor = vec4(finalColor, combinedAlpha);\n\n // Apply volumetric fog using shared Torque-style fog shader\n ".concat(c.fogFragmentShader,"\n }\n");var f=e.i(79123);function d(e){let{surfaceTexture:l,envMapTexture:c,opacity:d=.75,waveMagnitude:p=1,envMapIntensity:m=1,attach:g}=e,h=(0,r.textureToUrl)(l),x=(0,r.textureToUrl)(null!=c?c:"special/lush_env"),[T,y]=(0,t.useTexture)([h,x],e=>{(Array.isArray(e)?e:[e]).forEach(e=>{(0,s.setupColor)(e),e.colorSpace=i.NoColorSpace,e.wrapS=i.RepeatWrapping,e.wrapT=i.RepeatWrapping})}),{animationEnabled:b}=(0,f.useSettings)(),w=(0,a.useMemo)(()=>{var e,n,a,t,o,r;return e={opacity:d,waveMagnitude:p,envMapIntensity:m,baseTexture:T,envMapTexture:y},new i.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!=(o=null==e?void 0:e.baseTexture)?o:null},uEnvMapTexture:{value:null!=(r=null==e?void 0:e.envMapTexture)?r:null},fogColor:{value:new i.Color},fogNear:{value:1},fogFar:{value:2e3},fogVolumeData:u.globalFogUniforms.fogVolumeData,cameraHeight:u.globalFogUniforms.cameraHeight},vertexShader:"\n #include <fog_pars_vertex>\n\n #ifdef USE_FOG\n #define USE_FOG_WORLD_POSITION\n varying vec3 vFogWorldPosition;\n #endif\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 final world position after displacement for fog\n #ifdef USE_FOG\n vec4 displacedWorldPos = modelMatrix * vec4(displaced, 1.0);\n vFogWorldPosition = displacedWorldPos.xyz;\n #endif\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 // Set fog depth (distance from camera) - normally done by fog_vertex include\n // but we can't use that include because it references 'transformed' which we don't have\n #ifdef USE_FOG\n vFogDepth = length(mvPosition.xyz);\n #endif\n }\n",fragmentShader:v,transparent:!0,side:i.DoubleSide,depthWrite:!0,fog:!0})},[d,p,m,T,y]),P=(0,a.useRef)(0);return(0,o.useFrame)((e,n)=>{if(!b){P.current=0,w.uniforms.uTime.value=0;return}P.current+=n,w.uniforms.uTime.value=P.current}),(0,a.useEffect)(()=>()=>{w.dispose()},[w]),(0,n.jsx)("primitive",{object:w,attach:g})}function p(e){let{surfaceTexture:a,attach:o}=e,l=(0,r.textureToUrl)(a),u=(0,t.useTexture)(l,e=>(0,s.setupColor)(e));return(0,n.jsx)("meshStandardMaterial",{attach:o,map:u,transparent:!0,opacity:.8,side:i.DoubleSide})}let m=(0,a.memo)(function(e){var t,o,r,s;let{object:u}=e,c=(0,a.useMemo)(()=>(0,l.getPosition)(u),[u]),v=(0,a.useMemo)(()=>(0,l.getRotation)(u),[u]),[f,p,m]=(0,a.useMemo)(()=>(0,l.getScale)(u),[u]),g=null!=(t=(0,l.getProperty)(u,"surfaceTexture"))?t:"liquidTiles/BlueWater",h=(0,l.getProperty)(u,"envMapTexture"),x=parseFloat(null!=(o=(0,l.getProperty)(u,"surfaceOpacity"))?o:"0.75"),T=parseFloat(null!=(r=(0,l.getProperty)(u,"waveMagnitude"))?r:"1.0"),y=parseFloat(null!=(s=(0,l.getProperty)(u,"envMapIntensity"))?s:"1.0"),b=(0,a.useMemo)(()=>{let[e,n]=function(e,n){let a=e<=1024&&n<=1024?8:16;return[Math.max(4,Math.ceil(e/a)),Math.max(4,Math.ceil(n/a))]}(f,m),a=new i.PlaneGeometry(f,m,e,n);return a.rotateX(-Math.PI/2),a.translate(f/2,p,m/2),a},[f,p,m]);return(0,a.useEffect)(()=>()=>{b.dispose()},[b]),(0,n.jsx)("group",{position:c,quaternion:v,children:(0,n.jsx)("mesh",{geometry:b,children:(0,n.jsx)(a.Suspense,{fallback:(0,n.jsx)("meshStandardMaterial",{color:"blue",transparent:!0,opacity:.3,side:i.DoubleSide}),children:(0,n.jsx)(d,{attach:"material",surfaceTexture:g,envMapTexture:h,opacity:x,waveMagnitude:T,envMapIntensity:y})})})})})}]); |