更多精彩内容尽在数字孪生平台,技术交流添加VX:digital_twin123
读取深度图
mapboxgl里面都是通过pack_depth
将深度打包,
highp vec4 pack_depth(highp float ndc_z) {
highp float depth = ndc_z * 0.5 + 0.5;
const highp vec4 bit_shift = vec4(255.0 * 255.0 * 255.0, 255.0 * 255.0, 255.0, 1.0);
const highp vec4 bit_mask = vec4(0.0, 1.0 / 255.0, 1.0 / 255.0, 1.0 / 255.0);
highp vec4 res = fract(depth * bit_shift);
res -= res.xxyz * bit_mask;
return res;
}
unpack_depth
来读取深度
highp float unpack_depth(highp vec4 rgba_depth)
{
const highp vec4 bit_shift = vec4(1.0 / (255.0 * 255.0 * 255.0), 1.0 / (255.0 * 255.0), 1.0 / 255.0, 1.0);
return dot(rgba_depth, bit_shift) * 2.0 - 1.0;
}
在绘制地形的时候,通过drawTerrainDepth
方法,绘制到frameBuffer上