2014-11-08 48 views
0

當前正在製作遊戲,我想添加像水變形一樣好的着色器效果。 我將場景呈現給FBO,然後在其上應用高度圖失真着色器。 失真由片段着色器應用。 normalMapPosition是法線貼圖當前位置的顏色矢量。libgdx heighmap着色器變形artefact

vec2 normalCoord = v_texCoord0; 
vec4 normalMapPosition = 2 * texture2D(u_normals, v_texCoord0); 
vec2 distortedCoord = normalCoord + (normalMapPosition.xz * 0.05); 

然後將其呈現在屏幕上,我得到以下結果

diagonal artifact on shader effect

的問題是,有一個對角線穿越假象的整體形象。 我認爲這是由於紋理的openGL處理​​爲兩個三角形。 有沒有一種很好的方法來處理這類問題?

回答

0

我finaly找到解決辦法,問題來自同一個FBO的利用率來繪製場景,然後渲染着色器,如:

batch.setShader(waterfallShaderProgram) 
fbo.begin(); 
batch.begin(); 
// here is the problem, fbo is started and used to 
// draw at the same time 
batch.draw(fbo.getColorBufferTexture()); 
batch.end() 
fbo.end(); 

場景渲染到FBO fbo以在頂部應用其他效果。 介紹一個新的FBO fbo2解決了這個問題。

batch.setShader(waterfallShaderProgram) 
fbo2.begin(); 
batch.begin(); 
batch.draw(fbo.getColorBufferTexture()); 
batch.end() 
fbo2.end();