着色器编译错误

时间:2017-01-20 01:27:49

标签: c++ opengl shader

我正在开发一个隐藏在源代码中的着色器的项目。我收到此错误(在运行时):

Error compiling vertex shader:

Full VS shader source:

//precision highp float;

uniform vec2 uEyeToSourceUVScale;
uniform vec2 uEyeToSourceUVOffset;

attribute vec4 aPosition;         ///< [-1,+1],[-1,+1] over the entire framebuffer. Lerp factor in Pos.z. Vignette fade factorin Pos.w.
attribute vec2 aTanEyeAnglesR;   ///< The tangents of the horizontal and vertical eye angles for the red channel.
attribute vec2 aTanEyeAnglesG;   ///< The tangents of the horizontal and vertical eye angles for the green channel.
attribute vec2 aTanEyeAnglesB;   ///< The tangents of the horizontal and vertical eye angles for the blue channel.

varying vec4 vPosition; 
varying vec2 vTexCoordR; 
varying vec2 vTexCoordG; 
varying vec2 vTexCoordB; 

void main(void)
{
    vPosition = aPosition;
    vTexCoordR = aTanEyeAnglesR * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordG = aTanEyeAnglesG * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordB = aTanEyeAnglesB * uEyeToSourceUVScale + uEyeToSourceUVOffset;
    vTexCoordR.y = 1.0 - vTexCoordR.y;
    vTexCoordG.y = 1.0 - vTexCoordG.y;
    vTexCoordB.y = 1.0 - vTexCoordB.y;
    gl_Position = vec4(aPosition.xy, 0, 1);
}

Shader compilation failed.

我不知道如何解决这个问题(没有着色器体验);但是,我知道着色器代码类似于C ++代码,从这个意义上来说,这看起来非常直接(除非我遗漏了一些东西)。

此着色器代码是否存在明显错误?

1 个答案:

答案 0 :(得分:1)

缺少#version指令意味着#version 110

gl_Position = vec4(aPosition.xy, 0, 1);
                                 ^  ^ int literals

#version 110不支持自动int - &gt; float次转化。请改用float文字:

gl_Position = vec4(aPosition.xy, 0.0, 1.0);
                                 ^^^  ^^^ float literals
相关问题