What does (gl_FragCoord.z / gl_FragCoord.w) represent?

OpenGL深度坐标解析

This was asked (by the same person) and answered elsewhere. I'm paraphrasing and embellishing the answer here:

As stated in section 15.2.2 of the OpenGL 4.3 core profile specification (PDF), gl_FragCoord.w is 1 / clip.w, where clip.w is the W component of the clip-space position (ie: what you wrote to gl_Position).

gl_FragCoord.z is generated by the following process, assuming the usual transforms:

  1. Camera-space to clip-space transform, via projection matrix multiplication in the vertex shader. clip.z = (projectionMatrix * cameraPosition).z
  2. Transform to normalized device coordinates. ndc.z = clip.z / clip.w
  3. Transform to window coordinates, using the glDepthRange near/far values. win.z = ((dfar-dnear)/2) * ndc.z + (dfar+dnear)/2.

Now, using the default depth range of near=0, far=1, we can define win.z in terms of clip-space: (clip.z/clip.w)/2 + 0.5. If we then divide this by gl_FragCoord.w, that is the equivalent of multiplying by clip.w, thus giving us:

(gl_FragCoord.z / gl_FragCoord.w) = clip.z/2 + clip.w/2 = (clip.z + clip.w) / 2

Using the standard projection matrix, clip.z represents a scale and offset from camera-space Z component. The scale and offset are defined by the camera's near/far depth values. clip.w is, again in the standard projection matrix, just the negation of the camera-space Z. Therefore, we can redefine our equation in those terms:

(gl_FragCoord.z / gl_FragCoord.w) = (A * cam.z + B -cam.z)/2 = (C * cam.z + D)

Where A and B represent the offset and scale based on near/far, and C = (A - 1)/2 and D = B / 2.

Therefore, gl_FragCoord.z / gl_FragCoord.w is not the camera-space (or world-space) distance to the camera. Nor is it the camera-space planar distance to the camera. But it is a linear transform of the camera-space depth. You could use it as a way to compare two depth values together, if they came from the same projection matrix and so forth.

To actually compute the camera-space Z, you need to either pass the camera near/far from your matrix (OpenGL already gives you the range near/far) and compute those A and B values from them, or you need to use the inverse of the projection matrix. Alternatively, you could just use the projection matrix directly yourself, since fragment shaders can use the same uniforms available to vertex shaders. You can pick the A and B terms directly from that matrix. A = projectionMatrix[2][2], and B = projectionMatrix[3][2].

shareimprove this answer

answered Dec 5 '12 at 20:10

community wiki

 

Nicol Bolas

