2017-01-20 137 views
-2

我正在处理隐藏在源代码中的着色器的项目。我收到此错误(在运行时):着色器编译错误

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++代码类似,从这个意义上来说,这看起来非常直截了当(除非我错过了某些东西)。

这个着色器代码有什么明显的错误吗?

+0

您在日志中得到的错误消息是什么? –

+0

@Nicol:如何检查日志? – George

+2

[见此](https://www.khronos.org/opengl/wiki/Shader_Compilation#Example)。 [或此](http://stackoverflow.com/documentation/opengl/8685/shader-loading-and-compilation#t=201701200148341908547) –

回答

1

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

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

#version 110不支持自动int - >float转换。使用float文字代替:

gl_Position = vec4(aPosition.xy, 0.0, 1.0); 
           ^^^ ^^^ float literals 
+0

感谢您的提示。我试着相应地修改,并且错误仍然存​​在。 – George

+0

@George:那么[mcve]的时间。 – genpfault