forked from maplibre/maplibre-gl-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy over maplibre changes from maplibre#1713
- Loading branch information
Showing
19 changed files
with
362 additions
and
24 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import StencilMode from '../gl/stencil_mode'; | ||
import DepthMode from '../gl/depth_mode'; | ||
import CullFaceMode from '../gl/cull_face_mode'; | ||
import {skyUniformValues} from './program/sky_program'; | ||
import type Painter from './painter'; | ||
import Sky from '../style/sky'; | ||
|
||
export default drawSky; | ||
|
||
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'); | ||
|
||
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, | ||
CullFaceMode.disabled, skyUniforms, undefined, 'sky', sky.vertexBuffer, | ||
sky.indexBuffer, sky.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
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_fog_color': UniformColor; | ||
'u_horizon': Uniform1f; | ||
'u_horizon_blend': Uniform1f; | ||
}; | ||
|
||
const skyUniforms = (context: Context, locations: UniformLocations): SkyUniformsType => ({ | ||
'u_sky_color': new UniformColor(context, locations.u_sky_color), | ||
'u_fog_color': new UniformColor(context, locations.u_fog_color), | ||
'u_horizon': new Uniform1f(context, locations.u_horizon), | ||
'u_horizon_blend': new Uniform1f(context, locations.u_horizon_blend) | ||
}); | ||
|
||
const skyUniformValues = (sky: Sky, transform: Transform, pixelRatio: number): UniformValues<SkyUniformsType> => ({ | ||
'u_sky_color': sky.properties.get('sky-color'), | ||
'u_fog_color': sky.properties.get('fog-color'), | ||
'u_horizon': (transform.height / 2 + transform.getHorizon()) * pixelRatio, | ||
'u_horizon_blend': (sky.properties.get('horizon-blend') * transform.height / 2) * pixelRatio | ||
}); | ||
|
||
export {skyUniforms, skyUniformValues}; |
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,18 @@ | ||
uniform vec4 u_sky_color; | ||
uniform vec4 u_fog_color; | ||
uniform float u_horizon; | ||
uniform float u_horizon_blend; | ||
|
||
void main() { | ||
float y = gl_FragCoord.y; | ||
if (y > u_horizon) { | ||
float blend = y - u_horizon; | ||
if (blend < u_horizon_blend) { | ||
gl_FragColor = mix(u_sky_color, u_fog_color, pow(1.0 - blend / u_horizon_blend, 2.0)); | ||
} else { | ||
gl_FragColor = u_sky_color; | ||
} | ||
} else { | ||
gl_FragColor = u_fog_color; | ||
} | ||
} |
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,5 @@ | ||
attribute vec2 a_pos; | ||
|
||
void main() { | ||
gl_Position = vec4(a_pos, 1.0, 1.0); | ||
} |
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 |
---|---|---|
@@ -1,7 +1,15 @@ | ||
uniform sampler2D u_texture; | ||
uniform vec4 u_fog_color; | ||
uniform float u_fog_blend; | ||
uniform float u_fog_blend_opacity; | ||
|
||
in vec2 v_texture_pos; | ||
in float v_fog_depth; | ||
|
||
void main() { | ||
fragColor = texture(u_texture, v_texture_pos); | ||
if (v_fog_depth > u_fog_blend) { | ||
float a = (v_fog_depth - u_fog_blend) / (1.0 - u_fog_blend); | ||
fragColor = mix(fragColor, u_fog_color, pow(a * u_fog_blend_opacity, 2.0)); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,21 @@ | ||
in vec3 a_pos3d; | ||
|
||
uniform mat4 u_matrix; | ||
uniform mat4 u_fog_matrix; | ||
uniform float u_ele_delta; | ||
|
||
out vec2 v_texture_pos; | ||
out float v_depth; | ||
out float v_fog_depth; | ||
|
||
void main() { | ||
float ele = get_elevation(a_pos3d.xy); | ||
float extent = 8192.0; // 8192.0 is the hardcoded vector-tiles coordinates resolution | ||
float ele_delta = a_pos3d.z == 1.0 ? u_ele_delta : 0.0; | ||
v_texture_pos = a_pos3d.xy / extent; | ||
gl_Position = u_matrix * vec4(a_pos3d.xy, get_elevation(a_pos3d.xy) - ele_delta, 1.0); | ||
v_depth = gl_Position.z / gl_Position.w; | ||
gl_Position = u_matrix * vec4(a_pos3d.xy, ele - ele_delta, 1.0); | ||
v_depth = gl_Position.z / gl_Position.w; | ||
vec4 pos = u_fog_matrix * vec4(a_pos3d.xy, ele, 1.0); | ||
v_fog_depth = pos.z / pos.w * 0.5 + 0.5; | ||
|
||
} |
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,13 @@ | ||
attribute vec3 a_pos3d; | ||
|
||
uniform mat4 u_matrix; | ||
uniform float u_ele_delta; | ||
|
||
varying vec2 v_texture_pos; | ||
|
||
void main() { | ||
float ele = get_elevation(a_pos3d.xy); | ||
float ele_delta = a_pos3d.z == 1.0 ? u_ele_delta : 0.0; | ||
v_texture_pos = a_pos3d.xy / 8192.0; | ||
gl_Position = u_matrix * vec4(a_pos3d.xy, ele - ele_delta, 1.0); | ||
} |
Oops, something went wrong.