修复水面下岸不正常
This commit is contained in:
@@ -146,7 +146,7 @@ export class OceanScene {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.water.rotation.x = -Math.PI / 2;
|
this.water.rotation.x = -Math.PI / 2;
|
||||||
this.water.position.y = 0;
|
this.water.position.y = -0.15;
|
||||||
this.scene.add(this.water);
|
this.scene.add(this.water);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ export class TerrainGenerator {
|
|||||||
this.maxHeight = options.maxHeight || 50;
|
this.maxHeight = options.maxHeight || 50;
|
||||||
this.waterLevel = options.waterLevel || 0;
|
this.waterLevel = options.waterLevel || 0;
|
||||||
this.beachWidth = options.beachWidth || 20;
|
this.beachWidth = options.beachWidth || 20;
|
||||||
|
this.shoreWidth = options.shoreWidth || 3.5;
|
||||||
|
this.shoreDepth = options.shoreDepth || 1.5;
|
||||||
|
|
||||||
this.noise = new SimplexNoise(options.seed || 42);
|
this.noise = new SimplexNoise(options.seed || 42);
|
||||||
this.terrain = null;
|
this.terrain = null;
|
||||||
@@ -64,21 +66,33 @@ export class TerrainGenerator {
|
|||||||
|
|
||||||
const distFromCenter = Math.sqrt(x * x + y * y);
|
const distFromCenter = Math.sqrt(x * x + y * y);
|
||||||
const maxLandDist = this.size * 0.45;
|
const maxLandDist = this.size * 0.45;
|
||||||
const falloffStart = this.size * 0.25;
|
const falloffStart = this.size * 0.2;
|
||||||
|
|
||||||
let continentMask = 1.0;
|
let continentMask = 1.0;
|
||||||
|
let edgeDepth = 0;
|
||||||
if (distFromCenter > falloffStart) {
|
if (distFromCenter > falloffStart) {
|
||||||
const t = (distFromCenter - falloffStart) / (maxLandDist - falloffStart);
|
const t = (distFromCenter - falloffStart) / (maxLandDist - falloffStart);
|
||||||
continentMask = Math.max(0, 1 - Math.pow(t, 1.5));
|
continentMask = Math.max(0, 1 - Math.pow(t, 1.2));
|
||||||
|
edgeDepth = -15 * Math.pow(Math.max(0, t), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
height = height * continentMask;
|
height = height * continentMask + edgeDepth;
|
||||||
height = height * this.maxHeight * 0.4;
|
height = height * this.maxHeight * 0.5;
|
||||||
|
|
||||||
const beachZone = 2;
|
const shoreMin = this.waterLevel - this.shoreWidth;
|
||||||
if (height > this.waterLevel && height < this.waterLevel + beachZone) {
|
const shoreMax = this.waterLevel + this.shoreWidth;
|
||||||
const blend = Math.max(0, Math.min(1, (height - this.waterLevel) / beachZone));
|
if (height > shoreMin && height < shoreMax) {
|
||||||
height = this.waterLevel + Math.pow(blend, 0.5) * beachZone;
|
if (height < this.waterLevel) {
|
||||||
|
const t = (height - shoreMin) / (this.waterLevel - shoreMin);
|
||||||
|
height = this.waterLevel - this.shoreDepth * Math.pow(1 - t, 1.35);
|
||||||
|
} else {
|
||||||
|
const t = (height - this.waterLevel) / (shoreMax - this.waterLevel);
|
||||||
|
height = this.waterLevel + Math.pow(t, 0.75) * this.shoreWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.abs(height - this.waterLevel) < 0.06) {
|
||||||
|
height = this.waterLevel - 0.06;
|
||||||
}
|
}
|
||||||
|
|
||||||
return height;
|
return height;
|
||||||
@@ -97,18 +111,18 @@ export class TerrainGenerator {
|
|||||||
|
|
||||||
let color = new THREE.Color();
|
let color = new THREE.Color();
|
||||||
|
|
||||||
if (normalizedHeight < -0.1) {
|
if (height < this.waterLevel - 1.5) {
|
||||||
color.copy(deepWater);
|
color.copy(deepWater);
|
||||||
} else if (normalizedHeight < 0) {
|
} else if (height < this.waterLevel) {
|
||||||
color.lerpColors(deepWater, shallowWater, (normalizedHeight + 0.1) / 0.1);
|
const shallowBlend = (height - (this.waterLevel - 1.5)) / 1.5;
|
||||||
} else if (normalizedHeight < 0.05) {
|
color.lerpColors(deepWater, shallowWater, THREE.MathUtils.clamp(shallowBlend, 0, 1));
|
||||||
const beachBlend = Math.min(1, normalizedHeight / 0.05);
|
} else if (normalizedHeight < 0.08) {
|
||||||
color.lerpColors(shallowWater, beach, beachBlend);
|
color.copy(beach);
|
||||||
} else if (normalizedHeight < 0.15) {
|
} else if (normalizedHeight < 0.18) {
|
||||||
const sandToGrass = (normalizedHeight - 0.05) / 0.1;
|
const sandToGrass = (normalizedHeight - 0.08) / 0.1;
|
||||||
color.lerpColors(beach, grass, sandToGrass);
|
color.lerpColors(beach, grass, sandToGrass);
|
||||||
} else if (normalizedHeight < 0.4) {
|
} else if (normalizedHeight < 0.4) {
|
||||||
const grassBlend = (normalizedHeight - 0.15) / 0.25;
|
const grassBlend = (normalizedHeight - 0.18) / 0.22;
|
||||||
color.lerpColors(grass, darkGrass, grassBlend);
|
color.lerpColors(grass, darkGrass, grassBlend);
|
||||||
} else if (normalizedHeight < 0.6) {
|
} else if (normalizedHeight < 0.6) {
|
||||||
const rockBlend = (normalizedHeight - 0.4) / 0.2;
|
const rockBlend = (normalizedHeight - 0.4) / 0.2;
|
||||||
|
|||||||
Reference in New Issue
Block a user