调整海岸边缘

This commit is contained in:
2026-03-26 11:15:13 +08:00
parent 2061e97d5c
commit 3593a39fc7
2 changed files with 20 additions and 8 deletions

View File

@@ -291,6 +291,7 @@ export class OceanScene {
maxHeight: 34, // 海面以上地形的最大起伏高度
waterLevel: 0, // 海平面基准高度
underwaterDepthBias: 4.5, // 整体压低海面以下地形,避免浅滩露出
underwaterBiasFadeWidth: 8, // 水下额外下沉的渐变宽度,越大近岸越平滑
landBias: 0.2, // 整体抬升陆地倾向,增大陆地露出面积
falloffStartRatio: 0.22, // 从中心向外开始下沉的起始比例
maxLandRatio: 0.46, // 大陆海岸线的大致外缘比例
@@ -299,7 +300,8 @@ export class OceanScene {
continentLift: 0.55, // 核心大陆的额外抬升强度
coastVariance: 0.05, // 海岸线形状起伏幅度,越大越不规则
outerShelfDepth: 4, // 大陆外侧陆架的额外下沉深度
seed: 42 // 固定随机种子,保证地形稳定复现
coastlineBlendWidth: 42, // 海岸线外侧过渡到海底的缓冲宽度
seed: 23 // 固定随机种子,保证地形稳定复现
});
this.terrain = terrainGen.generate();
@@ -317,8 +319,8 @@ export class OceanScene {
terrainSize: 1200, // 随机植被允许分布的地形范围
waterLevel: 1, // 植被生成时参考的水位,避免贴近海边
treePlacements: [ // 手动指定树木坐标
{ x: -180, z: -120, rotation: 0.4, scale: 1.6 },
{ x: -120, z: -40, rotation: 1.2, scale: 1.35 },
{ x: 0, z: 50, rotation: 0.4, scale: 1.6 },
{ x: 21, z: 32, rotation: 1.2, scale: 1.35 },
// { x: -40, z: -150, rotation: 2.1, scale: 1.75 },
// { x: 70, z: -70, rotation: 2.8, scale: 1.45 },
// { x: 135, z: 15, rotation: 4.1, scale: 1.55 },

View File

@@ -11,6 +11,7 @@ export class TerrainGenerator {
this.shoreWidth = options.shoreWidth || 3.5;
this.shoreDepth = options.shoreDepth || 1.5;
this.underwaterDepthBias = options.underwaterDepthBias || 3.5;
this.underwaterBiasFadeWidth = options.underwaterBiasFadeWidth || 6;
this.landBias = options.landBias ?? 0.18;
this.falloffStartRatio = options.falloffStartRatio || 0.24;
this.maxLandRatio = options.maxLandRatio || 0.48;
@@ -19,6 +20,7 @@ export class TerrainGenerator {
this.continentLift = options.continentLift || 0.35;
this.coastVariance = options.coastVariance || 0.08;
this.outerShelfDepth = options.outerShelfDepth || 2.5;
this.coastlineBlendWidth = options.coastlineBlendWidth || 32;
this.noise = new SimplexNoise(options.seed || 42);
this.terrain = null;
@@ -96,7 +98,8 @@ export class TerrainGenerator {
let edgeDepth = 0;
if (distFromCenter > falloffStart) {
const t = (distFromCenter - falloffStart) / Math.max(0.0001, coastlineRadius - falloffStart);
continentMask = Math.max(0, 1 - Math.pow(t, 1.2));
const easedT = THREE.MathUtils.smoothstep(t, 0, 1);
continentMask = Math.max(0, 1 - Math.pow(easedT, 1.05));
edgeDepth = -this.edgeDepth * Math.pow(Math.max(0, t), 2);
}
@@ -105,12 +108,13 @@ export class TerrainGenerator {
if (distFromCenter > coastlineRadius) {
const t = THREE.MathUtils.clamp(
(distFromCenter - coastlineRadius) / (this.size * 0.08),
(distFromCenter - coastlineRadius) / this.coastlineBlendWidth,
0,
1
);
const forcedSeaFloor = this.waterLevel - this.outerShelfDepth * Math.pow(t, 1.1);
height = Math.min(height, forcedSeaFloor);
const forcedSeaFloor = this.waterLevel - this.outerShelfDepth * THREE.MathUtils.smoothstep(t, 0, 1);
const blend = THREE.MathUtils.smootherstep(t, 0, 1);
height = THREE.MathUtils.lerp(height, Math.min(height, forcedSeaFloor), blend);
}
const shoreMin = this.waterLevel - this.shoreWidth;
@@ -126,7 +130,13 @@ export class TerrainGenerator {
}
if (height < this.waterLevel) {
height -= this.underwaterDepthBias;
const underwaterDepth = THREE.MathUtils.clamp(this.waterLevel - height, 0, this.underwaterBiasFadeWidth);
const biasStrength = THREE.MathUtils.smootherstep(
underwaterDepth / this.underwaterBiasFadeWidth,
0,
1
);
height -= this.underwaterDepthBias * biasStrength;
}
if (Math.abs(height - this.waterLevel) < 0.06) {