本文介绍了使用glvertex4i传递网格面索引时的顶点着色器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初始化GL_List进行处理.

Initializing GL_List for processing.

glBegin(GL_POINTS); 
for (i = 0; i < faceNum; i++)
{
    mesh->GetFaceNodes(i + 1, ver[0], ver[1], ver[2], ver[3]);
    **glVertex4i(ver[0] - 1, ver[1] - 1, ver[2] - 1, i+1);**
}
glEnd();    
glEndList();

顶点着色器给我一个编译错误,不知道为什么.

Vertex Shader gives me a compilation error and doesn't know why.

顶点着色器:

varying out float final;

void main( void )
{
    final = float(gl_Vertex.w);       // want to pass this face index on to 
}

几何着色器:

varying in float final[];
varying out float final_tofrag;
final_tofrag=final[0];


//Doing other calculations here they are totally different 

片段着色器:

varying in float final_tofrag;

void main( void )
{
    if (color.z<0.0)
            gl_FragData[0] = vec4(float(final_frag),float(final_frag), -(gl_FragCoord.z), 0); // want to check that value of the final(gl_vertex.w) is being passed from vertex shader to fragment shader or not. Its giving me 0.00000;
    else
            gl_FragData[0] = vec4(float(final_frag), float(final_frag), gl_FragCoord.z, 0);
}

推荐答案

问题中的代码没有任何意义.之所以选择GLSL关键字varying,是因为其意图反映的特性是,由于跨基元的自动插值,每个片段的数据将有所不同.这仅发生在rasrererizer之前的最后一个可编程着色器阶段和片段着色器之间.

The code in the question does not make any sense. The GLSL keyword varying was chosen because it was meant to reflect the property that the data will be different for each fragment, due to the automatic interpolation across the primitive. This happens only between the last programmable shader stage before the rasrerizer and the fragment shader.

一开始,只有顶点着色器和片段着色器. VS将获得attribute s作为输入,并输出到varying s,这将是插值并成为FS的输入.

In the beginning, there was only the vertex shader and the fragment shader. The VS would get attributes as input, and output to varyings, which would be interpolation and become inputs to the FS.

随着GL 3.0/GLSL 1.30中的几何着色器的引入,该方案不再有意义. VS的输出将不再被插值,而是成为GS的直接输入.结果,关键字attributevarying从GLSL中删除,并由更通用的in/out方案代替.

With the introduction of the Geometry Shader in GL 3.0 / GLSL 1.30, this scheme did not make sense any more. The outputs of the VS would not be interpolated any more, but become direct inputs of the GS. As a result, the keywords attribute and varying where removed from GLSL, and replaced by the more general in / out scheme.

因此,不存在带有varying的GS.您可以使用不支持几何着色器"的旧版GLSL,或者使用具有in/out的较新GLSL.

As a result, a GS with varying cannot exist. You either use legacy GLSL which doesn't support Geometry Shaders, or you use a newer GLSL with in/out.

这篇关于使用glvertex4i传递网格面索引时的顶点着色器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:58