Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy does a single Vec4 multiplication slow down my ogl es 2 fragment shader so much?
    primarykey
    data
    text
    <p>I'm writing a 2D OpenGL game for iOS devices. Right now, i'm looking at the performance on iPad (first gen). The game has code paths for ogl 1.1 and 2.0, and I can switch which one is being used with a <code>#define</code>.</p> <p>When using ogl 2.0, the profiler tells me that my Renderer Utilization % is a fairly steady 100%, and my framerate is about 30 fps. When using ogl 1.1, the profiler tells me that my Renderer Utilization % is ~60% and my framerate is 60 fps.</p> <p>I want to improve the performance with ogl 2.0, and being fill rate limited, I suspected the fragment shader. Here is the fragment shader that was being used:</p> <pre><code>precision highp float; uniform vec4 u_color; uniform sampler2D u_sampler0; varying vec2 v_texCoord; void main() { gl_FragColor = u_color * texture2D( u_sampler0, v_texCoord ); } </code></pre> <p>You can see that the shader is pretty simple. It's just multiplying the geometry color by the texture color. As an experiment, I removed the multiplication, so that the output color was just the texture color, like this:</p> <pre><code>precision highp float; uniform vec4 u_color; uniform sampler2D u_sampler0; varying vec2 v_texCoord; void main() { gl_FragColor = texture2D( u_sampler0, v_texCoord ); } </code></pre> <p>Profiling the code using this modified shader gave a Renderer Utilization % of ~60% and a framerate of 60fps, the same performance achieved by the ogl 1.1 codepath.</p> <p>My question:</p> <p>1) Should a simple Vec4 multiplication in the fragment shader really have this large a negative effect on the performance?</p> <p>2) I've heard it said that on ogl es 2 devices, the 1.1 functionality is implemented with shaders. Obviously these shaders manage to efficiently achieve the effect i'm going for (blending geom color into texture color). How can I efficiently achieve this effect in my ogl 2 shader?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload