Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-19-2012, 03:36 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Age: 25
Posts: 169
mer10 is on a distinguished road
Default Grayscale Frag Shader is killing my frame rate

Granted it's expected.... but I'm looking for suggestions on what I could do to improve the performance. Currently it's causing my app to dip just below 30 FPS(normally at 50 or 60 FPS but I cap it at 30).

Here is the code for GrayScale.fsh

varying lowp vec4 colorVarying;
varying mediump vec2 TextureCoordOut;
uniform sampler2D Sampler;
varying lowp vec4 ColorOut;
lowp vec4 fragColor;
lowp float luminance;
void main()
{
fragColor=texture2D(Sampler, TextureCoordOut)*ColorOut;
luminance=fragColor.r*.2126+fragColor.g*.7152+.072 2*fragColor.b;
gl_FragColor=vec4(luminance,luminance,luminance,fr agColor.a);
}

Help is greatly appreciated!
mer10 is offline   Reply With Quote
Old 01-19-2012, 06:49 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mer10 View Post
Granted it's expected.... but I'm looking for suggestions on what I could do to improve the performance. Currently it's causing my app to dip just below 30 FPS(normally at 50 or 60 FPS but I cap it at 30).

Here is the code for GrayScale.fsh

varying lowp vec4 colorVarying;
varying mediump vec2 TextureCoordOut;
uniform sampler2D Sampler;
varying lowp vec4 ColorOut;
lowp vec4 fragColor;
lowp float luminance;
void main()
{
fragColor=texture2D(Sampler, TextureCoordOut)*ColorOut;
luminance=fragColor.r*.2126+fragColor.g*.7152+.072 2*fragColor.b;
gl_FragColor=vec4(luminance,luminance,luminance,fr agColor.a);
}

Help is greatly appreciated!

Are you sure it's the shader that's doing it? Try setting your fragment color to a fixed value (commenting out your texture and your luminance value) and test that. I bet there's no difference in speed. Fragment shaders are farmed out to the compute units on the GPU, and run VERY fast.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-20-2012, 10:40 AM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Age: 25
Posts: 169
mer10 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Are you sure it's the shader that's doing it? Try setting your fragment color to a fixed value (commenting out your texture and your luminance value) and test that. I bet there's no difference in speed. Fragment shaders are farmed out to the compute units on the GPU, and run VERY fast.
I tried that. My original frag shader only had this line in main() and didn't have the fragColor or Luminance in it. Worked well.

gl_FragColor=texture2D(Sampler, TextureCoordOut)*ColorOut;

All of the changes I made when comparing the two were in the frag shader. Perhaps I'm doing something wrong??
mer10 is offline   Reply With Quote
Old 01-20-2012, 11:48 AM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by mer10 View Post
I tried that. My original frag shader only had this line in main() and didn't have the fragColor or Luminance in it. Worked well.

gl_FragColor=texture2D(Sampler, TextureCoordOut)*ColorOut;

All of the changes I made when comparing the two were in the frag shader. Perhaps I'm doing something wrong??
Dunno. I'm a neophyte when it comes to OpenGL shaders. It might be that one of the calculations you're doing is causing the compute units in the GPU to thrash. Maybe you're asking to do double precision math, for example, or convert parameters to different precision? I understand that can be slow.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-20-2012, 01:29 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2011
Age: 25
Posts: 169
mer10 is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Dunno. I'm a neophyte when it comes to OpenGL shaders. It might be that one of the calculations you're doing is causing the compute units in the GPU to thrash. Maybe you're asking to do double precision math, for example, or convert parameters to different precision? I understand that can be slow.
Maybe...i'll have to look into it more. Thanks!
mer10 is offline   Reply With Quote
Reply

Bookmarks

Tags
grayscale, opengl

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 407
10 members and 397 guests
7twenty7, Atatator, FrankWeller, glenn_sayers, guusleijsten, iphonedevshani, QuantumDoja, Sami Gh, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,122
Posts: 402,907
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:45 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0