From 47ed806ce5c2b4a1d2b39e959025a50fdf9f0ff9 Mon Sep 17 00:00:00 2001 From: Jasper Date: Wed, 1 Nov 2023 13:01:32 -0600 Subject: [PATCH] minor bug fixes --- src/scenes/Space.svelte | 13 ++++++++++--- src/shaders/stars/Stars.js | 37 +++++++++++++++++++++---------------- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/scenes/Space.svelte b/src/scenes/Space.svelte index 419e5c5..db1c498 100644 --- a/src/scenes/Space.svelte +++ b/src/scenes/Space.svelte @@ -46,7 +46,8 @@ }) const Sky = createSky() - const Stars = createStars() + let starsPoints + const Stars = createStars().then(s => starsPoints = s) const DEG = Math.PI / 180 @@ -76,7 +77,12 @@ get FOV(){ return FOV }, set FOV(v){ return FOV = v }, get exposure(){ return Sky.exposure }, - set exposure(v){ return Sky.exposure = v }, + set exposure(v){ + Sky.exposure = v + if (!starsPoints) return + starsPoints.material.uniforms.exposure.value = v + starsPoints.material.uniforms.exposure.needsUpdate = true + }, get totalityFactor(){ return totalityFactor }, set totalityFactor(value){ totalityFactor = value }, doAnimation: true, @@ -279,7 +285,7 @@ // resolution: 256, // middleGrey: 0.6, whitePoint: 10, - minLuminance: 0.1, + minLuminance: 0.01, averageLuminance: 1, adaptationRate: 10 }), @@ -319,6 +325,7 @@ ref.lookAt(sun.position) rig = new CameraRig(ref, scene) controls = new FreeMovementControls(rig, { + domElement: renderer.domElement, tiltDegreeFactor: Math.PI / 6, panDegreeFactor: Math.PI / 6, }) diff --git a/src/shaders/stars/Stars.js b/src/shaders/stars/Stars.js index 8760281..26ed5e3 100644 --- a/src/shaders/stars/Stars.js +++ b/src/shaders/stars/Stars.js @@ -1,27 +1,30 @@ import * as THREE from 'three' import bsc5datUrl from '../../assets/bsc5.dat?url' +const brightnessAdjustment = 0.8 + function vertexShader() { return ` - attribute float size; - attribute vec4 color; - varying vec4 vColor; - void main() { - vColor = color; - vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); - gl_PointSize = size * ( 250.0 / -mvPosition.z ); - gl_Position = projectionMatrix * mvPosition; - } - ` + attribute float size; + attribute vec4 color; + varying vec4 vColor; + void main() { + vColor = color; + vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 ); + gl_PointSize = size * ( 250.0 / -mvPosition.z ); + gl_Position = projectionMatrix * mvPosition; + } + ` } function fragmentShader() { return ` - varying vec4 vColor; - void main() { - gl_FragColor = vec4( vColor ); - } - ` + varying vec4 vColor; + uniform float exposure; + void main() { + gl_FragColor = 1.0 - exp(-exposure * vec4( vColor )); + } + ` } export default async function createStars(){ @@ -90,7 +93,7 @@ export default async function createStars(){ const s = (star.mag * 26) / 255 + 0.18 sizes.push(s) - colors.push(color.r, color.g, color.b, s) + colors.push(color.r, color.g, color.b, s * brightnessAdjustment) }) const starsGeometry = new THREE.BufferGeometry() @@ -104,5 +107,7 @@ export default async function createStars(){ transparent: true, }) + starsMaterial.uniforms.exposure = { value: 1.0 } + return new THREE.Points(starsGeometry, starsMaterial) } \ No newline at end of file