Results 1 to 3 of 3

Thread: Fragment shader for detecting contour pixels

  1. #1
    Junior Member
    Join Date
    Jun 2008
    Posts
    13

    Fragment shader for detecting contour pixels

    Hi,

    i have the need to do the following thing. I am working with a 2D engine called cocos2D-x. This engine draws the sprite of the game as textured quads.
    Texture have alpha component. Pixels with alpha=255 (or 1.0f) are totally opaque, while pixels with alpha=0 are totally transparent.

    I would like to add the following functionality: when drawing a sprite, i want to be able to
    detect pixels that are contour pixels. A contour pixel is a pixel that is totally opaque and that it is adjacent to at least a totally transparent pixel. Once detected, i want to change its color in some ways.

    First question: can this be done with OpenGL ES?
    Second question: can someone show me a simple way to do this? Even a starting point would be really useful.

    What concerns me is the possibility to access adjacent pixels, that is, given pixel at coordinates (x,y), i need to check 4-neighboring or 8-neighboring. For example, for 4-neighboring that means checking the alpha of the following pixels:

    (x+1,y)
    (x-1,y)
    (x,y-1)
    (x,y+1)


    Third question: is OpenGL ES 2.0 in wide use or should avoid it? At my company we are writing a simple game for iPhone/Android platforms. While iPhone support 2.0 ES, i am wondering if Android phones are already there and if supporting OpenGL ES 2.0 is not a premature thing to do.

    Thank you.

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    353

    Re: Fragment shader for detecting contour pixels

    OpenGL ES 2.0 is widely supported on Android smartphones today.

    It's certainly doable, you just sample the sprite texture several times in your fragment shader with texture coordinates adjusted so they represent a +/-1 pixel offset. That said, if the sprites are static I think you should really do this contour detection as a preprocess pass generating a contour mask texture (which you could potentially combine with the alpha information, depending on the pixel format used).
    Georg Kolling, Imagination Technologies
    Please ask questions specific to PowerVR hardware or SDKs on the PowerVR Insider Forum
    DevTech@imgtec.com | http://www.powervrinsider.com

  3. #3
    Junior Member
    Join Date
    Jun 2008
    Posts
    13

    Re: Fragment shader for detecting contour pixels

    Thx, it was not difficult, but it was absolutely my first shader at all!
    And obviously yes, i will do that job off-line. Thx for your advice!

Similar Threads

  1. Saving data from the Fragment shader
    By williamsma in forum Developers Coding:Advanced
    Replies: 2
    Last Post: 05-09-2012, 10:29 AM
  2. Replies: 3
    Last Post: 11-16-2011, 06:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •