【问题标题】:Why does sprite size affect performance in OpenGL ES 2.0/3.0?为什么精灵大小会影响 OpenGL ES 2.0/3.0 中的性能?
【发布时间】:2020-03-26 09:58:54
【问题描述】:

有一个爆炸的粒子系统: 顶点着色器:

#version 300 es
uniform float u_lastTimeExplosion; // time elapsed since the explosion
// explosion center (particle coordinates are set relative to this center
uniform vec3 u_centerPosition; 
uniform float u_sizeSprite;
layout(location = 0) in float a_lifeTime; // particle lifetime in seconds
// initial position of the particle at the time of the explosion
layout(location = 1) in vec3 a_startPosition;
layout(location = 2) in vec3 a_endPosition; // final position of the particle
out float v_lifeTime; // remaining particle lifetime
void main()
{
    gl_Position.xyz = a_startPosition + (u_lastTimeExplosion * a_endPosition);
    gl_Position.xyz += u_centerPosition;
    gl_Position.w = 1.0;
    // calculate the remaining particle lifetime
    v_lifeTime = 1.0 - (u_lastTimeExplosion / a_lifeTime);
    v_lifeTime = clamp(v_lifeTime, 0.0, 1.0);
    // calculate sprite size based on remaining life time
    gl_PointSize = pow(v_lifeTime, 5.0) * u_sizeSprite;
}

片段着色器:

#version 300 es
precision lowp float;
in float v_lifeTime;
uniform vec4 u_color;
out vec4 fragColor;
uniform sampler2D s_texture;
void main()
{
    vec4 texColor = texture(s_texture, gl_PointCoord);
    fragColor = u_color * texColor;
    fragColor.a *= v_lifeTime; // increase sprite transparency
}

如果精灵的大小小于10,那么一切都很好:

GLES20.glUniform1f(sizeSpriteLink, 10f);

如果精灵的大小增加,则渲染速度会变慢(FPS 降低):

GLES20.glUniform1f(sizeSpriteLink, 150f);

奇怪的是 - 精灵的数量对性能的影响小于它们的大小。

问题:为什么精灵大小会影响性能?如有任何回答/评论,将不胜感激。

注意:使用了粒子纹理的 mipmap。

【问题讨论】:

    标签: java android opengl-es


    【解决方案1】:

    不确定,但似乎增加精灵的大小会极大地影响图形内存资源的消耗。也许有人知道这件事?

    最好使用这种类型的过滤来提高性能:

    // one value is taken from the nearest pyramid level
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
            GLES20.GL_NEAREST_MIPMAP_NEAREST);
    

    【讨论】:

      猜你喜欢
      • 2013-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-25
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多