Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

11716 visualize fog #11744

Merged
merged 60 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
73146e0
Set up scaffolding for FogPipelineStage
ptrgags Dec 7, 2023
35c7d9d
Add atmosphere settings to FrameState and UniformState
ptrgags Dec 7, 2023
8723127
Make builtins for common atmosphere functions
ptrgags Dec 18, 2023
bf1890c
Get a barebones atmosphere shader compiling
ptrgags Dec 18, 2023
0634b53
Create Atmosphere object to propagate uniforms
ptrgags Dec 18, 2023
d21e7bd
Fix typos in uniform names
ptrgags Dec 18, 2023
0a2c338
Merge branch 'main' into 4196-3d-tiles-fog
ptrgags Dec 18, 2023
092f91e
Temporary debugging code
ptrgags Dec 20, 2023
6b7be7f
Use scene.fog to choose when fog stage is enabled
ptrgags Dec 20, 2023
3027987
Add a DynamicAtmosphereLightingType enum
ptrgags Dec 20, 2023
fb92f87
Merge branch 'main' into 4196-3d-tiles-fog
ptrgags Jan 4, 2024
a1cb8e1
Document curvature directions in more detail
ptrgags Jan 4, 2024
9fb4110
Use a different method to compute the world position
ptrgags Jan 4, 2024
bc781be
Add unit test for Atmosphere
ptrgags Jan 5, 2024
990b815
Add unit tests for automatic uniforms
ptrgags Jan 5, 2024
c4e1b37
Fix and update unit tests for ModelRuntimePrimitive
ptrgags Jan 5, 2024
95b2a87
Merge branch 'main' into 11716-visualize-fog
ptrgags Jan 5, 2024
046160c
Implement the other method for computing the ellipsoid position
ptrgags Jan 8, 2024
4255132
Experiment with different ellipsoid calculations
ptrgags Jan 8, 2024
e3266df
Remove temporary debugging code
ptrgags Jan 8, 2024
cc1f346
Have scene.atmosphere work when globe is off
ptrgags Jan 8, 2024
bce6afc
darken dynamic lighting
ptrgags Jan 9, 2024
3112490
Remove dead function
ptrgags Jan 9, 2024
b57ea04
Remove debugging code
ptrgags Jan 9, 2024
bd7f7b9
Fix typo
ptrgags Jan 9, 2024
c68e971
Use common function for SkyAtmosphere
ptrgags Jan 9, 2024
a458be1
Remove debugging code
ptrgags Jan 9, 2024
63efb02
Remove unneeded file
ptrgags Jan 9, 2024
138e4e2
Merge branch 'main' into 11716-visualize-fog
ptrgags Jan 9, 2024
e0314cd
Add a uniform for whether the tile is in fog
ptrgags Jan 9, 2024
7d4e2fa
remove debugging code
ptrgags Jan 9, 2024
d78360a
Scattering is to be computed in the vertex shader
ptrgags Jan 9, 2024
59ab44d
Apply HSB shift
ptrgags Jan 9, 2024
3529441
Fix model matrix spec
ptrgags Jan 10, 2024
f8d3560
Async-ify model matrix update stage
ptrgags Jan 10, 2024
af06785
Move pipeline stage specs to ModelSceneGraph
ptrgags Jan 10, 2024
4e6b942
fix auto imports
ptrgags Jan 10, 2024
cdc24fc
Add test for czm_fogMinimumBrightness
ptrgags Jan 10, 2024
19cd032
Add specs for FogPipelineStage
ptrgags Jan 10, 2024
7e4e6e1
async-ify model scene graph tests
ptrgags Jan 10, 2024
393e7fc
Update documentation
ptrgags Jan 10, 2024
55db725
Merge branch 'main' into 11716-visualize-fog
ptrgags Jan 10, 2024
9b4c846
Add specs for DynamicAtmosphereLightingType
ptrgags Jan 10, 2024
e0f9b33
Rename FogPipelineStage -> AtmospherePipelineStage
ptrgags Jan 10, 2024
5236406
add render tests for model fog
ptrgags Jan 11, 2024
920ed28
Fix atmosphere pipeline specs
ptrgags Jan 11, 2024
dbbd50b
Update changelog
ptrgags Jan 11, 2024
060eb47
Update documentation based on PR feedback
ptrgags Jan 11, 2024
7592fa4
Add missing JSDoc tags
ptrgags Jan 11, 2024
7b930e2
Mark specs as requiring WebGL
ptrgags Jan 11, 2024
84e77ea
Reset atmosphere after each render test
ptrgags Jan 11, 2024
6c2af2f
Add a separate bullet for adding scene.atmosphere
ptrgags Jan 11, 2024
defd310
Don't mock in AtmospherePipelineStageSpec
ptrgags Jan 11, 2024
dca2dcf
address PR feedback
ptrgags Jan 16, 2024
7adf61d
add ignoreBlackPixels option to czm_applyHSBShift
ptrgags Jan 18, 2024
6cefbe1
use czm_tanh()
ptrgags Jan 18, 2024
ac17f63
Store the Atmosphere in the FrameState directly
ptrgags Jan 18, 2024
bca110f
Fix automatic uniform specs
ptrgags Jan 18, 2024
3a25627
Fix sky atmosphere
ptrgags Jan 18, 2024
ab97280
Update unit tests
ptrgags Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- Added `Cesium3DTileset.getHeight` to sample height values of the loaded tiles. If using WebGL 1, the `enablePick` option must be set to true to use this function. [#11581](https://github.com/CesiumGS/cesium/pull/11581)
- Added `Cesium3DTileset.disableCollision` to allow the camera from to go inside or below a 3D tileset, for instance, to be used with 3D Tiles interiors. [#11581](https://github.com/CesiumGS/cesium/pull/11581)
- The `Cesium3DTileset.dynamicScreenSpaceError` optimization is now enabled by default, as this improves performance for street-level horizon views. Furthermore, the default settings of this feature were tuned for improved performance. `Cesium3DTileset.dynamicScreenSpaceErrorDensity` was changed from 0.00278 to 0.0002. `Cesium3DTileset.dynamicScreenSpaceErrorFactor` was changed from 4 to 24. [#11718](https://github.com/CesiumGS/cesium/pull/11718)
- Fog rendering now applies to glTF models and 3D Tiles. This can be configured using `scene.fog` and `scene.atmosphere`. [#11744](https://github.com/CesiumGS/cesium/pull/11744)
- Added `scene.atmosphere` to store common atmosphere lighting parameters. [#11744](https://github.com/CesiumGS/cesium/pull/11744) and [#11681](https://github.com/CesiumGS/cesium/issues/11681)

##### Fixes :wrench:

Expand Down
3 changes: 3 additions & 0 deletions Specs/createFrameState.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
Atmosphere,
defaultValue,
GeographicProjection,
JulianDate,
Expand Down Expand Up @@ -51,6 +52,8 @@ function createFrameState(context, camera, frameNumber, time) {

frameState.minimumDisableDepthTestDistance = 0.0;

frameState.atmosphere = new Atmosphere();

return frameState;
}
export default createFrameState;
122 changes: 121 additions & 1 deletion packages/engine/Source/Renderer/AutomaticUniforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,8 @@ const AutomaticUniforms = {

/**
* An automatic GLSL uniform containing the ellipsoid radii of curvature at the camera position.
* The .x component is the prime vertical radius, .y is the meridional.
* The .x component is the prime vertical radius of curvature (east-west direction)
* .y is the meridional radius of curvature (north-south direction)
* This uniform is only valid when the {@link SceneMode} is <code>SCENE3D</code>.
*/
czm_eyeEllipsoidCurvature: new AutomaticUniform({
Expand Down Expand Up @@ -1591,6 +1592,125 @@ const AutomaticUniforms = {
},
}),

/**
* An automatic GLSL uniform scalar used to set a minimum brightness when dynamic lighting is applied to fog.
*
* @see czm_fog
*/
czm_fogMinimumBrightness: new AutomaticUniform({
ptrgags marked this conversation as resolved.
Show resolved Hide resolved
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.fogMinimumBrightness;
},
}),

/**
* An automatic uniform representing the color shift for the atmosphere in HSB color space
*
* @example
* uniform vec3 czm_atmosphereHsbShift;
*/
czm_atmosphereHsbShift: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT_VEC3,
getValue: function (uniformState) {
return uniformState.atmosphereHsbShift;
},
}),
/**
* An automatic uniform representing the intensity of the light that is used for computing the atmosphere color
*
* @example
* uniform float czm_atmosphereLightIntensity;
*/
czm_atmosphereLightIntensity: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.atmosphereLightIntensity;
},
}),
/**
* An automatic uniform representing the Rayleigh scattering coefficient used when computing the atmosphere scattering
*
* @example
* uniform vec3 czm_atmosphereRayleighCoefficient;
*/
czm_atmosphereRayleighCoefficient: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT_VEC3,
getValue: function (uniformState) {
return uniformState.atmosphereRayleighCoefficient;
},
}),
/**
* An automatic uniform representing the Rayleigh scale height in meters used for computing atmosphere scattering.
*
* @example
* uniform vec3 czm_atmosphereRayleighScaleHeight;
*/
czm_atmosphereRayleighScaleHeight: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.atmosphereRayleighScaleHeight;
},
}),
/**
* An automatic uniform representing the Mie scattering coefficient used when computing atmosphere scattering.
*
* @example
* uniform vec3 czm_atmosphereMieCoefficient;
*/
czm_atmosphereMieCoefficient: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT_VEC3,
getValue: function (uniformState) {
return uniformState.atmosphereMieCoefficient;
},
}),
/**
* An automatic uniform storign the Mie scale height used when computing atmosphere scattering.
*
* @example
* uniform float czm_atmosphereMieScaleHeight;
*/
czm_atmosphereMieScaleHeight: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.atmosphereMieScaleHeight;
},
}),
/**
* An automatic uniform representing the anisotropy of the medium to consider for Mie scattering.
*
* @example
* uniform float czm_atmosphereAnisotropy;
*/
czm_atmosphereMieAnisotropy: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.atmosphereMieAnisotropy;
},
}),

