FragCoord中代表什么

FragCoord中代表什么

本文介绍了1/w坐标在gl_FragCoord中代表什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gl_FragCoord变量存储四个分量:(x,y,z, 1/w )

The gl_FragCoord variable stores four components: (x, y, z, 1/w)

什么是 w 坐标,为什么将其存储为 1/w ?

What is the w coordinate and why is it stored as 1/w?

推荐答案

在这方面,GLSL和OpenGL规范不必要地造成混淆. OpenGL规范更容易理解:gl_FragCoord存储窗口空间顶点位置的X,Y和Z分量. X,Y和Z值的计算方法与在计算窗口空间位置时所述的方法相同(尽管像素中心和左上角的原点可以修改X和Y值).规范的Coordinate Transforms部分对此进行了说明.

The GLSL and OpenGL specifications are needlessly confusing in this regard. The OpenGL spec is easier to understand: gl_FragCoord stores the X, Y, and Z components of the window-space vertex position. The X, Y, and Z values are calculated as described for computing the window-space position (though the pixel-center and upper-left origin can modify the X and Y values). This is described in the Coordinate Transforms section of the spec.

gl_FragCoord的W分量是(1/W ),其中W 是 clip-space 顶点位置.是来自顶点着色器的gl_Position.w.

The W component of gl_FragCoord is (1 / W), where W is the clip-space vertex position. It's gl_Position.w from your vertex shader.

保持W 唯一有用的目的是反向转换gl_FragCoord 返回剪辑空间位置.如该页面所示,这需要乘以W .但是,由于gl_FragCoord仅存储此值的倒数,因此现在需要除以gl_FragCoord.w.

The only useful purpose for keeping W around is to reverse-transform gl_FragCoord to get the clip-space position back. Which, as that page shows, requires multiplying by W. But since gl_FragCoord only stores the inverse of this value, it now requires dividing by gl_FragCoord.w.

因此,我们可以假设OpenGL以这种方式存储它,因为不允许OpenGL太有意义;)看,这是OpenGL规范的每个部分都必须有一点荒谬的规则. XYZ组件的意义太大,因此他们决定让它存储您实际想要的值的倒数.

Therefore, we can assume that OpenGL stores it this way because OpenGL isn't allowed to make too much sense ;) See, it's a rule that every part of the OpenGL specification must have something that's a bit nonsensical. The XYZ components made too much sense, so they decided to have it stores the inverse of the value you actually want.

好的,从技术上讲,这是3D Labs创建GLSL以来的历史产物.我敢肯定他们这样做是出于纯粹自私的硬件原因,但是我没有真正的证据.

OK, technically this is a historical artifact from the days when 3D Labs created GLSL. I'm sure they did it for purely selfish hardware reasons, but I have no real proof of that.

这篇关于1/w坐标在gl_FragCoord中代表什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 02:07