Any sort of filters for opengl?

Member
Posts: 306
Joined: 2009.03
Post: #1
I implemented a time stop powerup in my game and I was wondering if there was some way to apply a filter to make everything black and white. I don't want to have to include knowledge of this in all my various rendering code because its very specific to this item. Any thoughts? Maybe some trick about drawing a transparent grey rectangle on top of everything at the very end?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #2
I think the only way it could be done without a shader is to re-render/load all of your textures in grayscale, which certainly isn't hard to do but will require extra memory and/or time.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #3
That would then require all the rendering code to know to switch to using the new texture at the right time. There are no shaders right? So there is no post processing of the entire image in iphone?
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #4
Right, no shaders on current versions of iPhone. I suppose you could render your scene to a texture, then desaturate it, then redraw it as a single texture. I don't know what kind of performance you'd get, but it may be worth a try.
Quote this message in a reply
Member
Posts: 241
Joined: 2008.07
Post: #5
When and if the iPhone ever evolves to be capable of supporting OpenGL ES 2.0 or later (assuming there is such a thing), then you can do shaders. Until then, you have to get creative. Wink
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #6
Ill try a transparent rectangle first. That's the easiest. I don't need it to be 100% black and white, I just want to put a noticable tint of some kind on the screen to make it obvious that something happened
Quote this message in a reply
Member
Posts: 166
Joined: 2009.04
Post: #7
bmantzey Wrote:When and if the iPhone ever evolves to be capable of supporting OpenGL ES 2.0 or later (assuming there is such a thing), then you can do shaders. Until then, you have to get creative. Wink

Oh there is ... in fact there is already hardware (SGX) which supports OpenGL 2.0 ES.
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2009.05
Post: #8
I discoverd a color inversion effect by accident maybe thats what you wan't

Code:
    glBindTexture(GL_TEXTURE_2D, _name);
    if(invert) glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND ); // Color invert
    glVertexPointer(2, GL_FLOAT, 0, vertices);
    glTexCoordPointer(2, GL_FLOAT, 0, coordinates);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
    if(invert) glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // Reset invert
Quote this message in a reply
Nibbie
Posts: 1
Joined: 2009.04
Post: #9
You can do this without shaders on the iPhone - in fact, I use this effect in Ancient Frog for the action replay mode.

The key is that dot3 blending sums the three colour channels, having done some other stuff to them. The trick is to first do the inverse of that other stuff so you're left with just the combined channel values.

You need to first render your scene to a texture. Then, in texture unit 0, you interpolate your screen texture towards mid-grey, and in texture unit 1 you perform a dot3 between that and a colour which defines how the channels are to be mixed. (I use #c0c080ff because it makes the vegetation look a bit like it's been shot with slightly IR-sensitive film, but you can use #aaaaaaff if you want a flat response.)

I'll post code if you need it, but it's more fun to fiddle around and see how it works. (Also I'd need to actually write the code - in Ancient Frog, all of the materials are defined in script files using my own format, so there isn't a conveniently copy-and-pasteable example.)

You can see it in action here.
Quote this message in a reply
Sage
Posts: 1,232
Joined: 2002.10
Post: #10
kendric Wrote:That would then require all the rendering code to know to switch to using the new texture at the right time. There are no shaders right? So there is no post processing of the entire image in iphone?

Greyscale conversion is entirely doable on the iPhone:
1) render scene to texture
2) interpolate scene from [0..1] to [0.5..1] on first texture unit
3) dot product result with weights (average or perceptual) on second unit

You'll have to render to texture to do it, which means additional fillrate overhead. That's the same situation you'd have even if you had shaders, though.
Quote this message in a reply
Moderator
Posts: 3,570
Joined: 2003.06
Post: #11
If anybody happens to be confused about why it seems like arekkusu is echoing AncientMoose's post, it's because AncientMoose's post had to wait to be approved. This post approval thing for new members can be confusing at times. Well anyway, welcome to iDevGames AncientMoose! Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  iPhone High Score Data File/Sort Art and Structure 4 3,660 Jul 4, 2009 01:42 PM
Last Post: Art and Structure