【发布时间】:2021-10-06 18:32:09
【问题描述】:
大家好使用 libgdx!
由于着色器,我在游戏中有 40 fps。这个着色器绘制背景,我想减少它处理的像素数。
在 Create 方法中,我使用 Pixmap 生成一个纹理,其宽度和高度是实际屏幕尺寸的 1/10。
pixmap = new Pixmap( (int)(Math.ceil(WIDTH/10f)), (int)(Math.ceil(HEIGHT/10f)), Pixmap.Format.RGBA8888 );
backGround = new Texture(pixmap);
然后我将 camera.zoom 设置为 0.1,因此纹理现在是全屏的。
camera.position.set( WIDTH/2f*0.1f, HEIGHT/2f*0.1f, 0);
camera.zoom = 0.1f;
camera.update();
batch.setProjectionMatrix(camera.combined);
然后 Render 方法中的着色器画了一个圆,但是该着色器处理屏幕的像素而不是纹理的像素,我得到了像以前一样漂亮流畅的画面。
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.draw(backGround,0,0);
片段着色器的代码:
vec3 yellow = vec3(0.93, 0.93, 0.32);
vec2 relativePosition = gl_FragCoord.xy / u_ScreenResolution;
relativePosition.x *= u_ScreenResolution.x / u_ScreenResolution.y;
float normDistance = pow( ( pow(relativePosition.x - 0.3,2.0) + pow(relativePosition.y - 0.5,2.0) ), 0.5 );
int distance = int( round( normDistance + 0.4 ) );
gl_FragColor = vec4(vec3(0.0) + yellow*clamp(1.0-distance, 0.0, 1.0), 1.0);
不确定我是否正确地表达了这个想法,所以这是一张图片:
【问题讨论】:
标签: android opengl-es libgdx shader textures