Skip to content

Commit

Permalink
fix fog and brightness for sunset
Browse files Browse the repository at this point in the history
  • Loading branch information
wellcaffeinated committed Jan 16, 2024
1 parent cab1f09 commit 28c018b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/entities/Earth.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const textures = useLoader(TextureLoader).load({
renderOrder={2}
>
<T.HemisphereLight
intensity={sunBrightness}
intensity={sunBrightness * 0.25 + 0.1}
position={[0, 100, 0]}
/>
<T.DirectionalLight
Expand Down
2 changes: 1 addition & 1 deletion src/entities/Terrain.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
coords.y = 0.5 + Math.sin(theta) * r;
}
const material = new THREE.MeshStandardMaterial({color: 0x000000})
const material = new THREE.MeshStandardMaterial({ color: 0x000000, dithering: true })
const terrainScene = Terrain({
easing: Terrain.EaseInOut,
Expand Down
9 changes: 6 additions & 3 deletions src/scenes/Space.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@
let sunBrightness = 1
$: sunIntensity = sunBrightness * 10000000 * Lsol / (4 * Math.PI * Math.pow(sunDistance, 2))
$: sunsetBrightness = MathUtils.clamp(MathUtils.inverseLerp(-10, 20, elevation / DEG), 0, 1)
const createExpotentialIn = (a) => {
return (x) => Math.pow(2, a * x - a) * x
Expand Down Expand Up @@ -283,15 +284,17 @@
controls?.update(window.performance.now())
const state = moonMove.at(time / 2)
moonDec = state.theta * DEG
sunBrightness = state.brightness
sunBrightness = state.brightness * sunsetBrightness
})
let fog
$: r0 = new Vector3(0, -planetRadius, 0)
$: Sky.sunPosition.set(...sunPosition).sub(r0).multiplyScalar(1 / METER)
$: Sky.sunRadius = sunRadius / METER
$: moonPosition = skyPosition(moonDistance, elevation, 0, new Vector3()).applyAxisAngle(moonAxis, moonDec)
$: Sky.moonPosition.set(...moonPosition).sub(r0).multiplyScalar(1 / METER)
$: Sky.moonRadius = moonRadius / METER
$: fog?.color.setHSL(200, 0.2, Easing.sinIn(sunBrightness) * 0.15)
const composer = new EffectComposer(renderer, {
frameBufferType: THREE.HalfFloatType,
Expand Down Expand Up @@ -334,10 +337,9 @@
// adaptive: true,
// resolution: 256,
// middleGrey: 0.6,
resolution: 512,
// resolution: 512,
whitePoint: 2,
minLuminance: 0.005,
averageLuminance: .2,
adaptationRate: 2
}),
)
Expand All @@ -354,6 +356,7 @@
<Stats />
<T.AmbientLight intensity={0.02}/>
<T.FogExp2 attach="fog" bind:ref={fog} far={90000} density={2.5e-5}/>
<!-- <Sky elevation={0.1} /> -->
<!-- <T.HemisphereLight
intensity={sunBrightness * 0.2}
Expand Down

0 comments on commit 28c018b

Please sign in to comment.