-
-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sky Implementation according to spec (#3645)
* copy code from old sky branch, but this branch is not ready yet * add missing _fogMatrixCache clearance * change long comment from // to /** */ syntax * serialize sky in map.getStyle() * add sky/fog expect tests (#3649) * fix sky2 calculateFogMatrix error and build error (#3651) * try to fix calculateFogMatrix error * Raise expectedBytes for maplibre-gl.js size * Update test/build/min.test.ts * Update diff function to take into consideration sky, updated tests * Move gl logic to draw_sky file, added tests to cover serialization. * Update docs comment * Add missing tests to map.test.ts * Remove unneeded member variable * Fix build * Add cache to draw sky mesh buffer * Use globe's mesh idea, store mesh in sky object, similar to how it is done with buckets. * Fix tests * Fix names according to new spec * Fix render and build tests * Changed name to sky-horizon-blend * Fix lint * Add support for blend in fog and horizon * Terrain fog blending improvements (#4314) * Incorporate my own feedback * Fix shader * Make terrain fog shader blending gamma-correct, update render test * Move surface_color_linear into the branch * Added a debug page, fixed a bug * Update the example to show the values in the spec. * Added test to reproduce the issue * Move sky test to a different folder * Fix lint * Remove unneeded reference from example * Always initialize sky, remove ifs, fix tests * Update CHANGELOG.md * Expect build to fail due to missing image in examples * Fix docs build * Fix docs build * Compress image * Update readme --------- Co-authored-by: Max Demmelbauer <[email protected]> Co-authored-by: Andrew Calcutt <[email protected]> Co-authored-by: Harel M <[email protected]> Co-authored-by: Jakub Pelc <[email protected]>
- Loading branch information
1 parent
8fe33a6
commit 6612f1b
Showing
42 changed files
with
949 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/docs/API | ||
/docs/examples | ||
/docs/example | ||
/site/ | ||
.cache/ | ||
*.es.js | ||
*.js.map | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {StencilMode} from '../gl/stencil_mode'; | ||
import {DepthMode} from '../gl/depth_mode'; | ||
import {CullFaceMode} from '../gl/cull_face_mode'; | ||
import {PosArray, TriangleIndexArray} from '../data/array_types.g'; | ||
import posAttributes from '../data/pos_attributes'; | ||
import {SegmentVector} from '../data/segment'; | ||
import {skyUniformValues} from './program/sky_program'; | ||
import {Sky} from '../style/sky'; | ||
import {Mesh} from './mesh'; | ||
import type {Painter} from './painter'; | ||
|
||
export function drawSky(painter: Painter, sky: Sky) { | ||
const context = painter.context; | ||
const gl = context.gl; | ||
|
||
const skyUniforms = skyUniformValues(sky, painter.style.map.transform, painter.pixelRatio); | ||
|
||
const depthMode = new DepthMode(gl.LEQUAL, DepthMode.ReadWrite, [0, 1]); | ||
const stencilMode = StencilMode.disabled; | ||
const colorMode = painter.colorModeForRenderPass(); | ||
const program = painter.useProgram('sky'); | ||
|
||
if (!sky.mesh) { | ||
const vertexArray = new PosArray(); | ||
vertexArray.emplaceBack(-1, -1); | ||
vertexArray.emplaceBack(1, -1); | ||
vertexArray.emplaceBack(1, 1); | ||
vertexArray.emplaceBack(-1, 1); | ||
|
||
const indexArray = new TriangleIndexArray(); | ||
indexArray.emplaceBack(0, 1, 2); | ||
indexArray.emplaceBack(0, 2, 3); | ||
|
||
sky.mesh = new Mesh( | ||
context.createVertexBuffer(vertexArray, posAttributes.members), | ||
context.createIndexBuffer(indexArray), | ||
SegmentVector.simpleSegment(0, 0, vertexArray.length, indexArray.length) | ||
); | ||
} | ||
|
||
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, | ||
CullFaceMode.disabled, skyUniforms, undefined, 'sky', sky.mesh.vertexBuffer, | ||
sky.mesh.indexBuffer, sky.mesh.segments); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import {SegmentVector} from '../data/segment'; | ||
import {VertexBuffer} from '../gl/vertex_buffer'; | ||
import {IndexBuffer} from '../gl/index_buffer'; | ||
|
||
export class Mesh { | ||
vertexBuffer: VertexBuffer; | ||
indexBuffer: IndexBuffer; | ||
segments: SegmentVector; | ||
|
||
constructor(vertexBuffer: VertexBuffer, indexBuffer: IndexBuffer, segments: SegmentVector) { | ||
this.vertexBuffer = vertexBuffer; | ||
this.indexBuffer = indexBuffer; | ||
this.segments = segments; | ||
} | ||
|
||
destroy(): void { | ||
this.vertexBuffer.destroy(); | ||
this.indexBuffer.destroy(); | ||
this.segments.destroy(); | ||
|
||
this.vertexBuffer = null; | ||
this.indexBuffer = null; | ||
this.segments = null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {UniformColor, Uniform1f} from '../uniform_binding'; | ||
import type {Context} from '../../gl/context'; | ||
import type {UniformValues, UniformLocations} from '../uniform_binding'; | ||
import {Transform} from '../../geo/transform'; | ||
import {Sky} from '../../style/sky'; | ||
|
||
export type SkyUniformsType = { | ||
'u_sky_color': UniformColor; | ||
'u_horizon_color': UniformColor; | ||
'u_horizon': Uniform1f; | ||
'u_sky_horizon_blend': Uniform1f; | ||
}; | ||
|
||
const skyUniforms = (context: Context, locations: UniformLocations): SkyUniformsType => ({ | ||
'u_sky_color': new UniformColor(context, locations.u_sky_color), | ||
'u_horizon_color': new UniformColor(context, locations.u_horizon_color), | ||
'u_horizon': new Uniform1f(context, locations.u_horizon), | ||
'u_sky_horizon_blend': new Uniform1f(context, locations.u_sky_horizon_blend), | ||
}); | ||
|
||
const skyUniformValues = (sky: Sky, transform: Transform, pixelRatio: number): UniformValues<SkyUniformsType> => ({ | ||
'u_sky_color': sky.properties.get('sky-color'), | ||
'u_horizon_color': sky.properties.get('horizon-color'), | ||
'u_horizon': (transform.height / 2 + transform.getHorizon()) * pixelRatio, | ||
'u_sky_horizon_blend': (sky.properties.get('sky-horizon-blend') * transform.height / 2) * pixelRatio, | ||
}); | ||
|
||
export {skyUniforms, skyUniformValues}; |
Oops, something went wrong.