@pinkaphant/kolmo 0.2.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +36 -36
- package/bin/kolmo.mjs +12 -6
- package/dist/engine/causewayBridge.d.ts +14 -0
- package/dist/engine/causewayBridge.js +166 -0
- package/dist/engine/causewayBridge.js.map +1 -0
- package/dist/engine/index.d.ts +6 -4
- package/dist/engine/index.js +19 -12
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/islandSettlementMesh.d.ts +26 -0
- package/dist/engine/islandSettlementMesh.js +166 -0
- package/dist/engine/islandSettlementMesh.js.map +1 -0
- package/dist/engine/kolmoActions.d.ts +23 -0
- package/dist/engine/kolmoActions.js +164 -0
- package/dist/engine/kolmoActions.js.map +1 -0
- package/dist/engine/kolmoActor.js +242 -165
- package/dist/engine/kolmoActor.js.map +1 -0
- package/dist/engine/kolmoFloatingOrigin.d.ts +17 -0
- package/dist/engine/kolmoFloatingOrigin.js +98 -0
- package/dist/engine/kolmoFloatingOrigin.js.map +1 -0
- package/dist/engine/kolmoGame.d.ts +27 -0
- package/dist/engine/kolmoGame.js +80 -0
- package/dist/engine/kolmoGame.js.map +1 -0
- package/dist/engine/kolmoHud.d.ts +23 -0
- package/dist/engine/kolmoHud.js +195 -0
- package/dist/engine/kolmoHud.js.map +1 -0
- package/dist/engine/kolmoInput.d.ts +1 -1
- package/dist/engine/kolmoInput.js +57 -30
- package/dist/engine/kolmoInput.js.map +1 -0
- package/dist/engine/kolmoIsland.d.ts +5 -10
- package/dist/engine/kolmoIsland.js +182 -250
- package/dist/engine/kolmoIsland.js.map +1 -0
- package/dist/engine/kolmoLongDrive.d.ts +3 -4
- package/dist/engine/kolmoLongDrive.js +140 -205
- package/dist/engine/kolmoLongDrive.js.map +1 -0
- package/dist/engine/kolmoPilotMesh.d.ts +2 -0
- package/dist/engine/kolmoPilotMesh.js +64 -0
- package/dist/engine/kolmoPilotMesh.js.map +1 -0
- package/dist/engine/kolmoProcedural.d.ts +13 -0
- package/dist/engine/kolmoProcedural.js +101 -0
- package/dist/engine/kolmoProcedural.js.map +1 -0
- package/dist/engine/kolmoRigs.d.ts +1 -1
- package/dist/engine/kolmoRigs.js +88 -47
- package/dist/engine/kolmoRigs.js.map +1 -0
- package/dist/engine/kolmoStore.d.ts +3 -100
- package/dist/engine/kolmoSurface.d.ts +2 -2
- package/dist/engine/kolmoSurface.js +150 -134
- package/dist/engine/kolmoSurface.js.map +1 -0
- package/dist/engine/kolmoTraits.d.ts +128 -0
- package/dist/engine/kolmoTraits.js +140 -0
- package/dist/engine/kolmoTraits.js.map +1 -0
- package/dist/engine/kolmoVehicle.d.ts +3 -33
- package/dist/engine/kolmoVehicle.js +66 -240
- package/dist/engine/kolmoVehicle.js.map +1 -0
- package/dist/engine/kolmoVehicleConfig.d.ts +54 -0
- package/dist/engine/kolmoVehicleConfig.js +80 -0
- package/dist/engine/kolmoVehicleConfig.js.map +1 -0
- package/dist/engine/kolmoVehicleDriver.d.ts +4 -1
- package/dist/engine/kolmoVehicleDriver.js +116 -22
- package/dist/engine/kolmoVehicleDriver.js.map +1 -0
- package/dist/engine/kolmoVehicleInner.d.ts +7 -0
- package/dist/engine/kolmoVehicleInner.js +261 -0
- package/dist/engine/kolmoVehicleInner.js.map +1 -0
- package/dist/engine/kolmoWorld.d.ts +6 -4
- package/dist/engine/kolmoWorld.js +134 -116
- package/dist/engine/kolmoWorld.js.map +1 -0
- package/dist/engine/longDriveKit.d.ts +5 -12
- package/dist/engine/longDriveKit.js +121 -233
- package/dist/engine/longDriveKit.js.map +1 -0
- package/dist/engine/longDriveRoadside.d.ts +16 -0
- package/dist/engine/longDriveRoadside.js +171 -0
- package/dist/engine/longDriveRoadside.js.map +1 -0
- package/dist/engine/macroCellBuilder.d.ts +34 -0
- package/dist/engine/macroCellBuilder.js +145 -0
- package/dist/engine/macroCellBuilder.js.map +1 -0
- package/dist/engine/mainlandMacroCell.d.ts +2 -2
- package/dist/engine/mainlandMacroCell.js +77 -165
- package/dist/engine/mainlandMacroCell.js.map +1 -0
- package/dist/engine/shiftedFixedBody.d.ts +1 -1
- package/dist/engine/shiftedFixedBody.js +55 -28
- package/dist/engine/shiftedFixedBody.js.map +1 -0
- package/dist/importer/ChopShopPanel.d.ts +9 -1
- package/dist/importer/ChopShopPanel.js +303 -359
- package/dist/importer/ChopShopPanel.js.map +1 -0
- package/dist/importer/DomainWorkshopPanel.d.ts +2 -1
- package/dist/importer/DomainWorkshopPanel.js +172 -242
- package/dist/importer/DomainWorkshopPanel.js.map +1 -0
- package/dist/importer/GateHudBar.d.ts +8 -0
- package/dist/importer/GateHudBar.js +290 -279
- package/dist/importer/GateHudBar.js.map +1 -0
- package/dist/importer/GlbImportGate.d.ts +2 -1
- package/dist/importer/GlbImportGate.js +252 -225
- package/dist/importer/GlbImportGate.js.map +1 -0
- package/dist/importer/ImperativeVehicleRig.d.ts +2 -2
- package/dist/importer/ImperativeVehicleRig.js +223 -284
- package/dist/importer/ImperativeVehicleRig.js.map +1 -0
- package/dist/importer/LiveDrivePads.d.ts +20 -0
- package/dist/importer/LiveDrivePads.js +169 -0
- package/dist/importer/LiveDrivePads.js.map +1 -0
- package/dist/importer/PaperShellDebrisRig.d.ts +25 -0
- package/dist/importer/PaperShellDebrisRig.js +143 -0
- package/dist/importer/PaperShellDebrisRig.js.map +1 -0
- package/dist/importer/R2VaultDrawer.d.ts +12 -0
- package/dist/importer/R2VaultDrawer.js +90 -0
- package/dist/importer/R2VaultDrawer.js.map +1 -0
- package/dist/importer/Step1CalibrationPlinth.d.ts +23 -5
- package/dist/importer/Step1CalibrationPlinth.js +180 -251
- package/dist/importer/Step1CalibrationPlinth.js.map +1 -0
- package/dist/importer/Step1ExplodedIslands.d.ts +31 -0
- package/dist/importer/Step1ExplodedIslands.js +144 -0
- package/dist/importer/Step1ExplodedIslands.js.map +1 -0
- package/dist/importer/Step2UniversalPad.d.ts +7 -7
- package/dist/importer/Step2UniversalPad.js +49 -170
- package/dist/importer/Step2UniversalPad.js.map +1 -0
- package/dist/importer/VfxEmitterPool.js +59 -86
- package/dist/importer/VfxEmitterPool.js.map +1 -0
- package/dist/importer/WheelRingHandles3D.d.ts +11 -0
- package/dist/importer/WheelRingHandles3D.js +318 -0
- package/dist/importer/WheelRingHandles3D.js.map +1 -0
- package/dist/importer/archLinerGeom.d.ts +2 -0
- package/dist/importer/archLinerGeom.js +51 -0
- package/dist/importer/archLinerGeom.js.map +1 -0
- package/dist/importer/{vehiclePanelAnim.d.ts → chopHingeHelpers.d.ts} +0 -10
- package/dist/importer/chopHingeHelpers.js +193 -0
- package/dist/importer/chopHingeHelpers.js.map +1 -0
- package/dist/importer/chopShopActions.d.ts +20 -26
- package/dist/importer/chopShopActions.js +135 -210
- package/dist/importer/chopShopActions.js.map +1 -0
- package/dist/importer/chopShopHandlers.d.ts +26 -0
- package/dist/importer/chopShopHandlers.js +276 -0
- package/dist/importer/chopShopHandlers.js.map +1 -0
- package/dist/importer/chopShopIoActions.d.ts +15 -0
- package/dist/importer/chopShopIoActions.js +137 -0
- package/dist/importer/chopShopIoActions.js.map +1 -0
- package/dist/importer/chopShopMcpAction.d.ts +18 -0
- package/dist/importer/chopShopMcpAction.js +58 -0
- package/dist/importer/chopShopMcpAction.js.map +1 -0
- package/dist/importer/cylinderBooleanSlice.d.ts +14 -0
- package/dist/importer/cylinderBooleanSlice.js +110 -0
- package/dist/importer/cylinderBooleanSlice.js.map +1 -0
- package/dist/importer/cylinderSliceMath.d.ts +14 -0
- package/dist/importer/cylinderSliceMath.js +251 -0
- package/dist/importer/cylinderSliceMath.js.map +1 -0
- package/dist/importer/fusedWheelDetect.d.ts +4 -0
- package/dist/importer/fusedWheelDetect.js +175 -0
- package/dist/importer/fusedWheelDetect.js.map +1 -0
- package/dist/importer/fusedWheelFit.d.ts +13 -0
- package/dist/importer/fusedWheelFit.js +138 -0
- package/dist/importer/fusedWheelFit.js.map +1 -0
- package/dist/importer/gateStore.d.ts +1 -1
- package/dist/importer/gateStore.js +36 -27
- package/dist/importer/gateStore.js.map +1 -0
- package/dist/importer/glbNormalizer.js +118 -79
- package/dist/importer/glbNormalizer.js.map +1 -0
- package/dist/importer/importerWebMcp.d.ts +4 -3
- package/dist/importer/importerWebMcp.js +41 -336
- package/dist/importer/importerWebMcp.js.map +1 -0
- package/dist/importer/importerWebMcpTools.d.ts +2 -0
- package/dist/importer/importerWebMcpTools.js +340 -0
- package/dist/importer/importerWebMcpTools.js.map +1 -0
- package/dist/importer/index.d.ts +4 -0
- package/dist/importer/index.js +32 -22
- package/dist/importer/index.js.map +1 -0
- package/dist/importer/khrCarPlanHelpers.d.ts +28 -0
- package/dist/importer/khrCarPlanHelpers.js +221 -0
- package/dist/importer/khrCarPlanHelpers.js.map +1 -0
- package/dist/importer/khrCarPlanner.d.ts +7 -0
- package/dist/importer/khrCarPlanner.js +279 -0
- package/dist/importer/khrCarPlanner.js.map +1 -0
- package/dist/importer/khrCompiler.d.ts +4 -22
- package/dist/importer/khrCompiler.js +56 -424
- package/dist/importer/khrCompiler.js.map +1 -0
- package/dist/importer/khrCraftPropCompiler.d.ts +40 -0
- package/dist/importer/khrCraftPropCompiler.js +250 -0
- package/dist/importer/khrCraftPropCompiler.js.map +1 -0
- package/dist/importer/launcherBake.js +76 -35
- package/dist/importer/launcherBake.js.map +1 -0
- package/dist/importer/meshIslands.d.ts +4 -46
- package/dist/importer/meshIslands.js +84 -283
- package/dist/importer/meshIslands.js.map +1 -0
- package/dist/importer/meshSliceBuffers.d.ts +15 -0
- package/dist/importer/meshSliceBuffers.js +159 -0
- package/dist/importer/meshSliceBuffers.js.map +1 -0
- package/dist/importer/polygonEarClipYZ.d.ts +3 -0
- package/dist/importer/polygonEarClipYZ.js +67 -0
- package/dist/importer/polygonEarClipYZ.js.map +1 -0
- package/dist/importer/sceneSiNormalize.d.ts +19 -0
- package/dist/importer/sceneSiNormalize.js +138 -0
- package/dist/importer/sceneSiNormalize.js.map +1 -0
- package/dist/importer/starterScene.d.ts +3 -0
- package/dist/importer/starterScene.js +76 -0
- package/dist/importer/starterScene.js.map +1 -0
- package/dist/importer/surfaceCutter.d.ts +4 -15
- package/dist/importer/surfaceCutter.js +69 -240
- package/dist/importer/surfaceCutter.js.map +1 -0
- package/dist/importer/surfaceGeodesic.d.ts +7 -0
- package/dist/importer/surfaceGeodesic.js +130 -0
- package/dist/importer/surfaceGeodesic.js.map +1 -0
- package/dist/importer/surfaceLoopRefine.d.ts +6 -0
- package/dist/importer/surfaceLoopRefine.js +171 -0
- package/dist/importer/surfaceLoopRefine.js.map +1 -0
- package/dist/importer/surfacePeel.d.ts +11 -0
- package/dist/importer/surfacePeel.js +119 -0
- package/dist/importer/surfacePeel.js.map +1 -0
- package/dist/importer/surfaceTopology.d.ts +2 -6
- package/dist/importer/surfaceTopology.js +93 -133
- package/dist/importer/surfaceTopology.js.map +1 -0
- package/dist/importer/universalGateBake.d.ts +7 -3
- package/dist/importer/universalGateBake.js +104 -106
- package/dist/importer/universalGateBake.js.map +1 -0
- package/dist/importer/usdPhysicsSpecs.d.ts +3 -0
- package/dist/importer/usdPhysicsSpecs.js +245 -0
- package/dist/importer/usdPhysicsSpecs.js.map +1 -0
- package/dist/importer/usdTextParse.d.ts +12 -0
- package/dist/importer/usdTextParse.js +118 -0
- package/dist/importer/usdTextParse.js.map +1 -0
- package/dist/importer/usdToGlb.d.ts +3 -2
- package/dist/importer/usdToGlb.js +80 -280
- package/dist/importer/usdToGlb.js.map +1 -0
- package/dist/importer/useChopShopController.d.ts +50 -47
- package/dist/importer/useChopShopController.js +156 -338
- package/dist/importer/useChopShopController.js.map +1 -0
- package/dist/importer/useChopShopState.d.ts +103 -0
- package/dist/importer/useChopShopState.js +319 -0
- package/dist/importer/useChopShopState.js.map +1 -0
- package/dist/importer/useWasdKeyRef.d.ts +9 -0
- package/dist/importer/useWasdKeyRef.js +35 -0
- package/dist/importer/useWasdKeyRef.js.map +1 -0
- package/dist/importer/vehiclePartSplit.d.ts +33 -0
- package/dist/importer/vehiclePartSplit.js +178 -0
- package/dist/importer/vehiclePartSplit.js.map +1 -0
- package/dist/importer/wheelAxlePairing.js +106 -70
- package/dist/importer/wheelAxlePairing.js.map +1 -0
- package/dist/importer/wheelCutterHelpers.d.ts +42 -0
- package/dist/importer/wheelCutterHelpers.js +178 -0
- package/dist/importer/wheelCutterHelpers.js.map +1 -0
- package/dist/importer/wheelRingHandleMath.d.ts +20 -0
- package/dist/importer/wheelRingHandleMath.js +66 -0
- package/dist/importer/wheelRingHandleMath.js.map +1 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +90 -66
- package/dist/index.js.map +1 -0
- package/dist/junk/DestructibleTarget.d.ts +3 -3
- package/dist/junk/DestructibleTarget.js +177 -114
- package/dist/junk/DestructibleTarget.js.map +1 -0
- package/dist/junk/KolmoJunk.js +55 -44
- package/dist/junk/KolmoJunk.js.map +1 -0
- package/dist/junk/ShardPieces.d.ts +2 -1
- package/dist/junk/ShardPieces.js +80 -61
- package/dist/junk/ShardPieces.js.map +1 -0
- package/dist/junk/TargetDecals.d.ts +6 -15
- package/dist/junk/TargetDecals.js +66 -40
- package/dist/junk/TargetDecals.js.map +1 -0
- package/dist/junk/bvhShatter.d.ts +2 -6
- package/dist/junk/bvhShatter.js +89 -43
- package/dist/junk/bvhShatter.js.map +1 -0
- package/dist/junk/bvhTriCollector.d.ts +2 -6
- package/dist/junk/bvhTriCollector.js +111 -62
- package/dist/junk/bvhTriCollector.js.map +1 -0
- package/dist/junk/index.d.ts +2 -2
- package/dist/junk/index.js +11 -11
- package/dist/junk/index.js.map +1 -0
- package/dist/junk/junkGeometry.d.ts +5 -26
- package/dist/junk/junkGeometry.js +61 -43
- package/dist/junk/junkGeometry.js.map +1 -0
- package/dist/junk/junkImportSanitize.d.ts +4 -5
- package/dist/junk/junkImportSanitize.js +57 -37
- package/dist/junk/junkImportSanitize.js.map +1 -0
- package/dist/junk/junkImporter.d.ts +2 -13
- package/dist/junk/junkImporter.js +105 -76
- package/dist/junk/junkImporter.js.map +1 -0
- package/dist/junk/junkLabelCanvas.d.ts +1 -6
- package/dist/junk/junkLabelCanvas.js +147 -29
- package/dist/junk/junkLabelCanvas.js.map +1 -0
- package/dist/junk/junkLabels.d.ts +4 -26
- package/dist/junk/junkLabels.js +42 -28
- package/dist/junk/junkLabels.js.map +1 -0
- package/dist/junk/targetHelpers.d.ts +3 -4
- package/dist/junk/targetHelpers.js +121 -67
- package/dist/junk/targetHelpers.js.map +1 -0
- package/dist/junk/targetHitLogic.d.ts +8 -8
- package/dist/junk/targetHitLogic.js +131 -95
- package/dist/junk/targetHitLogic.js.map +1 -0
- package/dist/junk/useTargetAssets.d.ts +9 -14
- package/dist/junk/useTargetAssets.js +113 -85
- package/dist/junk/useTargetAssets.js.map +1 -0
- package/dist/physics/index.d.ts +1 -1
- package/dist/physics/index.js +79 -58
- package/dist/physics/index.js.map +1 -0
- package/dist/schema/kolmoSchema.d.ts +3 -64
- package/dist/schema/kolmoSchema.js +75 -149
- package/dist/schema/kolmoSchema.js.map +1 -0
- package/dist/schema/kolmoStamp.d.ts +6 -0
- package/dist/schema/kolmoStamp.js +71 -0
- package/dist/schema/kolmoStamp.js.map +1 -0
- package/dist/schema/kolmoTypes.d.ts +63 -0
- package/dist/schema/kolmoTypes.js +66 -0
- package/dist/schema/kolmoTypes.js.map +1 -0
- package/dist/shaders/celestialBackdrop.d.ts +2 -10
- package/dist/shaders/celestialBackdrop.js +128 -291
- package/dist/shaders/celestialBackdrop.js.map +1 -0
- package/dist/shaders/emitterShaders.d.ts +9 -0
- package/dist/shaders/emitterShaders.js +114 -0
- package/dist/shaders/emitterShaders.js.map +1 -0
- package/dist/shaders/index.d.ts +1 -1
- package/dist/shaders/index.js +12 -9
- package/dist/shaders/index.js.map +1 -0
- package/dist/shaders/plumeAndSparkle.d.ts +2 -4
- package/dist/shaders/plumeAndSparkle.js +152 -191
- package/dist/shaders/plumeAndSparkle.js.map +1 -0
- package/dist/shaders/ps2GlslShared.js +29 -2
- package/dist/shaders/ps2GlslShared.js.map +1 -0
- package/dist/shaders/ps2MaterialsTSL.js +132 -51
- package/dist/shaders/ps2MaterialsTSL.js.map +1 -0
- package/dist/shaders/ps2MaterialsWebGL.js +45 -28
- package/dist/shaders/ps2MaterialsWebGL.js.map +1 -0
- package/dist/shaders/ps2RoadWebGL.js +69 -32
- package/dist/shaders/ps2RoadWebGL.js.map +1 -0
- package/dist/shaders/ps2TerrainWebGL.js +107 -30
- package/dist/shaders/ps2TerrainWebGL.js.map +1 -0
- package/dist/shaders/ps2Textures.d.ts +1 -1
- package/dist/shaders/ps2Textures.js +116 -41
- package/dist/shaders/ps2Textures.js.map +1 -0
- package/dist/shaders/retroPalettes.d.ts +1 -1
- package/dist/shaders/retroPalettes.js +90 -57
- package/dist/shaders/retroPalettes.js.map +1 -0
- package/dist/shaders/retroShader.d.ts +2 -86
- package/dist/shaders/retroShader.js +65 -196
- package/dist/shaders/retroShader.js.map +1 -0
- package/dist/shaders/retroUniforms.d.ts +60 -0
- package/dist/shaders/retroUniforms.js +215 -0
- package/dist/shaders/retroUniforms.js.map +1 -0
- package/dist/shaders/skyboxShaders.d.ts +16 -0
- package/dist/shaders/skyboxShaders.js +266 -0
- package/dist/shaders/skyboxShaders.js.map +1 -0
- package/dist/shaders/tsl.d.ts +1 -1
- package/dist/shaders/tsl.js.map +1 -0
- package/dist/vite/index.js +39 -23
- package/dist/vite/index.js.map +1 -0
- package/dist/world/frontage.js +25 -21
- package/dist/world/frontage.js.map +1 -0
- package/dist/world/index.d.ts +4 -4
- package/dist/world/index.js +12 -11
- package/dist/world/index.js.map +1 -0
- package/dist/world/infiniteWorld2D.d.ts +0 -5
- package/dist/world/infiniteWorld2D.js +175 -200
- package/dist/world/infiniteWorld2D.js.map +1 -0
- package/dist/world/island.js +81 -166
- package/dist/world/island.js.map +1 -0
- package/dist/world/islandPathing.d.ts +6 -0
- package/dist/world/islandPathing.js +166 -0
- package/dist/world/islandPathing.js.map +1 -0
- package/dist/world/macroCellSchema.js +15 -8
- package/dist/world/macroCellSchema.js.map +1 -0
- package/dist/world/macroKnightAStar.js +140 -71
- package/dist/world/macroKnightAStar.js.map +1 -0
- package/dist/world/macroSettlementZones.d.ts +9 -0
- package/dist/world/macroSettlementZones.js +108 -0
- package/dist/world/macroSettlementZones.js.map +1 -0
- package/dist/world/random.js +50 -24
- package/dist/world/random.js.map +1 -0
- package/dist/world/road.js +152 -90
- package/dist/world/road.js.map +1 -0
- package/dist/world/roadRibbon.d.ts +4 -19
- package/dist/world/roadRibbon.js +129 -124
- package/dist/world/roadRibbon.js.map +1 -0
- package/dist/world/terrain.d.ts +1 -1
- package/dist/world/terrain.js +111 -65
- package/dist/world/terrain.js.map +1 -0
- package/dist/world/terrainGeometry.d.ts +14 -0
- package/dist/world/terrainGeometry.js +76 -0
- package/dist/world/terrainGeometry.js.map +1 -0
- package/dist/world/worldTypes.d.ts +3 -3
- package/dist/world/worldTypes.js +133 -67
- package/dist/world/worldTypes.js.map +1 -0
- package/docs/api-reference.md +187 -0
- package/package.json +58 -32
- package/dist/engine/kolmoStore.js +0 -211
- package/dist/importer/ImporterPlinthUikitTags.d.ts +0 -19
- package/dist/importer/ImporterPlinthUikitTags.js +0 -112
- package/dist/importer/vehiclePanelAnim.js +0 -214
|
@@ -1,25 +1,43 @@
|
|
|
1
|
-
import { SHARED_PS2_GLSL_HELPERS
|
|
2
|
-
import * as
|
|
1
|
+
import { SHARED_PS2_GLSL_HELPERS } from "./ps2GlslShared.js";
|
|
2
|
+
import * as THREE from "three";
|
|
3
3
|
// src/shaders/ps2TerrainWebGL.ts
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
uSplat0: { value:
|
|
7
|
-
uSplat1: { value:
|
|
8
|
-
uAlphaTex: { value:
|
|
9
|
-
uDetailArray: { value:
|
|
10
|
-
uTileScale: { value:
|
|
11
|
-
uDitherTexelsPerMeter: { value:
|
|
12
|
-
uSplatContrast: { value:
|
|
13
|
-
uCavityStrength: { value:
|
|
14
|
-
uCavityShadowTint: { value: new
|
|
15
|
-
uPs2ColorQuantize: { value:
|
|
16
|
-
uScreenPixelScale: { value:
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
function createPS2TerrainMaterialWebGL(textures, opts = {}) {
|
|
5
|
+
const uniforms = {
|
|
6
|
+
uSplat0: { value: textures.splat0Tex },
|
|
7
|
+
uSplat1: { value: textures.splat1Tex },
|
|
8
|
+
uAlphaTex: { value: textures.alphaTex },
|
|
9
|
+
uDetailArray: { value: textures.detailArrayTex },
|
|
10
|
+
uTileScale: { value: opts.tileScale ?? 1 / 3 },
|
|
11
|
+
uDitherTexelsPerMeter: { value: opts.ditherTexelsPerMeter ?? 16 },
|
|
12
|
+
uSplatContrast: { value: opts.splatContrast ?? 1.65 },
|
|
13
|
+
uCavityStrength: { value: opts.cavityStrength ?? 1 },
|
|
14
|
+
uCavityShadowTint: { value: new THREE.Color(7239820) },
|
|
15
|
+
uPs2ColorQuantize: { value: opts.ps2ColorQuantize ?? .85 },
|
|
16
|
+
uScreenPixelScale: { value: opts.screenPixelScale ?? 1 }
|
|
17
|
+
};
|
|
18
|
+
const material = new THREE.MeshLambertMaterial({
|
|
19
|
+
vertexColors: true,
|
|
20
|
+
fog: true
|
|
20
21
|
});
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
material.userData.__kolmoRetroApplied = true;
|
|
23
|
+
material.customProgramCacheKey = () => "ps2-terrain-splat8-lambert-v1";
|
|
24
|
+
material.onBeforeCompile = (shader) => {
|
|
25
|
+
Object.assign(shader.uniforms, uniforms);
|
|
26
|
+
shader.vertexShader = shader.vertexShader.replace("#include <common>", `
|
|
27
|
+
#include <common>
|
|
28
|
+
varying vec2 vPs2Uv;
|
|
29
|
+
varying vec3 vPs2WorldPos;
|
|
30
|
+
`).replace("#include <project_vertex>", `
|
|
31
|
+
vPs2Uv = uv;
|
|
32
|
+
vec4 ps2Wp = vec4(transformed, 1.0);
|
|
33
|
+
#ifdef USE_INSTANCING
|
|
34
|
+
ps2Wp = instanceMatrix * ps2Wp;
|
|
35
|
+
#endif
|
|
36
|
+
ps2Wp = modelMatrix * ps2Wp;
|
|
37
|
+
vPs2WorldPos = ps2Wp.xyz;
|
|
38
|
+
#include <project_vertex>
|
|
39
|
+
`);
|
|
40
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <common>", `
|
|
23
41
|
#include <common>
|
|
24
42
|
precision mediump sampler2DArray;
|
|
25
43
|
|
|
@@ -39,16 +57,75 @@ function n(n, r = {}) {
|
|
|
39
57
|
varying vec2 vPs2Uv;
|
|
40
58
|
varying vec3 vPs2WorldPos;
|
|
41
59
|
|
|
42
|
-
${
|
|
43
|
-
`).replace("#include <color_fragment>",
|
|
60
|
+
${SHARED_PS2_GLSL_HELPERS}
|
|
61
|
+
`).replace("#include <color_fragment>", `
|
|
62
|
+
if (texture(uAlphaTex, vPs2Uv).r < 0.5) discard;
|
|
63
|
+
|
|
64
|
+
vec4 s0 = pow(max(texture(uSplat0, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));
|
|
65
|
+
vec4 s1 = pow(max(texture(uSplat1, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));
|
|
66
|
+
float totalW = s0.r + s0.g + s0.b + s0.a + s1.r + s1.g + s1.b + s1.a;
|
|
67
|
+
float invW = totalW > 1e-5 ? (1.0 / totalW) : 0.0;
|
|
68
|
+
s0 *= invW;
|
|
69
|
+
s1 *= invW;
|
|
70
|
+
|
|
71
|
+
float bayerWorld = ps2Bayer4x4(vPs2WorldPos.xz * uDitherTexelsPerMeter);
|
|
72
|
+
int winLayer = 7;
|
|
73
|
+
float cdf = s0.r;
|
|
74
|
+
if (bayerWorld < cdf) { winLayer = 0; }
|
|
75
|
+
else if (bayerWorld < (cdf += s0.g)) { winLayer = 1; }
|
|
76
|
+
else if (bayerWorld < (cdf += s0.b)) { winLayer = 2; }
|
|
77
|
+
else if (bayerWorld < (cdf += s0.a)) { winLayer = 3; }
|
|
78
|
+
else if (bayerWorld < (cdf += s1.r)) { winLayer = 4; }
|
|
79
|
+
else if (bayerWorld < (cdf += s1.g)) { winLayer = 5; }
|
|
80
|
+
else if (bayerWorld < (cdf += s1.b)) { winLayer = 6; }
|
|
81
|
+
|
|
82
|
+
vec2 tileUv = vPs2WorldPos.xz * uTileScale;
|
|
83
|
+
vec2 dTileDx = dFdx(tileUv);
|
|
84
|
+
vec2 dTileDy = dFdy(tileUv);
|
|
85
|
+
vec3 splatAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(winLayer)), dTileDx, dTileDy).rgb;
|
|
86
|
+
splatAlbedo *= ps2MacroVariation(vPs2WorldPos.xz);
|
|
87
|
+
|
|
88
|
+
float rawCavity = 1.0;
|
|
89
|
+
#if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)
|
|
90
|
+
rawCavity = vColor.r;
|
|
91
|
+
#endif
|
|
92
|
+
float cavityClamped = clamp(rawCavity, 0.0, 1.0);
|
|
93
|
+
float ridgeLift = max(0.0, rawCavity - 1.0) * 0.85 * uCavityStrength;
|
|
94
|
+
vec3 cavityTint = mix(uCavityShadowTint, vec3(1.0), cavityClamped);
|
|
95
|
+
|
|
96
|
+
diffuseColor.rgb *= splatAlbedo * mix(vec3(1.0), cavityTint, uCavityStrength * 0.45) * (1.0 + ridgeLift);
|
|
97
|
+
`).replace("#include <aomap_fragment>", `
|
|
98
|
+
#include <aomap_fragment>
|
|
99
|
+
#if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)
|
|
100
|
+
float ps2Ao = clamp(vColor.r, 0.0, 1.0);
|
|
101
|
+
float indirectAo = mix(1.0, pow(ps2Ao, 1.45), uCavityStrength);
|
|
102
|
+
float directAo = mix(1.0, mix(0.55, 1.0, ps2Ao), uCavityStrength);
|
|
103
|
+
reflectedLight.indirectDiffuse *= indirectAo;
|
|
104
|
+
reflectedLight.directDiffuse *= directAo;
|
|
105
|
+
#endif
|
|
106
|
+
`).replace("#include <dithering_fragment>", `
|
|
107
|
+
#include <dithering_fragment>
|
|
108
|
+
gl_FragColor.rgb = ps2QuantizeRGB555(
|
|
109
|
+
gl_FragColor.rgb,
|
|
110
|
+
gl_FragCoord.xy,
|
|
111
|
+
uScreenPixelScale,
|
|
112
|
+
uPs2ColorQuantize
|
|
113
|
+
);
|
|
114
|
+
`);
|
|
44
115
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
116
|
+
const depthMaterial = new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking });
|
|
117
|
+
depthMaterial.customProgramCacheKey = () => "ps2-terrain-depth-cutout-v1";
|
|
118
|
+
depthMaterial.onBeforeCompile = (shader) => {
|
|
119
|
+
shader.uniforms.uAlphaTex = uniforms.uAlphaTex;
|
|
120
|
+
shader.vertexShader = shader.vertexShader.replace("#include <common>", "#include <common>\nvarying vec2 vPs2DepthUv;").replace("#include <project_vertex>", "vPs2DepthUv = uv;\n#include <project_vertex>");
|
|
121
|
+
shader.fragmentShader = shader.fragmentShader.replace("#include <common>", "#include <common>\nuniform sampler2D uAlphaTex;\nvarying vec2 vPs2DepthUv;").replace("void main() {", "void main() {\n if (texture(uAlphaTex, vPs2DepthUv).r < 0.5) discard;");
|
|
122
|
+
};
|
|
123
|
+
return {
|
|
124
|
+
material,
|
|
125
|
+
depthMaterial,
|
|
126
|
+
uniforms
|
|
52
127
|
};
|
|
53
128
|
}
|
|
54
|
-
export {
|
|
129
|
+
export { createPS2TerrainMaterialWebGL };
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=ps2TerrainWebGL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ps2TerrainWebGL.js","names":[],"sources":["../../src/shaders/ps2TerrainWebGL.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { SHARED_PS2_GLSL_HELPERS, type PS2TerrainMaterialOptions } from \"./ps2GlslShared.js\";\nimport type { PS2TextureBundle } from \"./ps2Textures.js\";\n\nexport function createPS2TerrainMaterialWebGL(\n textures: PS2TextureBundle,\n opts: PS2TerrainMaterialOptions = {},\n): {\n material: THREE.MeshLambertMaterial;\n depthMaterial: THREE.MeshDepthMaterial;\n uniforms: Record<string, THREE.IUniform>;\n} {\n const uniforms: Record<string, THREE.IUniform> = {\n uSplat0: { value: textures.splat0Tex },\n uSplat1: { value: textures.splat1Tex },\n uAlphaTex: { value: textures.alphaTex },\n uDetailArray: { value: textures.detailArrayTex },\n uTileScale: { value: opts.tileScale ?? 1 / 3 },\n uDitherTexelsPerMeter: { value: opts.ditherTexelsPerMeter ?? 16 },\n uSplatContrast: { value: opts.splatContrast ?? 1.65 },\n uCavityStrength: { value: opts.cavityStrength ?? 1 },\n uCavityShadowTint: { value: new THREE.Color(0x6e788c) },\n uPs2ColorQuantize: { value: opts.ps2ColorQuantize ?? 0.85 },\n uScreenPixelScale: { value: opts.screenPixelScale ?? 1 },\n };\n\n const material = new THREE.MeshLambertMaterial({ vertexColors: true, fog: true });\n material.userData.__kolmoRetroApplied = true;\n material.customProgramCacheKey = () => \"ps2-terrain-splat8-lambert-v1\";\n material.onBeforeCompile = (shader) => {\n Object.assign(shader.uniforms, uniforms);\n shader.vertexShader = shader.vertexShader\n .replace(\"#include <common>\", `\n #include <common>\n varying vec2 vPs2Uv;\n varying vec3 vPs2WorldPos;\n `)\n .replace(\"#include <project_vertex>\", `\n vPs2Uv = uv;\n vec4 ps2Wp = vec4(transformed, 1.0);\n #ifdef USE_INSTANCING\n ps2Wp = instanceMatrix * ps2Wp;\n #endif\n ps2Wp = modelMatrix * ps2Wp;\n vPs2WorldPos = ps2Wp.xyz;\n #include <project_vertex>\n `);\n shader.fragmentShader = shader.fragmentShader\n .replace(\"#include <common>\", `\n #include <common>\n precision mediump sampler2DArray;\n\n uniform sampler2D uSplat0;\n uniform sampler2D uSplat1;\n uniform sampler2D uAlphaTex;\n uniform sampler2DArray uDetailArray;\n\n uniform float uTileScale;\n uniform float uDitherTexelsPerMeter;\n uniform float uSplatContrast;\n uniform float uCavityStrength;\n uniform vec3 uCavityShadowTint;\n uniform float uPs2ColorQuantize;\n uniform float uScreenPixelScale;\n\n varying vec2 vPs2Uv;\n varying vec3 vPs2WorldPos;\n\n ${SHARED_PS2_GLSL_HELPERS}\n `)\n .replace(\"#include <color_fragment>\", `\n if (texture(uAlphaTex, vPs2Uv).r < 0.5) discard;\n\n vec4 s0 = pow(max(texture(uSplat0, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));\n vec4 s1 = pow(max(texture(uSplat1, vPs2Uv), vec4(0.0)), vec4(uSplatContrast));\n float totalW = s0.r + s0.g + s0.b + s0.a + s1.r + s1.g + s1.b + s1.a;\n float invW = totalW > 1e-5 ? (1.0 / totalW) : 0.0;\n s0 *= invW;\n s1 *= invW;\n\n float bayerWorld = ps2Bayer4x4(vPs2WorldPos.xz * uDitherTexelsPerMeter);\n int winLayer = 7;\n float cdf = s0.r;\n if (bayerWorld < cdf) { winLayer = 0; }\n else if (bayerWorld < (cdf += s0.g)) { winLayer = 1; }\n else if (bayerWorld < (cdf += s0.b)) { winLayer = 2; }\n else if (bayerWorld < (cdf += s0.a)) { winLayer = 3; }\n else if (bayerWorld < (cdf += s1.r)) { winLayer = 4; }\n else if (bayerWorld < (cdf += s1.g)) { winLayer = 5; }\n else if (bayerWorld < (cdf += s1.b)) { winLayer = 6; }\n\n vec2 tileUv = vPs2WorldPos.xz * uTileScale;\n vec2 dTileDx = dFdx(tileUv);\n vec2 dTileDy = dFdy(tileUv);\n vec3 splatAlbedo = textureGrad(uDetailArray, vec3(tileUv, float(winLayer)), dTileDx, dTileDy).rgb;\n splatAlbedo *= ps2MacroVariation(vPs2WorldPos.xz);\n\n float rawCavity = 1.0;\n #if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)\n rawCavity = vColor.r;\n #endif\n float cavityClamped = clamp(rawCavity, 0.0, 1.0);\n float ridgeLift = max(0.0, rawCavity - 1.0) * 0.85 * uCavityStrength;\n vec3 cavityTint = mix(uCavityShadowTint, vec3(1.0), cavityClamped);\n\n diffuseColor.rgb *= splatAlbedo * mix(vec3(1.0), cavityTint, uCavityStrength * 0.45) * (1.0 + ridgeLift);\n `)\n .replace(\"#include <aomap_fragment>\", `\n #include <aomap_fragment>\n #if defined(USE_COLOR) || defined(USE_COLOR_ALPHA)\n float ps2Ao = clamp(vColor.r, 0.0, 1.0);\n float indirectAo = mix(1.0, pow(ps2Ao, 1.45), uCavityStrength);\n float directAo = mix(1.0, mix(0.55, 1.0, ps2Ao), uCavityStrength);\n reflectedLight.indirectDiffuse *= indirectAo;\n reflectedLight.directDiffuse *= directAo;\n #endif\n `)\n .replace(\"#include <dithering_fragment>\", `\n #include <dithering_fragment>\n gl_FragColor.rgb = ps2QuantizeRGB555(\n gl_FragColor.rgb,\n gl_FragCoord.xy,\n uScreenPixelScale,\n uPs2ColorQuantize\n );\n `);\n };\n\n const depthMaterial = new THREE.MeshDepthMaterial({ depthPacking: THREE.RGBADepthPacking });\n depthMaterial.customProgramCacheKey = () => \"ps2-terrain-depth-cutout-v1\";\n depthMaterial.onBeforeCompile = (shader) => {\n shader.uniforms.uAlphaTex = uniforms.uAlphaTex;\n shader.vertexShader = shader.vertexShader\n .replace(\"#include <common>\", \"#include <common>\\nvarying vec2 vPs2DepthUv;\")\n .replace(\"#include <project_vertex>\", \"vPs2DepthUv = uv;\\n#include <project_vertex>\");\n shader.fragmentShader = shader.fragmentShader\n .replace(\"#include <common>\", \"#include <common>\\nuniform sampler2D uAlphaTex;\\nvarying vec2 vPs2DepthUv;\")\n .replace(\"void main() {\", \"void main() {\\n if (texture(uAlphaTex, vPs2DepthUv).r < 0.5) discard;\");\n };\n\n return { material, depthMaterial, uniforms };\n}\n"],"mappings":";;;AAIA,SAAgB,8BACZ,UACA,OAAkC,CAAC,GAKrC;CACE,MAAM,WAA2C;EAC7C,SAAS,EAAE,OAAO,SAAS,UAAU;EACrC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6B,8CAA8C;EACxF,OAAO,iBAAiB,OAAO,eAC1B,QAAQ,qBAAqB,4EAA4E,CAAC,CAC1G,QAAQ,iBAAiB,wEAAwE;CAC1G;CAEA,OAAO;EAAE;EAAU;EAAe;CAAS;AAC/C"}
|
|
@@ -18,5 +18,5 @@ export interface PS2TextureBundle {
|
|
|
18
18
|
readonly detailSliceTexs: readonly THREE.DataTexture[];
|
|
19
19
|
readonly dispose: () => void;
|
|
20
20
|
}
|
|
21
|
-
export declare function generatePS2DetailSlices(seed: number, size?: number): Uint8Array[];
|
|
21
|
+
export declare function generatePS2DetailSlices(seed: number, size?: number): Uint8Array<ArrayBuffer>[];
|
|
22
22
|
export declare function createPS2WorldTextures(worldData: WorldGenResult): PS2TextureBundle;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { SplitMix32
|
|
2
|
-
import * as
|
|
1
|
+
import { SplitMix32, hashSeed } from "../world/worldTypes.js";
|
|
2
|
+
import * as THREE from "three";
|
|
3
3
|
// src/shaders/ps2Textures.ts
|
|
4
|
-
var
|
|
4
|
+
var SPLAT_LAYER = {
|
|
5
5
|
DIRT: 0,
|
|
6
6
|
GRASS: 1,
|
|
7
7
|
SAND: 2,
|
|
@@ -11,15 +11,30 @@ var r = {
|
|
|
11
11
|
SNOW: 6,
|
|
12
12
|
ASPHALT: 7
|
|
13
13
|
};
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
function hashTile(ix, iy, period, seed) {
|
|
15
|
+
const wx = (ix % period + period) % period;
|
|
16
|
+
const wy = (iy % period + period) % period;
|
|
17
|
+
let h = Math.imul(wx, 374761393) + Math.imul(wy, 668265263) + seed | 0;
|
|
18
|
+
h = Math.imul(h ^ h >>> 13, 1274126177);
|
|
19
|
+
return ((h ^ h >>> 16) >>> 0) / 4294967296;
|
|
17
20
|
}
|
|
18
|
-
function
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
function tileNoise(u, v, freq, seed) {
|
|
22
|
+
const x = u * freq;
|
|
23
|
+
const y = v * freq;
|
|
24
|
+
const ix = Math.floor(x);
|
|
25
|
+
const iy = Math.floor(y);
|
|
26
|
+
const fx = x - ix;
|
|
27
|
+
const fy = y - iy;
|
|
28
|
+
const sx = fx * fx * (3 - 2 * fx);
|
|
29
|
+
const sy = fy * fy * (3 - 2 * fy);
|
|
30
|
+
const n00 = hashTile(ix, iy, freq, seed);
|
|
31
|
+
const n10 = hashTile(ix + 1, iy, freq, seed);
|
|
32
|
+
const n01 = hashTile(ix, iy + 1, freq, seed);
|
|
33
|
+
const n11 = hashTile(ix + 1, iy + 1, freq, seed);
|
|
34
|
+
return (n00 * (1 - sx) + n10 * sx) * (1 - sy) + (n01 * (1 - sx) + n11 * sx) * sy;
|
|
21
35
|
}
|
|
22
|
-
var
|
|
36
|
+
var clampByte = (v) => Math.max(0, Math.min(255, Math.round(v)));
|
|
37
|
+
var LAYER_PALETTES = [
|
|
23
38
|
{
|
|
24
39
|
base: [
|
|
25
40
|
108,
|
|
@@ -183,42 +198,102 @@ var o = (e) => Math.max(0, Math.min(255, Math.round(e))), s = [
|
|
|
183
198
|
speckle: .42
|
|
184
199
|
}
|
|
185
200
|
];
|
|
186
|
-
function
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
201
|
+
function generatePS2DetailSlices(seed, size = 128) {
|
|
202
|
+
const rng = new SplitMix32(seed);
|
|
203
|
+
const slices = [];
|
|
204
|
+
for (let layer = 0; layer < 8; layer++) {
|
|
205
|
+
const data = new Uint8Array(size * size * 4);
|
|
206
|
+
const pal = LAYER_PALETTES[layer];
|
|
207
|
+
const sA = rng.next() * 2147483647 | 0;
|
|
208
|
+
const sB = rng.next() * 2147483647 | 0;
|
|
209
|
+
const sC = rng.next() * 2147483647 | 0;
|
|
210
|
+
for (let y = 0; y < size; y++) for (let x = 0; x < size; x++) {
|
|
211
|
+
const u = x / size;
|
|
212
|
+
const a = tileNoise(u, y / size * (pal.striateY ?? 1) % 1, pal.freqA, sA);
|
|
213
|
+
const b = tileNoise(u, y / size, pal.freqB, sB);
|
|
214
|
+
const c = hashTile(x, y, size, sC);
|
|
215
|
+
let h = a * .55 + b * .45;
|
|
216
|
+
if (c > 1 - pal.speckle * .35) h = Math.min(1, h + .32);
|
|
217
|
+
else if (c < pal.speckle * .35) h = Math.max(0, h - .3);
|
|
218
|
+
h = Math.round(h * 12) / 12;
|
|
219
|
+
const t = h < .5 ? h * 2 : (h - .5) * 2;
|
|
220
|
+
const c0 = h < .5 ? pal.dark : pal.base;
|
|
221
|
+
const c1 = h < .5 ? pal.base : pal.light;
|
|
222
|
+
const idx = (y * size + x) * 4;
|
|
223
|
+
data[idx] = clampByte(c0[0] * (1 - t) + c1[0] * t);
|
|
224
|
+
data[idx + 1] = clampByte(c0[1] * (1 - t) + c1[1] * t);
|
|
225
|
+
data[idx + 2] = clampByte(c0[2] * (1 - t) + c1[2] * t);
|
|
226
|
+
data[idx + 3] = 255;
|
|
195
227
|
}
|
|
196
|
-
|
|
228
|
+
slices.push(data);
|
|
197
229
|
}
|
|
198
|
-
return
|
|
230
|
+
return slices;
|
|
199
231
|
}
|
|
200
|
-
function
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
232
|
+
function createPS2WorldTextures(worldData) {
|
|
233
|
+
const n = worldData.config.gridCells;
|
|
234
|
+
const makeSplat = (buf) => {
|
|
235
|
+
const tex = new THREE.DataTexture(buf, n, n, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
236
|
+
tex.colorSpace = THREE.NoColorSpace;
|
|
237
|
+
tex.wrapS = THREE.ClampToEdgeWrapping;
|
|
238
|
+
tex.wrapT = THREE.ClampToEdgeWrapping;
|
|
239
|
+
tex.magFilter = THREE.LinearFilter;
|
|
240
|
+
tex.minFilter = THREE.LinearFilter;
|
|
241
|
+
tex.generateMipmaps = false;
|
|
242
|
+
tex.flipY = false;
|
|
243
|
+
tex.needsUpdate = true;
|
|
244
|
+
return tex;
|
|
245
|
+
};
|
|
246
|
+
const splat0Tex = makeSplat(worldData.splat0);
|
|
247
|
+
const splat1Tex = makeSplat(worldData.splat1);
|
|
248
|
+
const alphaTex = new THREE.DataTexture(worldData.alphaMap, n, n, THREE.RedFormat, THREE.UnsignedByteType);
|
|
249
|
+
alphaTex.colorSpace = THREE.NoColorSpace;
|
|
250
|
+
alphaTex.wrapS = THREE.ClampToEdgeWrapping;
|
|
251
|
+
alphaTex.wrapT = THREE.ClampToEdgeWrapping;
|
|
252
|
+
alphaTex.magFilter = THREE.NearestFilter;
|
|
253
|
+
alphaTex.minFilter = THREE.NearestFilter;
|
|
254
|
+
alphaTex.generateMipmaps = false;
|
|
255
|
+
alphaTex.flipY = false;
|
|
256
|
+
alphaTex.needsUpdate = true;
|
|
257
|
+
const slices = generatePS2DetailSlices(hashSeed(worldData.config.seed) ^ 2654435769, 128);
|
|
258
|
+
const arrayData = /* @__PURE__ */ new Uint8Array(524288);
|
|
259
|
+
const detailSliceTexs = [];
|
|
260
|
+
for (let i = 0; i < 8; i++) {
|
|
261
|
+
arrayData.set(slices[i], i * 128 * 128 * 4);
|
|
262
|
+
const tex = new THREE.DataTexture(slices[i], 128, 128, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
263
|
+
tex.colorSpace = THREE.SRGBColorSpace;
|
|
264
|
+
tex.wrapS = THREE.RepeatWrapping;
|
|
265
|
+
tex.wrapT = THREE.RepeatWrapping;
|
|
266
|
+
tex.magFilter = THREE.NearestFilter;
|
|
267
|
+
tex.minFilter = THREE.LinearMipmapNearestFilter;
|
|
268
|
+
tex.generateMipmaps = true;
|
|
269
|
+
tex.needsUpdate = true;
|
|
270
|
+
detailSliceTexs.push(tex);
|
|
211
271
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
272
|
+
const detailArrayTex = new THREE.DataArrayTexture(arrayData, 128, 128, 8);
|
|
273
|
+
detailArrayTex.format = THREE.RGBAFormat;
|
|
274
|
+
detailArrayTex.type = THREE.UnsignedByteType;
|
|
275
|
+
detailArrayTex.colorSpace = THREE.SRGBColorSpace;
|
|
276
|
+
detailArrayTex.wrapS = THREE.RepeatWrapping;
|
|
277
|
+
detailArrayTex.wrapT = THREE.RepeatWrapping;
|
|
278
|
+
detailArrayTex.magFilter = THREE.NearestFilter;
|
|
279
|
+
detailArrayTex.minFilter = THREE.LinearMipmapNearestFilter;
|
|
280
|
+
detailArrayTex.generateMipmaps = true;
|
|
281
|
+
detailArrayTex.needsUpdate = true;
|
|
282
|
+
return {
|
|
283
|
+
splat0Tex,
|
|
284
|
+
splat1Tex,
|
|
285
|
+
alphaTex,
|
|
286
|
+
detailArrayTex,
|
|
287
|
+
detailSliceTexs,
|
|
219
288
|
dispose: () => {
|
|
220
|
-
|
|
289
|
+
splat0Tex.dispose();
|
|
290
|
+
splat1Tex.dispose();
|
|
291
|
+
alphaTex.dispose();
|
|
292
|
+
detailArrayTex.dispose();
|
|
293
|
+
detailSliceTexs.forEach((t) => t.dispose());
|
|
221
294
|
}
|
|
222
295
|
};
|
|
223
296
|
}
|
|
224
|
-
export {
|
|
297
|
+
export { SPLAT_LAYER, createPS2WorldTextures, generatePS2DetailSlices };
|
|
298
|
+
|
|
299
|
+
//# sourceMappingURL=ps2Textures.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ps2Textures.js","names":[],"sources":["../../src/shaders/ps2Textures.ts"],"sourcesContent":["import * as THREE from \"three\";\nimport { SplitMix32, hashSeed, type WorldGenResult } from \"../world/worldTypes.js\";\n\nexport const SPLAT_LAYER = {\n DIRT: 0,\n GRASS: 1,\n SAND: 2,\n ROCK: 3,\n GRAVEL: 4,\n FOREST: 5,\n SNOW: 6,\n ASPHALT: 7,\n} as const;\n\nexport interface PS2TextureBundle {\n readonly splat0Tex: THREE.DataTexture;\n readonly splat1Tex: THREE.DataTexture;\n readonly alphaTex: THREE.DataTexture;\n readonly detailArrayTex: THREE.DataArrayTexture;\n readonly detailSliceTexs: readonly THREE.DataTexture[];\n readonly dispose: () => void;\n}\n\nfunction hashTile(ix: number, iy: number, period: number, seed: number): number {\n const wx = ((ix % period) + period) % period;\n const wy = ((iy % period) + period) % period;\n let h = (Math.imul(wx, 374761393) + Math.imul(wy, 668265263) + seed) | 0;\n h = Math.imul(h ^ (h >>> 13), 1274126177);\n return ((h ^ (h >>> 16)) >>> 0) / 4294967296;\n}\n\nfunction tileNoise(u: number, v: number, freq: number, seed: number): number {\n const x = u * freq;\n const y = v * freq;\n const ix = Math.floor(x);\n const iy = Math.floor(y);\n const fx = x - ix;\n const fy = y - iy;\n const sx = fx * fx * (3 - 2 * fx);\n const sy = fy * fy * (3 - 2 * fy);\n const n00 = hashTile(ix, iy, freq, seed);\n const n10 = hashTile(ix + 1, iy, freq, seed);\n const n01 = hashTile(ix, iy + 1, freq, seed);\n const n11 = hashTile(ix + 1, iy + 1, freq, seed);\n return (n00 * (1 - sx) + n10 * sx) * (1 - sy) + (n01 * (1 - sx) + n11 * sx) * sy;\n}\n\nconst clampByte = (v: number): number => Math.max(0, Math.min(255, Math.round(v)));\n\ninterface LayerPalette {\n base: [number, number, number];\n dark: [number, number, number];\n light: [number, number, number];\n freqA: number;\n freqB: number;\n speckle: number;\n striateY?: number;\n}\n\nconst LAYER_PALETTES: readonly LayerPalette[] = [\n { base: [108, 82, 56], dark: [72, 53, 36], light: [138, 108, 76], freqA: 16, freqB: 48, speckle: 0.28 },\n { base: [86, 114, 52], dark: [58, 82, 34], light: [122, 146, 68], freqA: 20, freqB: 64, speckle: 0.22 },\n { base: [194, 174, 128], dark: [164, 142, 98], light: [218, 202, 158], freqA: 12, freqB: 64, speckle: 0.14, striateY: 3 },\n { base: [112, 110, 106], dark: [68, 66, 64], light: [148, 145, 138], freqA: 14, freqB: 36, speckle: 0.2, striateY: 4.5 },\n { base: [124, 118, 108], dark: [76, 72, 66], light: [168, 162, 150], freqA: 32, freqB: 64, speckle: 0.45 },\n { base: [56, 76, 42], dark: [36, 48, 28], light: [88, 98, 54], freqA: 18, freqB: 52, speckle: 0.26 },\n { base: [222, 228, 236], dark: [182, 194, 212], light: [246, 248, 252], freqA: 12, freqB: 40, speckle: 0.1 },\n { base: [54, 55, 58], dark: [36, 37, 40], light: [86, 88, 92], freqA: 32, freqB: 64, speckle: 0.42 },\n];\n\nexport function generatePS2DetailSlices(seed: number, size = 128): Uint8Array<ArrayBuffer>[] {\n const rng = new SplitMix32(seed);\n const slices: Uint8Array<ArrayBuffer>[] = [];\n for (let layer = 0; layer < 8; layer++) {\n const data = new Uint8Array(size * size * 4);\n const pal = LAYER_PALETTES[layer];\n const sA = (rng.next() * 2147483647) | 0;\n const sB = (rng.next() * 2147483647) | 0;\n const sC = (rng.next() * 2147483647) | 0;\n for (let y = 0; y < size; y++) {\n for (let x = 0; x < size; x++) {\n const u = x / size;\n const a = tileNoise(u, ((y / size) * (pal.striateY ?? 1)) % 1, pal.freqA, sA);\n const b = tileNoise(u, y / size, pal.freqB, sB);\n const c = hashTile(x, y, size, sC);\n let h = a * 0.55 + b * 0.45;\n if (c > 1 - pal.speckle * 0.35)\n h = Math.min(1, h + 0.32);\n else if (c < pal.speckle * 0.35)\n h = Math.max(0, h - 0.3);\n h = Math.round(h * 12) / 12;\n const t = h < 0.5 ? h * 2 : (h - 0.5) * 2;\n const c0 = h < 0.5 ? pal.dark : pal.base;\n const c1 = h < 0.5 ? pal.base : pal.light;\n const idx = (y * size + x) * 4;\n data[idx] = clampByte(c0[0] * (1 - t) + c1[0] * t);\n data[idx + 1] = clampByte(c0[1] * (1 - t) + c1[1] * t);\n data[idx + 2] = clampByte(c0[2] * (1 - t) + c1[2] * t);\n data[idx + 3] = 255;\n }\n }\n slices.push(data);\n }\n return slices;\n}\n\nexport function createPS2WorldTextures(worldData: WorldGenResult): PS2TextureBundle {\n const n = worldData.config.gridCells;\n const makeSplat = (buf: Uint8Array): THREE.DataTexture => {\n const tex = new THREE.DataTexture(buf, n, n, THREE.RGBAFormat, THREE.UnsignedByteType);\n tex.colorSpace = THREE.NoColorSpace;\n tex.wrapS = THREE.ClampToEdgeWrapping;\n tex.wrapT = THREE.ClampToEdgeWrapping;\n tex.magFilter = THREE.LinearFilter;\n tex.minFilter = THREE.LinearFilter;\n tex.generateMipmaps = false;\n tex.flipY = false;\n tex.needsUpdate = true;\n return tex;\n };\n const splat0Tex = makeSplat(worldData.splat0);\n const splat1Tex = makeSplat(worldData.splat1);\n const alphaTex = new THREE.DataTexture(worldData.alphaMap, n, n, THREE.RedFormat, THREE.UnsignedByteType);\n alphaTex.colorSpace = THREE.NoColorSpace;\n alphaTex.wrapS = THREE.ClampToEdgeWrapping;\n alphaTex.wrapT = THREE.ClampToEdgeWrapping;\n alphaTex.magFilter = THREE.NearestFilter;\n alphaTex.minFilter = THREE.NearestFilter;\n alphaTex.generateMipmaps = false;\n alphaTex.flipY = false;\n alphaTex.needsUpdate = true;\n\n const slices = generatePS2DetailSlices(hashSeed(worldData.config.seed) ^ 0x9e3779b9, 128);\n const arrayData = new Uint8Array(128 * 128 * 8 * 4);\n const detailSliceTexs: THREE.DataTexture[] = [];\n for (let i = 0; i < 8; i++) {\n arrayData.set(slices[i], i * 128 * 128 * 4);\n const tex = new THREE.DataTexture(slices[i], 128, 128, THREE.RGBAFormat, THREE.UnsignedByteType);\n tex.colorSpace = THREE.SRGBColorSpace;\n tex.wrapS = THREE.RepeatWrapping;\n tex.wrapT = THREE.RepeatWrapping;\n tex.magFilter = THREE.NearestFilter;\n tex.minFilter = THREE.LinearMipmapNearestFilter;\n tex.generateMipmaps = true;\n tex.needsUpdate = true;\n detailSliceTexs.push(tex);\n }\n const detailArrayTex = new THREE.DataArrayTexture(arrayData, 128, 128, 8);\n detailArrayTex.format = THREE.RGBAFormat;\n detailArrayTex.type = THREE.UnsignedByteType;\n detailArrayTex.colorSpace = THREE.SRGBColorSpace;\n detailArrayTex.wrapS = THREE.RepeatWrapping;\n detailArrayTex.wrapT = THREE.RepeatWrapping;\n detailArrayTex.magFilter = THREE.NearestFilter;\n detailArrayTex.minFilter = THREE.LinearMipmapNearestFilter;\n detailArrayTex.generateMipmaps = true;\n detailArrayTex.needsUpdate = true;\n\n return {\n splat0Tex,\n splat1Tex,\n alphaTex,\n detailArrayTex,\n detailSliceTexs,\n dispose: () => {\n splat0Tex.dispose();\n splat1Tex.dispose();\n alphaTex.dispose();\n detailArrayTex.dispose();\n detailSliceTexs.forEach((t) => t.dispose());\n },\n };\n}\n"],"mappings":";;;AAGA,IAAa,cAAc;CACvB,MAAM;CACN,OAAO;CACP,MAAM;CACN,MAAM;CACN,QAAQ;CACR,QAAQ;CACR,MAAM;CACN,SAAS;AACb;AAWA,SAAS,SAAS,IAAY,IAAY,QAAgB,MAAsB;CAC5E,MAAM,MAAO,KAAK,SAAU,UAAU;CACtC,MAAM,MAAO,KAAK,SAAU,UAAU;CACtC,IAAI,IAAK,KAAK,KAAK,IAAI,SAAS,IAAI,KAAK,KAAK,IAAI,SAAS,IAAI,OAAQ;CACvE,IAAI,KAAK,KAAK,IAAK,MAAM,IAAK,UAAU;CACxC,SAAS,IAAK,MAAM,QAAS,KAAK;AACtC;AAEA,SAAS,UAAU,GAAW,GAAW,MAAc,MAAsB;CACzE,MAAM,IAAI,IAAI;CACd,MAAM,IAAI,IAAI;CACd,MAAM,KAAK,KAAK,MAAM,CAAC;CACvB,MAAM,KAAK,KAAK,MAAM,CAAC;CACvB,MAAM,KAAK,IAAI;CACf,MAAM,KAAK,IAAI;CACf,MAAM,KAAK,KAAK,MAAM,IAAI,IAAI;CAC9B,MAAM,KAAK,KAAK,MAAM,IAAI,IAAI;CAC9B,MAAM,MAAM,SAAS,IAAI,IAAI,MAAM,IAAI;CACvC,MAAM,MAAM,SAAS,KAAK,GAAG,IAAI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c;CAEvB,MAAM,SAAS,wBAAwB,SAAS,UAAU,OAAO,IAAI,IAAI,YAAY,GAAG;CACxF,MAAM,4BAAY,IAAI,WAAW,MAAiB;CAClD,MAAM,kBAAuC,CAAC;CAC9C,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;EACxB,UAAU,IAAI,OAAO,IAAI,IAAI,MAAM,MAAM,CAAC;EAC1C,MAAM,MAAM,IAAI,MAAM,YAAY,OAAO,IAAI,KAAK,KAAK,MAAM,YAAY,MAAM,gBAAgB;EAC/F,IAAI,aAAa,MAAM;EACvB,IAAI,QAAQ,MAAM;EAClB,IAAI,QAAQ,MAAM;EAClB,IAAI,YAAY,MAAM;EACtB,IAAI,YAAY,MAAM;EACtB,IAAI,kBAAkB;EACtB,IAAI,cAAc;EAClB,gBAAgB,KAAK,GAAG;CAC5B;CACA,MAAM,iBAAiB,IAAI,MAAM,iBAAiB,WAAW,KAAK,KAAK,CAAC;CACxE,eAAe,SAAS,MAAM;CAC9B,eAAe,OAAO,MAAM;CAC5B,eAAe,aAAa,MAAM;CAClC,eAAe,QAAQ,MAAM;CAC7B,eAAe,QAAQ,MAAM;CAC7B,eAAe,YAAY,MAAM;CACjC,eAAe,YAAY,MAAM;CACjC,eAAe,kBAAkB;CACjC,eAAe,cAAc;CAE7B,OAAO;EACH;EACA;EACA;EACA;EACA;EACA,eAAe;GACX,UAAU,QAAQ;GAClB,UAAU,QAAQ;GAClB,SAAS,QAAQ;GACjB,eAAe,QAAQ;GACvB,gBAAgB,SAAS,MAAM,EAAE,QAAQ,CAAC;EAC9C;CACJ;AACJ"}
|
|
@@ -9,7 +9,7 @@ export interface RetroColorModeSpec {
|
|
|
9
9
|
export declare const RETRO_COLOR_MODES: readonly RetroColorModeSpec[];
|
|
10
10
|
export declare const PALETTE_CRUNCHY_16: readonly string[];
|
|
11
11
|
export declare const PALETTE_CRUNCHY_64: readonly string[];
|
|
12
|
-
export declare function buildPaletteLutData(paletteHex: readonly string[]): Uint8Array
|
|
12
|
+
export declare function buildPaletteLutData(paletteHex: readonly string[]): Uint8Array<ArrayBuffer>;
|
|
13
13
|
export declare function getPaletteLutTexture(kind: "crunchy16" | "crunchy64" | "fallback"): THREE.DataTexture;
|
|
14
14
|
export declare function getColorQuantVector(mode: RetroColorMode, target?: THREE.Vector4): THREE.Vector4;
|
|
15
15
|
export interface RetroTextureOptions {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as THREE from "three";
|
|
2
2
|
// src/shaders/retroPalettes.ts
|
|
3
|
-
var
|
|
3
|
+
var RETRO_COLOR_MODES = [
|
|
4
4
|
{
|
|
5
5
|
id: "off",
|
|
6
6
|
label: "Off (24-bit)",
|
|
@@ -37,7 +37,8 @@ var t = [
|
|
|
37
37
|
shortLabel: "64-Col",
|
|
38
38
|
description: "64-color indexed LUT"
|
|
39
39
|
}
|
|
40
|
-
]
|
|
40
|
+
];
|
|
41
|
+
var PALETTE_CRUNCHY_16 = [
|
|
41
42
|
"#050811",
|
|
42
43
|
"#141c33",
|
|
43
44
|
"#27395c",
|
|
@@ -54,8 +55,9 @@ var t = [
|
|
|
54
55
|
"#ff6b00",
|
|
55
56
|
"#ffb847",
|
|
56
57
|
"#fff29c"
|
|
57
|
-
]
|
|
58
|
-
|
|
58
|
+
];
|
|
59
|
+
var PALETTE_CRUNCHY_64 = [
|
|
60
|
+
...PALETTE_CRUNCHY_16,
|
|
59
61
|
"#0a1020",
|
|
60
62
|
"#10182b",
|
|
61
63
|
"#1b2742",
|
|
@@ -105,60 +107,81 @@ var t = [
|
|
|
105
107
|
"#505569",
|
|
106
108
|
"#8a91a8"
|
|
107
109
|
];
|
|
108
|
-
function
|
|
109
|
-
|
|
110
|
+
function hexToRgb(hex) {
|
|
111
|
+
const clean = hex.startsWith("#") ? hex.slice(1) : hex;
|
|
112
|
+
const val = Number.parseInt(clean, 16);
|
|
110
113
|
return [
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
val >> 16 & 255,
|
|
115
|
+
val >> 8 & 255,
|
|
116
|
+
val & 255
|
|
114
117
|
];
|
|
115
118
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
119
|
+
function buildPaletteLutData(paletteHex) {
|
|
120
|
+
const rgb = paletteHex.map(hexToRgb);
|
|
121
|
+
const out = /* @__PURE__ */ new Uint8Array(131072);
|
|
122
|
+
for (let g = 0; g < 32; g++) {
|
|
123
|
+
const gg = Math.round(g / 31 * 255);
|
|
124
|
+
for (let b = 0; b < 32; b++) {
|
|
125
|
+
const bb = Math.round(b / 31 * 255);
|
|
126
|
+
for (let r = 0; r < 32; r++) {
|
|
127
|
+
const rr = Math.round(r / 31 * 255);
|
|
128
|
+
let bestDist = Infinity;
|
|
129
|
+
let best = rgb[0];
|
|
130
|
+
for (let i = 0; i < rgb.length; i++) {
|
|
131
|
+
const p = rgb[i];
|
|
132
|
+
const dr = rr - p[0];
|
|
133
|
+
const dg = gg - p[1];
|
|
134
|
+
const db = bb - p[2];
|
|
135
|
+
const dist = 2 * dr * dr + 4 * dg * dg + 3 * db * db;
|
|
136
|
+
if (dist < bestDist) {
|
|
137
|
+
bestDist = dist;
|
|
138
|
+
best = p;
|
|
139
|
+
}
|
|
127
140
|
}
|
|
128
|
-
|
|
129
|
-
|
|
141
|
+
const idx = (g * 1024 + (b * 32 + r)) * 4;
|
|
142
|
+
out[idx] = best[0];
|
|
143
|
+
out[idx + 1] = best[1];
|
|
144
|
+
out[idx + 2] = best[2];
|
|
145
|
+
out[idx + 3] = 255;
|
|
130
146
|
}
|
|
131
147
|
}
|
|
132
148
|
}
|
|
133
|
-
return
|
|
149
|
+
return out;
|
|
134
150
|
}
|
|
135
|
-
function
|
|
136
|
-
|
|
137
|
-
|
|
151
|
+
function makeLutTex(data, w = 1024, h = 32) {
|
|
152
|
+
const tex = new THREE.DataTexture(data, w, h, THREE.RGBAFormat, THREE.UnsignedByteType);
|
|
153
|
+
tex.magFilter = THREE.NearestFilter;
|
|
154
|
+
tex.minFilter = THREE.NearestFilter;
|
|
155
|
+
tex.generateMipmaps = false;
|
|
156
|
+
tex.colorSpace = THREE.NoColorSpace;
|
|
157
|
+
tex.unpackAlignment = 1;
|
|
158
|
+
tex.needsUpdate = true;
|
|
159
|
+
return tex;
|
|
138
160
|
}
|
|
139
|
-
var
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
if (
|
|
143
|
-
|
|
161
|
+
var lutCache = {};
|
|
162
|
+
function getPaletteLutTexture(kind) {
|
|
163
|
+
const cached = lutCache[kind];
|
|
164
|
+
if (cached) return cached;
|
|
165
|
+
const tex = kind === "crunchy16" ? makeLutTex(buildPaletteLutData(PALETTE_CRUNCHY_16)) : kind === "crunchy64" ? makeLutTex(buildPaletteLutData(PALETTE_CRUNCHY_64)) : makeLutTex(new Uint8Array([
|
|
144
166
|
255,
|
|
145
167
|
255,
|
|
146
168
|
255,
|
|
147
169
|
255
|
|
148
170
|
]), 1, 1);
|
|
149
|
-
|
|
171
|
+
lutCache[kind] = tex;
|
|
172
|
+
return tex;
|
|
150
173
|
}
|
|
151
|
-
function
|
|
152
|
-
switch (
|
|
153
|
-
case "off": return
|
|
154
|
-
case "rgb444": return
|
|
155
|
-
case "rgb332": return
|
|
156
|
-
case "crunchy16": return
|
|
157
|
-
case "crunchy64": return
|
|
158
|
-
default: return
|
|
174
|
+
function getColorQuantVector(mode, target = new THREE.Vector4()) {
|
|
175
|
+
switch (mode) {
|
|
176
|
+
case "off": return target.set(255, 255, 255, 0);
|
|
177
|
+
case "rgb444": return target.set(15, 15, 15, 1);
|
|
178
|
+
case "rgb332": return target.set(7, 7, 3, 1);
|
|
179
|
+
case "crunchy16": return target.set(16, .26, 0, 2);
|
|
180
|
+
case "crunchy64": return target.set(64, .14, 0, 2);
|
|
181
|
+
default: return target.set(31, 31, 31, 1);
|
|
159
182
|
}
|
|
160
183
|
}
|
|
161
|
-
var
|
|
184
|
+
var TEX_SLOTS = [
|
|
162
185
|
"map",
|
|
163
186
|
"normalMap",
|
|
164
187
|
"roughnessMap",
|
|
@@ -167,22 +190,32 @@ var u = [
|
|
|
167
190
|
"bumpMap",
|
|
168
191
|
"aoMap"
|
|
169
192
|
];
|
|
170
|
-
function
|
|
171
|
-
if (!
|
|
172
|
-
|
|
173
|
-
|
|
193
|
+
function applyRetroTextureFiltering(texture, opts) {
|
|
194
|
+
if (!texture) return texture;
|
|
195
|
+
const pixelated = opts?.pixelated !== false;
|
|
196
|
+
const mipmaps = opts?.mipmaps !== false;
|
|
197
|
+
texture.magFilter = pixelated ? THREE.NearestFilter : THREE.LinearFilter;
|
|
198
|
+
texture.generateMipmaps = mipmaps;
|
|
199
|
+
texture.minFilter = mipmaps ? THREE.NearestMipmapLinearFilter : pixelated ? THREE.NearestFilter : THREE.LinearFilter;
|
|
200
|
+
if (typeof opts?.anisotropy === "number" && Number.isFinite(opts.anisotropy)) texture.anisotropy = Math.max(1, Math.round(opts.anisotropy));
|
|
201
|
+
texture.needsUpdate = true;
|
|
202
|
+
return texture;
|
|
174
203
|
}
|
|
175
|
-
function
|
|
176
|
-
if (!
|
|
177
|
-
|
|
178
|
-
for (
|
|
179
|
-
|
|
180
|
-
|
|
204
|
+
function applyRetroFilteringToMaterial(material, opts) {
|
|
205
|
+
if (!material) return;
|
|
206
|
+
const record = material;
|
|
207
|
+
for (const slot of TEX_SLOTS) {
|
|
208
|
+
const tex = record[slot];
|
|
209
|
+
if (tex && typeof tex === "object" && tex.isTexture) applyRetroTextureFiltering(tex, opts);
|
|
181
210
|
}
|
|
182
211
|
}
|
|
183
|
-
function
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
212
|
+
function computeRetroDpr(renderScale, isSoftGl = false, devicePixelRatio) {
|
|
213
|
+
if (isSoftGl) return .5;
|
|
214
|
+
const winDpr = typeof window !== "undefined" && Number.isFinite(window.devicePixelRatio) && window.devicePixelRatio > 0 ? window.devicePixelRatio : 1;
|
|
215
|
+
const base = Math.min(2, Math.max(1, Math.round(typeof devicePixelRatio === "number" && Number.isFinite(devicePixelRatio) && devicePixelRatio > 0 ? devicePixelRatio : winDpr)));
|
|
216
|
+
const s = THREE.MathUtils.clamp(Number.isFinite(renderScale) ? renderScale : .67, .33, 1);
|
|
217
|
+
return s >= .98 ? base : base / Math.max(1, Math.round(base / s));
|
|
187
218
|
}
|
|
188
|
-
export {
|
|
219
|
+
export { PALETTE_CRUNCHY_16, PALETTE_CRUNCHY_64, RETRO_COLOR_MODES, applyRetroFilteringToMaterial, applyRetroTextureFiltering, buildPaletteLutData, computeRetroDpr, getColorQuantVector, getPaletteLutTexture };
|
|
220
|
+
|
|
221
|
+
//# sourceMappingURL=retroPalettes.js.map
|