933 added disableSunDisk option

This commit is contained in:
Zemledelec 2025-10-09 14:45:30 +02:00
parent ec3676e2a5
commit 3335030d34
6 changed files with 88 additions and 8 deletions

30
sandbox/clamp/osm.html Normal file
View File

@ -0,0 +1,30 @@
<html>
<head>
<title>OpenStreetMap Base Layer</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./osm.js" type="module"></script>
<link rel="stylesheet" href="../../css/og.css" type="text/css"/>
<style>
body {
padding: 0;
margin: 0;
}
</style>
</head>
<body>
<div style="
width: 100%;
height: 100%;
position: absolute;
background-color: green;
z-index: -1;
">Hello world!</div>
<div id="earth" style="width:100%;height:100%"></div>
</body>
</html>

36
sandbox/clamp/osm.js Normal file
View File

@ -0,0 +1,36 @@
import {
Globe,
Vector,
GlobusRgbTerrain,
OpenStreetMap,
Bing,
Object3d,
Vec3,
Entity,
control,
LonLat,
Gltf
} from "../../lib/og.es.js";
let objLayer = new Vector("Obj.Layer", {
scaleByDistance: [50, 50000, 1]
});
let globe = new Globe({
target: "earth",
name: "Earth",
terrain: new GlobusRgbTerrain(),
transitionOpacityEnabled: true,
atmosphereEnabled: true,
layers: [new OpenStreetMap()],
transparentBackground: true,
atmosphereParameters:{
disableSunDisk: true
}
});
globe.planet.addControls([
new control.TimelineControl(),
new control.LayerSwitcher(),
new control.Lighting()
]);

View File

@ -26,6 +26,7 @@ export interface IAtmosphereParams extends IControlParams {
sunIntensity?: number,
ozoneDensityHeight?: number,
ozoneDensityWide?: number,
disableSunDisk?: boolean
}
export class Atmosphere extends Control {
@ -64,6 +65,7 @@ export class Atmosphere extends Control {
SUN_INTENSITY: options.sunIntensity || 1.0,
ozoneDensityHeight: options.ozoneDensityHeight || 25e3,
ozoneDensityWide: options.ozoneDensityWide || 15e3,
disableSunDisk: options.disableSunDisk
}
}
@ -301,6 +303,9 @@ function atmosphereBackgroundShader(atmosParams?: AtmosphereParameters): Program
corners: "vec3"
},
vertexShader: atmosphere_vert,
fragmentShader: stringTemplate2(atmosphere_frag, atmosParams)
fragmentShader: stringTemplate2(atmosphere_frag, {
...atmosParams,
disableSunDisk: atmosParams?.disableSunDisk ? 1 : 0
})
});
}

View File

@ -276,6 +276,7 @@ export class AtmosphereConfig extends Control {
SUN_INTENSITY: 0,
ozoneDensityHeight: 0,
ozoneDensityWide: 0,
disableSunDisk: false
}
}

View File

@ -2,6 +2,8 @@ precision lowp float;
#include "../../shaders/atmos/common.glsl"
#define DISABLE_SUN_DISK ${disableSunDisk}
uniform mat4 viewMatrix;
uniform vec3 sunPos;
uniform vec3 camPos;
@ -178,15 +180,19 @@ void mainImage(out vec4 fragColor)
// }
// }
float distanceToGround = 0.0;
bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;
if (!hitGround)
#if !DISABLE_SUN_DISK
{
vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0, 1.0, 0.8);
// limit the bloom effect
sunLum = smoothstep(0.002, 1.0, sunLum);
light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;
float distanceToGround = 0.0;
bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;
if (!hitGround)
{
vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0, 1.0, 0.8);
// limit the bloom effect
sunLum = smoothstep(0.002, 1.0, sunLum);
light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;
}
}
#endif
fragColor = vec4(pow(opacity * light * 8.0, vec3(1.0 / 2.2)), valueHSV(light) * clamp(opacity, 0.0, 1.0));
}

View File

@ -26,6 +26,7 @@ export interface AtmosphereParameters {
SUN_INTENSITY: number,
ozoneDensityHeight: number,
ozoneDensityWide: number,
disableSunDisk?: boolean
}
const DEFAULT_PARAMS: AtmosphereParameters = {
@ -46,6 +47,7 @@ const DEFAULT_PARAMS: AtmosphereParameters = {
SUN_INTENSITY: 1.0,
ozoneDensityHeight: 25e3,
ozoneDensityWide: 15e3,
disableSunDisk: false
}
export function transmittance(atmosParams?: AtmosphereParameters): Program {