【发布时间】: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。
【问题讨论】: