feat(environment): add adaptive atmospheric fog
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled
🔍 Lint / 🪄 Check lint (pull_request) Has been cancelled
🔍 Lint / 🎨 Check format (pull_request) Has been cancelled
🔍 Lint / 🔎 Typecheck (pull_request) Has been cancelled
📊 Quality / 🔒 Security Audit (pull_request) Has been cancelled
📊 Quality / 📋 Dependency Freshness (pull_request) Has been cancelled
📊 Quality / 📦 Bundle Size (pull_request) Has been cancelled
🔍 Lint / 🏗 Build (pull_request) Has been cancelled
This commit is contained in:
@@ -44,8 +44,10 @@ export function WaterSurface({
|
||||
uOpacity: { value: WATER_SHADER_CONFIG.opacity },
|
||||
uDeepOpacity: { value: WATER_SHADER_CONFIG.deepOpacity },
|
||||
uFogEnabled: { value: 0 },
|
||||
uFogMode: { value: 0 },
|
||||
uFogNear: { value: FOG_CONFIG.near },
|
||||
uFogFar: { value: FOG_CONFIG.far },
|
||||
uFogDensity: { value: FOG_CONFIG.density },
|
||||
uFogColor: { value: new THREE.Color(FOG_CONFIG.color) },
|
||||
}),
|
||||
[],
|
||||
@@ -61,8 +63,10 @@ export function WaterSurface({
|
||||
uFlowX,
|
||||
uFlowZ,
|
||||
uFogColor,
|
||||
uFogDensity,
|
||||
uFogEnabled,
|
||||
uFogFar,
|
||||
uFogMode,
|
||||
uFogNear,
|
||||
uNoiseScale,
|
||||
uTime,
|
||||
@@ -77,9 +81,15 @@ export function WaterSurface({
|
||||
|
||||
if (scene.fog instanceof THREE.Fog) {
|
||||
if (uFogEnabled) uFogEnabled.value = 1;
|
||||
if (uFogMode) uFogMode.value = 0;
|
||||
if (uFogNear) uFogNear.value = scene.fog.near;
|
||||
if (uFogFar) uFogFar.value = scene.fog.far;
|
||||
if (uFogColor) uFogColor.value.copy(scene.fog.color);
|
||||
} else if (scene.fog instanceof THREE.FogExp2) {
|
||||
if (uFogEnabled) uFogEnabled.value = 1;
|
||||
if (uFogMode) uFogMode.value = 1;
|
||||
if (uFogDensity) uFogDensity.value = scene.fog.density;
|
||||
if (uFogColor) uFogColor.value.copy(scene.fog.color);
|
||||
} else if (uFogEnabled) {
|
||||
uFogEnabled.value = 0;
|
||||
}
|
||||
|
||||
@@ -33,8 +33,10 @@ export const WATER_FRAGMENT_SHADER = /* glsl */ `
|
||||
uniform float uOpacity;
|
||||
uniform float uDeepOpacity;
|
||||
uniform float uFogEnabled;
|
||||
uniform float uFogMode;
|
||||
uniform float uFogNear;
|
||||
uniform float uFogFar;
|
||||
uniform float uFogDensity;
|
||||
uniform vec3 uFogColor;
|
||||
|
||||
varying vec2 vUv;
|
||||
@@ -152,6 +154,12 @@ export const WATER_FRAGMENT_SHADER = /* glsl */ `
|
||||
if (uFogEnabled > 0.5) {
|
||||
float fogDistance = distance(cameraPosition, vWorldPosition);
|
||||
float fogFactor = smoothstep(uFogNear, uFogFar, fogDistance);
|
||||
|
||||
if (uFogMode > 0.5) {
|
||||
fogFactor = 1.0 - exp(-uFogDensity * uFogDensity * fogDistance * fogDistance);
|
||||
}
|
||||
|
||||
fogFactor = clamp(fogFactor, 0.0, 1.0);
|
||||
color = mix(color, uFogColor, fogFactor);
|
||||
alpha *= 1.0 - fogFactor;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user