English 中文(简体)
OpenGL ES 遮光镜会降低太多性能
原标题:OpenGL ES shader degrades too much performance

我正优化一个双向的游戏, iPhone 和 Android。 我用4个阴影来绘制场景, 我注意到如果我把其中一个变换成另一个, 纤维灯泡会从32个增加到42个, 即使只有1个符号是用这个阴影画的, 而这2个阴影的唯一区别就是 碎片阴影里的一个产品。

这些是遮蔽者,

默认 2d- tex. shader

#ifdef GL_ES
precision highp float;
precision lowp int;
#endif

#ifdef VERTEX

uniform mat4        umvp;

attribute vec4      avertex;
attribute vec2      auv;

varying vec2        vuv;

void main()
{
    // Pass the texture coordinate attribute to a varying.
    vuv = auv;

    // Here we set the final position to this vertex.
    gl_Position = umvp * avertex;
}

#endif

#ifdef FRAGMENT

uniform sampler2D   map0;
uniform vec4 ucolor;

varying vec2        vuv;

void main()
{
    gl_FragColor =  texture2D(map0, vuv) * ucolor;
}

#endif

默认 2d- tex- white. shader

#ifdef GL_ES
precision highp float;
precision lowp int;
#endif

#ifdef VERTEX

uniform mat4        umvp;

attribute vec4      avertex;
attribute vec2      auv;

varying vec2        vuv;

void main()
{
    // Pass the texture coordinate attribute to a varying.
    vuv = auv;

    // Here we set the final position to this vertex.
    gl_Position = umvp * avertex;
}

#endif

#ifdef FRAGMENT

uniform sampler2D   map0;

varying vec2        vuv;

void main()
{
    gl_FragColor =  texture2D(map0, vuv);
}

#endif

Again,
If I modify 默认 2d- tex. shader and remove the product "* ucolor", the fps goes from 32 to 42, and I m using it for just one sprite in the scene!

这正常吗?为什么这个遮光剂这么慢,我怎么才能改进它呢?

<强度 > EDIT:

我看到iPod和Android的性能减慢,比例相等。两者均为PowerVr SGX GPUs(iPod 3 gen和三星银河SL-PowerVR SGX 530-),iOS版本为4.1,Android版本为2.3.3。

绘图图I m 缩放以填充屏幕( 缩放为 4x), 我绘制每框架一次 。 它取自质地图, 因此纹理实际上更大( 1024x1024), 但所拍摄的部分为 80x120 。 启用了 Alpha 混合 。

<强 > EDIT 2

I made a mistake. The sprite is scaled 11x: its 32x48. If I don t draw that sprite at all, fps goes to 45. I m drawing a lot of sprites in the scene, why is that one taking so much time? Could it be because it s scaled so much?

最佳回答

当你从上述代码中删除“*ucolor”时,

  1. uniform ucolor becomes unused
  2. GLSL compiler removes this uniform from the active uniforms set
  3. when you have you program linked the ID of the missing uniform becomes -1
  4. when you do glUniform4fv( -1, value ) for the removed uniform it just exits instantly, without any update

与“* ucolor”的设置相比,这项工作要少得多。

此外,这是在碎片阴影器中每个碎片少一个操作。

问题回答

Your problem is in your fragment shader in default-2d-tex.shader. You have uniform vec4 ucolor; That means, that each of your color s components (RGBA) will be converted to 32-bits float value. And this drops performance heavily. Should be: uniform lowp vec4 ucolor;





相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签