Skip to content

Commit

Permalink
minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
wellcaffeinated committed Nov 1, 2023
1 parent 469d422 commit 47ed806
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
13 changes: 10 additions & 3 deletions src/scenes/Space.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
})
const Sky = createSky()
const Stars = createStars()
let starsPoints
const Stars = createStars().then(s => starsPoints = s)
const DEG = Math.PI / 180
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -279,7 +285,7 @@
// resolution: 256,
// middleGrey: 0.6,
whitePoint: 10,
minLuminance: 0.1,
minLuminance: 0.01,
averageLuminance: 1,
adaptationRate: 10
}),
Expand Down Expand Up @@ -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,
})
Expand Down
37 changes: 21 additions & 16 deletions src/shaders/stars/Stars.js
Original file line number Diff line number Diff line change
@@ -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(){
Expand Down Expand Up @@ -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()
Expand All @@ -104,5 +107,7 @@ export default async function createStars(){
transparent: true,
})

starsMaterial.uniforms.exposure = { value: 1.0 }

return new THREE.Points(starsGeometry, starsMaterial)
}

0 comments on commit 47ed806

Please sign in to comment.