2013-03-07 44 views
1

有人能指出我正確的方向來創建可在GL ES 2.0上運行的效果similar to this嗎?GL ES 2.0中的簡單通道偏移着色器

.vert

uniform vec2 uAberrationOffset; 

void main() { 
    gl_TexCoord[0] = gl_MultiTexCoord0; 
    gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex; 
} 

.frag

uniform sampler2DRect baseTex; 
uniform vec2 uAberrationOffset; 

void main() { 


vec4 coords = gl_TexCoord[0]; 

// baseTex is FBO of screen (1280x800 -> non-square) 
// offset red 
vec4 fbo1 = texture2DRect(baseTex, coords.xy - uAberrationOffset); 
// keep green where it is 
vec4 fbo2 = texture2DRect(baseTex, coords.xy); 
// offset blue 
vec4 fbo3 = texture2DRect(baseTex, coords.xy + uAberrationOffset); 

// FBO channels mixed (incl. offsets) 
vec4 colFinal = vec4(fbo1.r, fbo2.g, fbo3.b, 1.); 

// Output final pixel color 
gl_FragColor = colFinal; 
} 

回答

2

以下嬰兒的步驟可以讓你的端口,這些着色器ES 2.0。

  • 不要使用舊校服:gl_ProjectionMatrixgl_ModelViewMatrix。將這些替換爲用戶定義的制服。

  • sampler2DRecttexture2DRect ES中不支持,但你可以使用普通samplertexture2D呼籲這種效果。

  • gl_MultiTexCoord0gl_Vertex是老派屬性。您需要用用戶定義的頂點屬性來替換它們。