/**
* An automatic uniform representing which light source to use for dynamic lighting
*
* @example
* uniform float czm_atmosphereDynamicLighting
*/
czm_atmosphereDynamicLighting: new AutomaticUniform({
size: 1,
datatype: WebGLConstants.FLOAT,
getValue: function (uniformState) {
return uniformState.atmosphereDynamicLighting;
},
}),

/**
* An automatic GLSL uniform representing the splitter position to use when rendering with a splitter.
* This will be in pixel coordinates relative to the canvas.
Expand Down
127 changes: 127 additions & 0 deletions packages/engine/Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ function UniformState() {
this._specularEnvironmentMapsMaximumLOD = undefined;

this._fogDensity = undefined;
this._fogMinimumBrightness = undefined;

this._atmosphereHsbShift = undefined;
this._atmosphereLightIntensity = undefined;
this._atmosphereRayleighCoefficient = new Cartesian3();
this._atmosphereRayleighScaleHeight = new Cartesian3();
this._atmosphereMieCoefficient = new Cartesian3();
this._atmosphereMieScaleHeight = undefined;
this._atmosphereMieAnisotropy = undefined;
this._atmosphereDynamicLighting = undefined;

this._invertClassificationColor = undefined;

Expand Down Expand Up @@ -915,6 +925,99 @@ Object.defineProperties(UniformState.prototype, {
},
},

/**
* A scalar used as a minimum value when brightening fog
* @memberof UniformState.prototype
* @type {number}
*/
fogMinimumBrightness: {
get: function () {
return this._fogMinimumBrightness;
},
},

