Skip to content

Commit

Permalink
scale all parameters in an attempt to fix artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
wellcaffeinated committed Apr 3, 2024
1 parent b7d989c commit 4f962ff
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
30 changes: 16 additions & 14 deletions src/entities/Sky.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,20 @@
return null
}
$: scale = 1e-6
$: Sky.cameraScale = scale
$: Sky.moonTexture = getTexture(textures, $selectedMoon)
$: Sky.sunIntensity = $sunIntensity
$: Sky.rayleighCoefficients = $rayleighCoefficient
$: Sky.rayleighScaleHeight = $rayleighScaleHeight
$: Sky.mieCoefficients = $mieCoefficient
$: Sky.rayleighCoefficients = $rayleighCoefficient.clone().multiplyScalar(1/scale)
$: Sky.rayleighScaleHeight = $rayleighScaleHeight * scale
$: Sky.mieCoefficients = $mieCoefficient.clone().multiplyScalar(1/scale)
$: Sky.mieWavelengthResponse = $mieWavelengthResponse
$: Sky.mieScaleHeight = $mieScaleHeight
$: Sky.mieScaleHeight = $mieScaleHeight * scale
$: Sky.mieDirectional = $mieDirectional
$: Sky.mieBaseline = $mieBaseline
$: Sky.ozoneLayerHeight = $ozoneLayerHeight
$: Sky.ozoneLayerWidth = $ozoneLayerWidth
$: Sky.ozoneCoefficients = $ozoneCoefficients
$: Sky.ozoneLayerHeight = $ozoneLayerHeight * scale
$: Sky.ozoneLayerWidth = $ozoneLayerWidth * scale
$: Sky.ozoneCoefficients = $ozoneCoefficients.clone().multiplyScalar(1/scale)
// $: Sky.exposure = $exposure
$: Sky.iSteps = $iSteps
$: Sky.jSteps = $jSteps
Expand All @@ -88,14 +90,14 @@
$: Sky.cloudThreshold = $cloudThreshold
$: Sky.cloudAbsorption = $cloudAbsorption
$: Sky.windSpeed = $windSpeed
$: Sky.atmosphereThickness = $atmosphereThickness
$: Sky.planetRadius = $planetRadius
$: Sky.sunPosition.set(...$sunPosition)
$: Sky.sunRadius = $sunRadius / METER
$: Sky.moonPosition.copy($moonPosition)
$: Sky.moonRadius = $moonRadius / METER
$: Sky.atmosphereThickness = $atmosphereThickness * scale
$: Sky.planetRadius = $planetRadius * scale
$: Sky.sunPosition.set(...$sunPosition).multiplyScalar(scale)
$: Sky.sunRadius = $sunRadius / METER * scale
$: Sky.moonPosition.copy($moonPosition).multiplyScalar(scale)
$: Sky.moonRadius = $moonRadius / METER * scale
$: Sky.fisheye = fisheye
$: Sky.uAltitude = $altitude
$: Sky.uAltitude = ($altitude + 1) * scale
// $: Sky.shader.blendEquation = $altitude > $atmosphereThickness * 0.9 ? THREE.AddEquation : THREE.MaxEquation
Expand Down
1 change: 1 addition & 0 deletions src/shaders/sky/Sky.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default () => {

const uniforms = {
opacity: 1,
cameraScale: 1,
planetColor: new THREE.Color(0x111111),
moonPosition: new THREE.Vector3(0, 0, 0),
moonRadius: 0.2727 * Re,
Expand Down
7 changes: 4 additions & 3 deletions src/shaders/sky/fragment.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ vec4 scattering(
opacity = mix(1., opacity, avgUmbra);
}
// add the clouds
color = color * (1. - cloudAbsorptionAmount) + cloud;
color = color * (1. - cloudAbsorptionAmount) + cloud;
return vec4(I0 * clamp(color, 0.0, 1.0), clamp(opacity, 0.0, 1.0));
}

Expand All @@ -630,7 +630,8 @@ void main() {

// if the ray intersects the planet, return planet color
bool planet_intersected = intersectsInside(intPlanet);
if (altitude < 2000.){
float z = altitude / atmosphereThickness;
if (z < 0.025){
if(planet_intersected) {
gl_FragColor = vec4(planetColor, 1.);
return;
Expand All @@ -656,7 +657,7 @@ void main() {

// as we get closer to the planet, the atmosphere should get darker
if (planet_intersected){
float k = remap(altitude, 2000., 4000., 0., 1.);
float k = remap(z, 0.025, 0.05, 0., 1.);
color = mix(vec4(planetColor, 1.), color, k);
} else {
// color = color * (1.0 + 0.8 * fbm(vUv * 100.));
Expand Down
4 changes: 3 additions & 1 deletion src/shaders/sky/vertex.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ varying float altitude;
varying vec3 origin;
varying float sunVisibleArea;

uniform float cameraScale;
uniform bool fisheye;
uniform float uAltitude;
uniform vec3 sunPosition;
Expand All @@ -29,7 +30,8 @@ void main() {
gl_Position.z = gl_Position.w; // set z to camera.far... not sure why though

origin = (modelMatrix * vec4(0.0, 0.0, 0.0, 1.0)).xyz;
rayOrigin = fisheye ? vec3(0., planetRadius + uAltitude + 1.0, 0.0) : cameraPosition - origin + vec3(0, 1.0, 0);
rayOrigin = fisheye ? vec3(0., planetRadius + uAltitude, 0.0) : (cameraPosition - origin + vec3(0, 1.0, 0)) * cameraScale;
// rayOrigin = vec3(0., planetRadius + uAltitude, 0.0);
altitude = length(rayOrigin) - planetRadius;
vec3 groundOrigin = normalize(rayOrigin) * planetRadius;

Expand Down

0 comments on commit 4f962ff

Please sign in to comment.