问题描述
使用LibGDX,我试图弄清楚如何编写一个简单的片段着色器,该着色器可以使用简单的正弦效果在X和Y方向上渲染平铺的水纹理,但要确保相邻的平铺对象仍处于连接状态纹理边缘(参见图片)。我很难弄清楚这个简单的事情-我的数学可能有点生锈。你能帮我吗?
当然,当纹理坐标向内偏移时,着色器无法“猜测”纹理负部分上的内容,但是纹理是自连接的镶嵌,因此我想可以在此处完成。
片段着色器是:
#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D u_texture; // 0
uniform float time; // elapsed time
uniform float xFactor; // controls effect amplitude in the X and Y directions
uniform float yFactor;
uniform float xWobble; // de-synchronize X and Y 'wobling' effect between layers
uniform float yWobble;
const float M_PI = 3.1415926538;
varying vec2 v_texCoords;
void main()
{
vec2 l_texCoords = v_texCoords;
l_texCoords = v_texCoords + vec2(xFactor * sin((1. - v_texCoords.x) * 2. * M_PI + time * xWobble),yFactor * cos((1. - v_texCoords.y) * 2. * M_PI + time * yWobble));
gl_FragColor = texture2D(u_texture,l_texCoords);
}
然后,在Java方面,我这样做:
batch.setShader(waterShader);
batch.setProjectionMatrix(backgroundCamera1.combined); //Background 1
batch.begin();
batch.getShader().setUniformf("time",deltaAcc);
batch.getShader().setUniformf("xFactor",0.05f);
batch.getShader().setUniformf("yFactor",0.07f);
batch.getShader().setUniformf("xWobble",0.12f);
batch.getShader().setUniformf("yWobble",0.22f);
batchTileMapRenderer.setView(backgroundCamera1);
bTileMapRenderer.renderTileLayer(tilesBg1Layer); // The water layer,with 128x128 tiles
batch.end();
batch.setShader(null);
我希望您能阐明这个看似简单的问题...
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)