2014-03-25 32 views
3

我試圖在Galaxy Tab 3上使用自定義着色器,但它們未能編譯或鏈接。這是代碼。 這是頂點着色器在Vivante GC1000 GPU(Galaxy Tab 3)上編譯/鏈接着色器

attribute vec4 a_position; 
attribute vec2 a_texCoord; 

uniform sampler2D u_texture; 
varying vec2  blurs[8]; 
uniform vec2  blurSize; 

#ifdef GL_ES 
varying lowp vec2 v_texCoord;      
#else      
varying vec2 v_texCoord; 
#endif 

void main() 
{ 
    gl_Position = CC_MVPMatrix * a_position; 
    v_texCoord = a_texCoord; 

    blurs[0] = v_texCoord + vec2(-0.016, 0.0) * blurSize; 
    blurs[1] = v_texCoord + vec2(-0.012, 0.0) * blurSize; 
    blurs[2] = v_texCoord + vec2(-0.008, 0.0) * blurSize; 
    blurs[3] = v_texCoord + vec2(-0.004, 0.0) * blurSize; 
    blurs[4] = v_texCoord + vec2(0.004, 0.0) * blurSize; 
    blurs[5] = v_texCoord + vec2(0.008, 0.0) * blurSize; 
    blurs[6] = v_texCoord + vec2(0.012, 0.0) * blurSize; 
    blurs[7] = v_texCoord + vec2(0.016, 0.0) * blurSize; 
} 

這是片段着色器

#ifdef GL_ES 
precision lowp float; 
#endif 

varying vec2 v_texCoord; 
varying vec2 blurs[8]; 
uniform sampler2D u_texture; 

//uniform vec2 blurSize; 
uniform vec4 substract; 

void main() { 
    gl_FragColor = vec4(0.0); 
    gl_FragColor += texture2D(u_texture, blurs[0])*0.0443; 
    gl_FragColor += texture2D(u_texture, blurs[1])*0.0776; 
    gl_FragColor += texture2D(u_texture, blurs[2])*0.1158; 
    gl_FragColor += texture2D(u_texture, blurs[3])*0.1473; 
    gl_FragColor += texture2D(u_texture, v_texCoord  )*0.1595; 
    gl_FragColor += texture2D(u_texture, blurs[4])*0.1473; 
    gl_FragColor += texture2D(u_texture, blurs[5])*0.1158; 
    gl_FragColor += texture2D(u_texture, blurs[6])*0.0776; 
    gl_FragColor += texture2D(u_texture, blurs[7])*0.0443; 
} 

在ipad,結點設備和星系S3/S4和說明3能正常工作。但在galaxy標籤3(與vivante gc1000 gpu)無法編譯或鏈接;我不確定哪一個失敗。 下面是logcat的錯誤:

03-25 20:59:36.328 D/v_gal (3167): [tid=3179] gcmONERROR: status=-10(gcvSTATUS_TOO_COMPLEX) @ _GenerateStates(10194) 
03-25 20:59:36.328 D/v_gal (3167): [tid=3179] gcmONERROR: status=-10(gcvSTATUS_TOO_COMPLEX) @ gcLINKTREE_GenerateStates(11342) 
03-25 20:59:36.328 D/v_gal (3167): [tid=3179] gcmERR_BREAK: status=-10(gcvSTATUS_TOO_COMPLEX) @ gcLinkShaders(7831) 
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR: Failed to link program: 25 
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG PROGRAM: (null) 
03-25 20:59:36.328 D/v_gal (3167): [tid=3179] gl2mERROR: result=0x0501 @ glGetShaderiv(886) 
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG VERTEX: (null) 
03-25 20:59:36.328 D/v_gal (3167): [tid=3179] gl2mERROR: result=0x0501 @ glGetShaderiv(886) 
03-25 20:59:36.328 D/cocos2d-x debug info(3167): cocos2d: ERROR LOG FRAG: (null) 

錯誤日誌程序,錯誤日誌VERTEX,錯誤日誌FRAG是glGetProgramInfoLog和glGetShaderInfoLog呼叫。他們都返回null

+0

Andres,這種模糊效果對你有好處嗎?我假設有一個垂直模糊的第二遍,對吧?你有任何截圖嗎? – nmr

回答

2

Vivante GC1000最多有8個不同的載體,由glGetIntegerv(GL_MAX_VARYING_VECTORS)返回。許多ES設備具有相同的最大值。您目前使用9個變化向量着色(v_texCoord + 8模糊座標),這就是着色器編譯器告訴您輸入過於複雜的原因。要解決你的問題,你可以結合你的8模糊協調vec2的爲4 vec4的,使用.xy.zw組件原來的vec2偏移,例如

在VS:

varying vec2 blurs[8]; 
… 
blurs[0] = v_texCoord + vec2(-0.016, 0.0) * blurSize; 
blurs[1] = v_texCoord + vec2(-0.012, 0.0) * blurSize; 

能成爲

varying vec4 blurs[4]; 
... 
blurs[0] = v_texCoord.xyxy + vec4(-0.016, 0.0, -0.012, 0.0) * blurSize; 

而在PS:

varying vec2 blurs[8]; 
… 
gl_FragColor += texture2D(u_texture, blurs[0])*0.0443; 
gl_FragColor += texture2D(u_texture, blurs[1])*0.0776; 

變爲:

varying vec4 blurs[4]; 
… 
gl_FragColor += texture2D(u_texture, blurs[0].xy)*0.0443; 
gl_FragColor += texture2D(u_texture, blurs[0].zw)*0.0776; 

希望幫助!

+0

在某些平臺和設備(例如:較舊的iOS設備)上,調整'vec4'以提取'vec2'座標將導致依賴紋理讀取而降低性能。見[這裏](https://developer.apple.com/library/ios/documentation/3DDrawing/Conceptual/OpenGLES_ProgrammingGuide/BestPracticesforShaders/BestPracticesforShaders.html#//apple_ref/doc/uid/TP40008793-CH7-SW18):「packing將多組紋理座標合併到一個單獨的變化參數中,並使用swizzle命令來提取座標仍會導致依賴紋理讀取。「 – TachyonVortex