// Copyright (c) 2015 - 2017 Uber Technologies, Inc. // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. export default `\ #version 300 es #define SHADER_NAME line-layer-vertex-shader in vec3 positions; in vec3 instanceSourcePositions; in vec3 instanceTargetPositions; in vec3 instanceSourcePositions64Low; in vec3 instanceTargetPositions64Low; in vec4 instanceColors; in vec3 instancePickingColors; in float instanceWidths; uniform float opacity; uniform float widthScale; uniform float widthMinPixels; uniform float widthMaxPixels; uniform float useShortestPath; uniform int widthUnits; out vec4 vColor; out vec2 uv; // offset vector by strokeWidth pixels // offset_direction is -1 (left) or 1 (right) vec2 getExtrusionOffset(vec2 line_clipspace, float offset_direction, float width) { // normalized direction of the line vec2 dir_screenspace = normalize(line_clipspace * project_uViewportSize); // rotate by 90 degrees dir_screenspace = vec2(-dir_screenspace.y, dir_screenspace.x); return dir_screenspace * offset_direction * width / 2.0; } vec3 splitLine(vec3 a, vec3 b, float x) { float t = (x - a.x) / (b.x - a.x); return vec3(x, mix(a.yz, b.yz, t)); } void main(void) { geometry.worldPosition = instanceSourcePositions; geometry.worldPositionAlt = instanceTargetPositions; vec3 source_world = instanceSourcePositions; vec3 target_world = instanceTargetPositions; vec3 source_world_64low = instanceSourcePositions64Low; vec3 target_world_64low = instanceTargetPositions64Low; if (useShortestPath > 0.5 || useShortestPath < -0.5) { source_world.x = mod(source_world.x + 180., 360.0) - 180.; target_world.x = mod(target_world.x + 180., 360.0) - 180.; float deltaLng = target_world.x - source_world.x; if (deltaLng * useShortestPath > 180.) { source_world.x += 360. * useShortestPath; source_world = splitLine(source_world, target_world, 180. * useShortestPath); source_world_64low = vec3(0.0); } else if (deltaLng * useShortestPath < -180.) { target_world.x += 360. * useShortestPath; target_world = splitLine(source_world, target_world, 180. * useShortestPath); target_world_64low = vec3(0.0); } else if (useShortestPath < 0.) { // Line is not split, abort gl_Position = vec4(0.); return; } } // Position vec4 source_commonspace; vec4 target_commonspace; vec4 source = project_position_to_clipspace(source_world, source_world_64low, vec3(0.), source_commonspace); vec4 target = project_position_to_clipspace(target_world, target_world_64low, vec3(0.), target_commonspace); // linear interpolation of source & target to pick right coord float segmentIndex = positions.x; vec4 p = mix(source, target, segmentIndex); geometry.position = mix(source_commonspace, target_commonspace, segmentIndex); uv = positions.xy; geometry.uv = uv; geometry.pickingColor = instancePickingColors; // Multiply out width and clamp to limits float widthPixels = clamp( project_size_to_pixel(instanceWidths * widthScale, widthUnits), widthMinPixels, widthMaxPixels ); // extrude vec3 offset = vec3( getExtrusionOffset(target.xy - source.xy, positions.y, widthPixels), 0.0); DECKGL_FILTER_SIZE(offset, geometry); DECKGL_FILTER_GL_POSITION(p, geometry); gl_Position = p + vec4(project_pixel_size_to_clipspace(offset.xy), 0.0, 0.0); // Color vColor = vec4(instanceColors.rgb, instanceColors.a * opacity); DECKGL_FILTER_COLOR(vColor, geometry); } `;