/**
* A color shift to apply to the atmosphere color in HSB.
* @memberof UniformState.prototype
* @type {Cartesian3}
*/
atmosphereHsbShift: {
get: function () {
return this._atmosphereHsbShift;
},
},
/**
* The intensity of the light that is used for computing the atmosphere color
* @memberof UniformState.prototype
* @type {number}
*/
atmosphereLightIntensity: {
get: function () {
return this._atmosphereLightIntensity;
},
},
/**
* The Rayleigh scattering coefficient used in the atmospheric scattering equations for the sky atmosphere.
* @memberof UniformState.prototype
* @type {Cartesian3}
*/
atmosphereRayleighCoefficient: {
get: function () {
return this._atmosphereRayleighCoefficient;
},
},
/**
* The Rayleigh scale height used in the atmospheric scattering equations for the sky atmosphere, in meters.
* @memberof UniformState.prototype
* @type {number}
*/
atmosphereRayleighScaleHeight: {
get: function () {
return this._atmosphereRayleighScaleHeight;
},
},
/**
* The Mie scattering coefficient used in the atmospheric scattering equations for the sky atmosphere.
* @memberof UniformState.prototype
* @type {Cartesian3}
*/
atmosphereMieCoefficient: {
get: function () {
return this._atmosphereMieCoefficient;
},
},
/**
* The Mie scale height used in the atmospheric scattering equations for the sky atmosphere, in meters.
* @memberof UniformState.prototype
* @type {number}
*/
atmosphereMieScaleHeight: {
get: function () {
return this._atmosphereMieScaleHeight;
},
},
/**
* The anisotropy of the medium to consider for Mie scattering.
* @memberof UniformState.prototype
* @type {number}
*/
atmosphereMieAnisotropy: {
get: function () {
return this._atmosphereMieAnisotropy;
},
},
/**
* Which light source to use for dynamically lighting the atmosphere
*
* @memberof UniformState.prototype
* @type {DynamicAtmosphereLightingType}
*/
atmosphereDynamicLighting: {
get: function () {
return this._atmosphereDynamicLighting;
},
},

/**
* A scalar that represents the geometric tolerance per meter
* @memberof UniformState.prototype
Expand Down Expand Up @@ -1411,6 +1514,30 @@ UniformState.prototype.update = function (frameState) {
}

this._fogDensity = frameState.fog.density;
this._fogMinimumBrightness = frameState.fog.minimumBrightness;

const atmosphere = frameState.atmosphere;
if (defined(atmosphere)) {
this._atmosphereHsbShift = Cartesian3.fromElements(
atmosphere.hueShift,
atmosphere.saturationShift,
atmosphere.brightnessShift,
this._atmosphereHsbShift
);
this._atmosphereLightIntensity = atmosphere.lightIntensity;
this._atmosphereRayleighCoefficient = Cartesian3.clone(
atmosphere.rayleighCoefficient,
this._atmosphereRayleighCoefficient
);
this._atmosphereRayleighScaleHeight = atmosphere.rayleighScaleHeight;
this._atmosphereMieCoefficient = Cartesian3.clone(
atmosphere.mieCoefficient,
this._atmosphereMieCoefficient
);
this._atmosphereMieScaleHeight = atmosphere.mieScaleHeight;
this._atmosphereMieAnisotropy = atmosphere.mieAnisotropy;
this._atmosphereDynamicLighting = atmosphere.dynamicLighting;
}

this._invertClassificationColor = frameState.invertClassificationColor;

Expand Down
Loading