纹理协调器是否通过各种着色器管道? [英] Do the texture coordiantes go through the various Shader pipeline?

查看:166
本文介绍了纹理协调器是否通过各种着色器管道?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以如果我有这个代码

const char* vertex_shader =
      "#version 400\n"
      "layout(location =  0) in vec2 vp;"
      "layout(location = 1) in vec2 tex;"
      "out vec2 texCoord;"
      "void main () {"
      "  gl_Position = vec4 (vp, 0.0f, 1.0f);"
      "  texCoord = tex; "
      "}";

   const char* fragment_shader =
      "#version 400\n"
      "uniform sampler2D s;"
      "in vec2 texCoord;"
      "out vec4 color;"
      "void main () {"
      "color = texture(s, texCoord);"
      "}";

我想知道的是,根据我的理解,给顶点着色器的顶点,一旦通过顶点着色器,它会转到光栅化

What i would like to know is that based on what i understand , the vertices given to vertex shader , once it passes the vertex shader it goes to Rasterization which is


光栅化是一个过程,根据
原语的样本覆盖率,每个单独的Primitive是
分解成离散元素。

Rasterization is the process whereby each individual Primitive is broken down into discrete elements based on the sample coverage of the primitive.

由于实际的tex坐标是作为具有顶点的图元给出的,所以它在被转换到各个空格之后也被分解,以便生成

Since the actual tex-coordinates is given as a primitive with vertices, does it also get broken down after being transformed to the various spaces , in order to generate al the fragments that fall within its range?

如果它们没有,那么片段着色器如何获取数据,将它们放在实际渲染的基元上?

And if they dont , then how does the fragment shader get the data where to put them on the actual rendered primitive?

如果你要用数学来回答这个问题,请记住我是一个初学者,你需要彻底解释。

Please also if your going to answer this question with mathematics, bear in mind i am a beginner and you will need to explain it thoroughly

到目前为止,我已经看过解释这个过程我还没有明白,因为所有的矩阵谈话,我甚至不确定涵盖我问的问题

So far what i have seen explaining this process i have not understood due to all the matrices talk, which i am not even sure covers the question i am asking about

我知道矩阵和向量,但非常基本的水平,所以保持所有的数学谈基本和解释,没有一个直观的知识,因为我没有它

i do understand matrices and vectors, but very basic level so keep all maths talk basic and explained, none of that intuitive knowledge cause i dont have it yet

推荐答案

光栅化只对每个三角形发生一次。所以,如果你想知道纹理坐标是否是像栅格化的位置,答案是:不。

Rasterization only happens once for each triangle. So if you're wondering if the texture coordinates are rasterized just like the positions, the answer is: No.

你看的过程,这是一部分在顶点和片段着色器之间执行的固定功能块由两个主要步骤组成:

The process you're looking at, which is part of the fixed function block that is executed between vertex and fragment shader, consists of two main steps:


  1. 片段< >。此步骤枚举每个三角形内的所有片段,纯粹基于作为顶点着色器(*)的输出生成的 gl_Position 值用于三个三角形顶点。

  2. 顶点着色器输出是 interpolated ,意味着为步骤1中生成的每个片段计算每个输出的值。这需要3个三角形顶点(您的顶点着色器生成),然后在三角形内插这些值,以计算每个片段的值。

  1. Fragments are generated. This step enumerates all fragments that are inside each triangle, based purely on the gl_Position value that you produced as output of your vertex shader (*) for each of the 3 triangle vertices.
  2. Vertex shader outputs are interpolated, meaning that a value for each output is calculated for each fragment generated in step 1. This takes the output at each of the 3 triangle vertices (which your vertex shader produced), and then interpolates those values across the triangle to calculate a value for each fragment.

内插值的计算发生在重心坐标中,这意味着计算三角形内每个片段的重心坐标,然后线性插值顶点值以获得在这些重心坐标处的片段的值。

The calculation of the interpolated values happens in barycentric coordinates, meaning that the barycentric coordinates of each fragment within the triangle are calculated, and then the vertex values are interpolated linearly to get the value for the fragment at those barycentric coordinates.

由此产生的插值顶点着色器输出值被用作相应片段着色器输入的值。因此,当为步骤1中生成的每个片段调用片段着色器时,在步骤2中计算的内插值变为片段着色器的输入。

The interpolated vertex shader output values resulting from this are then used as the values for the corresponding fragment shader input. So when the fragment shader is invoked for each of the fragments generated in step 1, the interpolated values calculated in step 2 become the inputs for the fragment shader.

只有顶点着色器的 gl_Position 输出用于生成片段,但是所有输出(在您的示例中是位置和纹理坐标)都是内插的。

In summary, only the gl_Position output of the vertex shader is used to generate fragments, but all outputs (which are the position and texture coordinates in your example) are interpolated.

gl_Position 的特殊作用也解释了为什么它在OpenGL核心配置文件中仍然是一个预定义的变量,而大多数其他预定义变量

This special role of gl_Position also explains why it's still a predefined variable in the OpenGL core profile, while most of the other predefined variables that used to be present in older versions of OpenGL have been removed.

(*)应用于 gl_Position 值,然后到达这个阶段,如透视分割和裁剪。

(*) There is additional processing that is applied to the gl_Position value before it gets to this stage, like perspective division and clipping.

这篇关于纹理协调器是否通过各种着色器管道?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