2017-01-20 135 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