码迷,mamicode.com
首页 > 其他好文 > 详细

Opengl_07_插值

时间:2017-01-04 07:48:49      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:images   保存   als   之间   variable   cts   alt   spec   法向量   

1,
光栅器对从顶点着色器传来的变量插值。

为了在屏幕上真正显示,必须将顶点着色器vs的输出变量设置为‘gl_Position‘,gl_Position是一个保存着顶点齐次坐标的4维向量。XYZ分量被W分量所分割(称作视角分割,这个是教程的重点话题)并且XYZ分量上超出单位化盒子([-1,1])的部分会被裁剪掉。最终的结果会被转换到屏幕坐标系然后三角形(或者其他支持的图元类型)被光栅器渲染到屏幕上。

光栅器在三角形的三个顶点之间进行插值(或者通过另外一种技术一行一行的插值)并执行片断着色器遍历三角形的每一个像素。
片断着色器会返回光栅器存在颜色缓存中用于显示的像素颜色值。

从顶点着色器传来的其他的变量不会经过上面的步骤。如果片断着色器没有显式地请求那个变量那么一般的驱动优化会丢弃顶点着色器vs中只是影响该变量的操作。但如果片断着色器fs确实使用到了那个变量,光栅器会在光栅化阶段对其进行插值,并且每一次片断着色器fs的调用都会提供一个匹配特定位置的插值后的值,这意味着相邻的两个像素的值都略有不同。

技术分享


技术分享

在各渲染管线之间进行传递的参数必须在
shader中使用‘out‘保留字来全局的进行声明定义。

2,
三角形的法向量和纹理坐标是很常见的两种依赖插值变量

顶点的法向量通常是包含这个顶点的所有三角形法向量的平均值。如果物体不是平坦的话那么每个三角形的三个顶点的法向量会各不相同,那样我们可以通过插值来计算每个像素的法向量,那些向量会用于光线的计算,从而产生更逼真可信的光照效果。
对于纹理坐标的应用也类似,这些插值结果作为模型的一部分定义在每个顶点上。为了用贴图覆盖三角形你需要对每个像素进行一样的插值操作并给每个像素制定正确的纹理坐标,
这些坐标都是插值的结果。
Two very common variables that often rely on this interpolation are the triangle normal and texture coordinates. The vertex normal is usually calculated as the average between the triangle normals of all triangles that include that vertex. If that object is not completely flat this usually means that the three vertex normals of each triangle will be different from each other. In that case we rely on interpolation to calculate the specific normal at each pixel. That normal is used in lighting calculations in order to generate a more believable representation of lighting effects. The case for texture coordinates is similar. These coordinates are part of the model and are specified per vertex. In order to "cover" the triangle with a texture you need to perform the sample operation for each pixel and specify the correct texture coordinates for that pixel. These coordinates are the result of the interpolation.

Opengl_07_插值

标签:images   保存   als   之间   variable   cts   alt   spec   法向量   

原文地址:http://www.cnblogs.com/liuhan333/p/6247178.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!