INFO: Sourcing build tools [INFO] Silentconfig project [INFO] Sourcing build environment [INFO] Generating kconfig for Rootfs [INFO] Silentconfig rootfs [INFO] Generating plnxtool conf [INFO] Generating workspace directory [INFO] Configuring: u-boot [INFO] devtool modify u-boot-xlnx NOTE: Starting bitbake server... NOTE: Reconnecting to bitbake server... NOTE: Retrying server connection (#1)... NOTE: Reconnecting to bitbake server... NOTE: Previous bitbake instance shutting down?, waiting to retry... NOTE: Retrying server connection (#2)... WARNING: Invalid mirror variable value for PREMIRRORS: ['cvs://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'svn://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'git://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'gitsm://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'hg://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'bzr://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'p4://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'osc://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'https?$://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'ftp://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'npm://.*/?.*', 'file:///proj/yocto/daily-downloads_2020/', '\\', 'git://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'gitsm://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'ftp://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'http://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'https://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'git://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'ftp://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'http://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'https://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'git://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'ftp://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'http://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'https://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads'], should contain paired members. Parsing recipes: 100% |######################################################################################################################################################################| Time: 0:01:52 Parsing of 2995 .bb files complete (0 cached, 2995 parsed). 4265 targets, 169 skipped, 0 masked, 0 errors. Summary: There was 1 WARNING message shown. INFO: SRC_URI contains some conditional appends/prepends - will create branches to represent these WARNING: Invalid mirror variable value for PREMIRRORS: ['cvs://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'svn://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'git://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'gitsm://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'hg://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'bzr://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'p4://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'osc://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'https?$://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'ftp://.*/.*', 'file:///proj/yocto/daily-downloads_2020/', 'npm://.*/?.*', 'file:///proj/yocto/daily-downloads_2020/', '\\', 'git://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'gitsm://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'ftp://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'http://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', '\\', 'https://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'git://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'ftp://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'http://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'https://.*/.*', 'file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads', 'git://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'ftp://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'http://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads', 'https://.*/.*', 'http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads'], should contain paired members. NOTE: Resolving any missing task queue dependencies Initialising tasks: 100% |###################################################################################################################################################################| Time: 0:00:01 Sstate summary: Wanted 0 Found 0 Missed 0 Current 0 (0% match, 0% complete) NOTE: No setscene tasks NOTE: Executing Tasks WARNING: Invalid mirror data cvs://.*/.* file:///proj/yocto/daily-downloads_2020/ \n svn://.*/.* file:///proj/yocto/daily-downloads_2020/ \n git://.*/.* file:///proj/yocto/daily-downloads_2020/ \n gitsm://.*/.* file:///proj/yocto/daily-downloads_2020/ \n hg://.*/.* file:///proj/yocto/daily-downloads_2020/ \n bzr://.*/.* file:///proj/yocto/daily-downloads_2020/ \n p4://.*/.* file:///proj/yocto/daily-downloads_2020/ \n osc://.*/.* file:///proj/yocto/daily-downloads_2020/ \n https?$://.*/.* file:///proj/yocto/daily-downloads_2020/ \n ftp://.*/.* file:///proj/yocto/daily-downloads_2020/ \n npm://.*/?.* file:///proj/yocto/daily-downloads_2020/ \n \ git://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n \ gitsm://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n \ ftp://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n \ http://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n \ https://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n git://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n ftp://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n http://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n https://.*/.* file:///home/lvvl/hd_workspace/tools/downloads_2020.2/downloads \n git://.*/.* http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads \n ftp://.*/.* http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads \n http://.*/.* http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads \n https://.*/.* http://petalinux.xilinx.com/sswreleases/rel-v2020/downloads \n, should have paired members. ERROR: The URL: '\' is invalid and cannot be interpreted ERROR: Logfile of failure stored in: /home/lvvl/hd_workspace/b5_prj/build/tmp/work/zynqmp_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.2+gitAUTOINC+bb4660c33a-r0/devtooltmp-wdh0csko/temp/log.do_fetch.21136
最新发布
07-31
<think>我们正在处理Bitbake构建过程中出现的PREMIRRORS配置错误和无效URL问题。根据用户提供的引用和错误信息,我们可以分析如下: 根据引用[1],出现`ERROR: Failed to source bitbake`和`ERROR: Unable to connect to bitbake server, or start one`,这可能是由于环境配置问题或bitbake服务未正确启动。而引用[2]和[3]则分别提到了安装Yocto SDK失败和cpio命令出错的问题。引用[4]提供了安装petalinux的参考手册。 现在用户的具体问题是:Bitbake构建过程中出现关于PREMIRRORS的警告(WARNING)和错误(ERROR),具体为“Invalid mirror variable value”和“invalid URL”。 ### 分析: 在Bitbake中,`PREMIRRORS`用于指定在下载源代码之前优先使用的镜像站点。如果配置的URL无效,则会导致下载失败。 常见的错误原因包括: 1. `PREMIRRORS`配置的URL格式不正确。 2. 配置的URL不可访问(如网络问题、URL已失效等)。 3. 配置的变量值有误(如拼写错误、使用了不支持的协议等)。 ### 解决步骤: 1. **检查`PREMIRRORS`配置**: - 在Bitbake的配置中(通常在`conf/local.conf`或`conf/site.conf`等文件中),检查`PREMIRRORS`的设置。 - 确保每个URL都是有效的,并且可以访问。 2. **验证URL**: - 使用浏览器或命令行工具(如`curl`或`wget`)测试配置的URL是否可访问。 - 注意URL中使用的协议(如http, https, ftp等)是否被支持。 3. **修正无效的URL**: - 如果发现无效的URL,将其替换为有效的镜像URL。 - 可以参考官方文档或社区推荐的镜像源。 4. **清理并重新构建**: - 在修正配置后,建议清理之前的构建缓存(如删除`downloads`目录和`sstate-cache`目录),然后重新构建。 5. **检查网络设置**: - 确保构建环境可以访问互联网,特别是如果使用了外部镜像源。 ### 示例: 假设在`local.conf`中有如下配置: ```bitbake PREMIRRORS = "git://.*/.* http://my-internal-mirror.com/sources/ \n \ ftp://.*/.* http://my-internal-mirror.com/sources/" ``` 如果出现无效URL的警告,请检查`http://my-internal-mirror.com/sources/`是否可访问,并确保没有拼写错误。 ### 参考引用: - 关于Bitbake的镜像配置,可以参考Yocto项目文档中的相关章节[^1]。 - 如果问题仍然存在,可以尝试搜索类似错误,如引用[2]中提到的安装Yocto SDK失败的问题,可能也是由于网络或镜像配置问题导致的。 §§相关问题§§ 1. 如何配置Bitbake的PREMIRRORS和MIRRORS? 2. Bitbake构建中常见的网络问题有哪些? 3. 如何调试Bitbake的下载失败问题?</think>### Bitbake PREMIRRORS配置错误解决方案 #### 问题分析 在Bitbake/Yocto/Petalinux构建过程中出现`PREMIRRORS`配置错误和无效URL警告的根本原因是: 1. **镜像源配置错误**:`PREMIRRORS`变量包含格式错误的URL或不可访问的镜像地址 2. **网络访问限制**:构建环境无法访问配置的镜像服务器 3. **协议不匹配**:源URL与镜像URL的协议类型(http/https/ftp)不兼容 4. **路径错误**:镜像路径与原始文件路径不匹配 #### 解决步骤 1. **检查PREMIRRORS配置** - 打开配置文件(通常为`conf/local.conf`或`conf/site.conf`) - 查找`PREMIRRORS`变量定义: ```bitbake PREMIRRORS = " \\ git://.*/.* http://my-mirror.com/sources/ \\n \\ ftp://.*/.* http://my-mirror.com/sources/ \\n \\ https?://.*/.* http://my-mirror.com/sources/ \\ " ``` - 验证所有URL格式正确性(需包含协议头`http://`或`https://`) 2. **测试镜像可访问性** ```bash # 测试URL连通性 curl -I http://my-mirror.com/sources/ # 测试文件下载 wget http://my-mirror.com/sources/sample-file ``` 3. **修正无效URL(常见错误示例)** | 错误配置 | 正确配置 | |---|---| | `http:/mirror.com` (缺少斜杠) | `http://mirror.com/` | | `http://mirror.com` (缺少路径) | `http://mirror.com/sources/` | | `git://github.com/.*` (协议不匹配) | `https://github.com/.*` | 4. **添加备用镜像源** ```bitbake PREMIRRORS:append = " \\ https?://.*/.* https://cdn.kernel.org/pub/ \\n \\ git://git.yoctoproject.org/.* https://downloads.yoctoproject.org/mirror/ \\ " ``` 5. **启用详细日志调试** ```bash bitbake -c fetchall <recipe> -vDDD 2>&1 | grep 'mirror fetch' ``` 6. **清理缓存后重建** ```bash rm -rf downloads/* # 清除下载缓存 bitbake <image-name> --runall=fetch ``` #### 预防措施 1. 使用镜像状态检查脚本: ```bash #!/bin/bash for url in $(grep -hoP 'https?://[^ \\]*' conf/local.conf); do curl -sL -w "%{http_code} %{url_effective}\\n" "$url" -o /dev/null done ``` 2. 优先使用HTTPS协议镜像源 3. 定期更新镜像配置(参考[Xilinx官方镜像列表](https://docs.xilinx.com/r/en-US/ug1144-petalinux-tools-reference-guide/Setting-Up-Your-Environment) [^4]) > **关键提示**:当出现`Invalid mirror variable value`错误时,99%的情况是URL格式错误或路径缺失结尾斜杠`/`,需特别注意正则表达式中的协议匹配[^1][^2]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值