UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

21 lines (20 loc) 1.59 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ import{ReadDepth as e}from"./output/ReadDepth.glsl.js";import{CameraSpace as o}from"./util/CameraSpace.glsl.js";import{glsl as t}from"../shaderModules/glsl.js";function i(i){const r=i.fragment;i.include(o),r.include(e),r.code.add(t`vec3 normalFromDepth(sampler2D depthMap, vec3 pixelPos, vec2 fragCoord, vec2 uv) { ivec2 iuv = ivec2(uv * vec2(textureSize(depthMap, 0))); float leftPixelDepth = linearizeDepth(texelFetch(depthMap, iuv + ivec2(-1, 0), 0).r); float rightPixelDepth = linearizeDepth(texelFetch(depthMap, iuv + ivec2(1, 0), 0).r); float bottomPixelDepth = linearizeDepth(texelFetch(depthMap, iuv + ivec2(0, -1), 0).r); float topPixelDepth = linearizeDepth(texelFetch(depthMap, iuv + ivec2(0, 1), 0).r); bool pickLeft = abs(pixelPos.z - leftPixelDepth) < abs(pixelPos.z - rightPixelDepth); bool pickBottom = abs(pixelPos.z - bottomPixelDepth) < abs(pixelPos.z - topPixelDepth); vec3 fragCoordHorizontal = pickLeft ? vec3(fragCoord + vec2(-1.0, 0.0), leftPixelDepth) : vec3(fragCoord + vec2(1.0, 0.0), rightPixelDepth); vec3 fragCoordVertical = pickBottom ? vec3(fragCoord + vec2(0.0, -1.0), bottomPixelDepth) : vec3(fragCoord + vec2(0.0, 1.0), topPixelDepth); vec3 verticalPixelPos = reconstructPosition(fragCoordHorizontal.xy, fragCoordHorizontal.z); vec3 horizontalPixelPos = reconstructPosition(fragCoordVertical.xy, fragCoordVertical.z); vec3 normal = normalize(cross(verticalPixelPos - pixelPos, horizontalPixelPos - pixelPos)); return pickLeft == pickBottom ? normal : -normal; }`)}export{i as NormalFromDepth};