Cesium 转换到视图空间的方法

本文详细介绍了在Cesium中如何使用两种方法将屏幕空间和剪裁空间的深度转换到视图空间,包括windowToEye和clipToEye函数,以及相关的深度处理和坐标变换过程。
摘要由CSDN通过智能技术生成

Cesium 转换到视图空间的方法

方法1-从屏幕空间

// depth: [0, 1]
vec4 windowToEye(in vec2 uv, in float depth){
  vec4 posInCamera = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth);
  posInCamera = posInCamera / posInCamera.w;
  return posInCamera;
}

vec4 originDepth = texture(depthTexture, v_textureCoordinates);
vec4 posInCamera = windowToEye(v_textureCoordinates, originDepth.r);
方法2-从剪裁空间
float getClipDepth(in vec4 depth){
  float z_window = czm_unpackDepth(depth);
  z_window = czm_reverseLogDepth(z_window);
  float n_range = czm_depthRange.near;
  float f_range = czm_depthRange.far;
  return (2.0 * z_window - n_range - f_range) / (f_range - n_range);
}

// depth: [-1, 1]
vec4 clipToEye(in vec2 uv, in float depth){
  vec2 xy = vec2((uv.x * 2.0 - 1.0),(uv.y * 2.0 - 1.0));
  vec4 posInCamera =czm_inverseProjection * vec4(xy, depth, 1.0);
  posInCamera =posInCamera / posInCamera.w;
  return posInCamera;
}

vec4 originDepth = texture(depthTexture, v_textureCoordinates);
float depth = getClipDepth(originDepth);
vec4 posInCamera = clipToEye(v_textureCoordinates, depth);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值