pixelate in openGL


    Jan 12 2008 | 5:37 am
    I am wondering if there is a way to create a "pixelated" effect in openGL with textures.
    I have been using vades v001.pixelate.jxs shader (what a great collection) on my tower (mac quadCore dual Intel), however on my laptop (Mac 1.67GHz PowerPC G4 / Radeon 9700 video card) the shader does not work. Most of vades shaders work on my laptop, although some of them do not (all of them work on my desktop).
    I would like to process the effect in openGL, what is the best way to do this?
    Below is a patch if you care to see an example.

    • Jan 12 2008 | 1:24 pm
      On my computer matrix size is very low, but the picture is not exactly pixelated(c64 style) since the pixels are interpolated through jit.gl.videoplane.
      But anyway, jit.gl.slab has nice'n'handy 'dimscale x-scale y-scale' attribute that you can use to scale it's dimensions - so to get the low resolution look you can set it to the values lower than 1. (0.5 - half of the input dimensions/resolution). The 'look' will not yet be 'blocky' since textures are still interpolated, so you can turn off the interpolation by setting output texture's 'filter' attribute to 'none' - just send 'sendoutput filter none' message to jit.gl.slab.
      Your patch modified is pasted below.
      best, nesa
    • Jan 12 2008 | 2:48 pm
      hi nesa, missed you on the list.
      On Jan 12, 2008 3:24 PM, nesa wrote:
      > On my computer matrix size is very low, but the picture is not > exactly pixelated(c64 style) since the pixels are interpolated > through jit.gl.videoplane. > > But anyway, jit.gl.slab has nice'n'handy 'dimscale x-scale y-scale' > attribute that you can use to scale it's dimensions - so to get the > low resolution look you can set it to the values lower than 1. (0.5 - > half of the input dimensions/resolution). > The 'look' will not yet be 'blocky' since textures are still > interpolated, so you can turn off the interpolation by setting output > texture's 'filter' attribute to 'none' - just send 'sendoutput filter > none' message to jit.gl.slab. > > Your patch modified is pasted below. > > best, > nesa > > #P window setfont "Sans Serif" 9.; > #P window linecount 1; > #P hidden newex 342 137 48 196617 loadbang; > #P hidden message 342 161 23 196617 0.1; > #P message 243 213 108 196617 sendoutput filter none; > #P flonum 315 238 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P window linecount 2; > #P message 446 102 107 196617 ; jitter glreadback fbo; > #P window linecount 1; > #P newex 197 330 60 196617 loadmess 1; > #P message 315 262 79 196617 dimscale $1 $1; > #P window setfont "Fixedwidth Serif" 10.; > #P message 211 154 98 1441802 read dishes.mov; > #P window setfont "Sans Serif" 9.; > #P newex 14 481 48 196617 loadbang; > #P message 32 527 55 196617 floating $1; > #P toggle 31 508 15 0; > #P newex 33 547 70 196617 jit.window fa; > #P flonum 272 358 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P flonum 235 358 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #P flonum 198 358 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0; > #N vpatcher 30 89 630 489; > #P outlet 51 218 15 0; > #P inlet 225 89 15 0; > #P inlet 158 89 15 0; > #P inlet 74 89 15 0; > #P inlet 43 89 15 0; > #P window setfont "Sans Serif" 9.; > #P message 74 126 72 196617 brightness $1; > #P newex 77 160 76 196617 prepend param; > #P message 158 126 63 196617 contrast $1; > #P message 225 126 71 196617 saturation $1; > #P newex 51 185 209 196617 jit.gl.slab fa @type char @file > cc.brcosa.jxs; > #P connect 5 0 0 0; > #P fasten 3 0 0 0 82 176 56 176; > #P connect 0 0 9 0; > #P connect 6 0 4 0; > #P fasten 4 0 3 0 79 150 82 150; > #P fasten 1 0 3 0 230 147 82 147; > #P fasten 2 0 3 0 163 147 82 147; > #P connect 7 0 2 0; > #P connect 8 0 1 0; > #P pop; > #P newobj 130 374 59 196617 p brcosaGL; > #P user jit.fpsgui 82 467 60 196617 0; > #P newex 82 419 254 196617 jit.gl.videoplane fa @transform_reset 2 > @automatic 0; > #P newex 46 107 30 196617 t b b; > #P toggle 75 21 15 0; > #P newex 75 43 51 196617 qmetro 2; > #P newex 75 64 58 196617 t b b erase; > #P newex 82 443 77 196617 jit.gl.render fa; > #P message 168 158 29 196617 stop; > #P message 131 158 33 196617 start; > #P newex 130 181 63 196617 jit.qt.movie; > #P comment 355 238 113 196617 < set dimension scaling; > #P comment 354 213 129 196617 < turn off interpolation; > #P user panel 208 181 290 112; > #X brgb 229 255 207; > #X frgb 166 0 0; > #X border 1; > #X rounded 0; > #X shadow 0; > #X done; > #P hidden connect 28 0 26 0; > #P hidden connect 28 0 27 0; > #P connect 23 0 14 0; > #P connect 23 0 15 0; > #P connect 23 0 16 0; > #P hidden connect 27 0 25 0; > #P fasten 26 0 13 0 248 301 135 301; > #P connect 25 0 22 0; > #P fasten 22 0 13 0 320 314 135 314; > #P connect 3 0 13 0; > #P connect 20 0 18 0; > #P connect 18 0 19 0; > #P connect 19 0 17 0; > #P fasten 7 1 10 0 104 94 51 94; > #P connect 9 0 8 0; > #P connect 8 0 7 0; > #P connect 13 0 11 0; > #P fasten 10 0 11 0 51 445 87 445; > #P fasten 7 0 6 0 80 142 87 142; > #P fasten 7 2 6 0 128 142 87 142; > #P connect 6 0 12 0; > #P connect 4 0 3 0; > #P fasten 5 0 3 0 173 177 135 177; > #P connect 10 1 3 0; > #P connect 21 0 3 0; > #P connect 14 0 13 1; > #P connect 15 0 13 2; > #P connect 16 0 13 3; > #P window clipboard copycount 29; > >
    • Jan 12 2008 | 10:49 pm
      The difficulty with the dimscale method is that if you're mixing two textures further down the slab chain and the pixelated one is in the left inlet of the mixing slab, the texture coming in the right inlet will be pixelated, too, because the texture in the left inlet sets the attributes for the other inlets. I have tried various combinations of slabs, textures, attributes, and sendinput and sendoutput messages, e.g., "sendinput 1 filter none" and "sendinput 1 autoscale 1" to correct this, but it hasn't worked. The only solution that I can see is to make sure the pixelated texture is always in the right inlet of other slabs, which is a PITA. Has anyone else gotten this to work?
    • Jan 12 2008 | 10:57 pm
      One way to pixelate and keep texture dimensions up is to apply a step function to your texture sampling and turn off interpolation.
      wes
      On Jan 12, 2008 2:49 PM, Dan Winckler wrote: > The difficulty with the dimscale method is that if you're mixing two > textures further down the slab chain and the pixelated one is in the > left inlet of the mixing slab, the texture coming in the right inlet > will be pixelated, too, because the texture in the left inlet sets > the attributes for the other inlets. I have tried various > combinations of slabs, textures, attributes, and sendinput and > sendoutput messages, e.g., "sendinput 1 filter none" and "sendinput 1 > autoscale 1" to correct this, but it hasn't worked. The only > solution that I can see is to make sure the pixelated texture is > always in the right inlet of other slabs, which is a PITA. Has > anyone else gotten this to work? > >
    • Jan 12 2008 | 11:12 pm
      Thanks. This answered my question perfectly!
    • Jan 13 2008 | 2:18 pm
      > The only solution that I can see is to make sure the pixelated > texture is always in the right inlet of other slabs, which is a > PITA. Has anyone else gotten this to work?
      Well, you can re-scale it back afterwards, if you have a really good reason to do it 'out' of the shader:
      jit.slab @dimscale 0.1 0.1 | jit.slab @dimscale 10. 10.
      or really out of the shader:
      dullness | jit.gl.texture fa @adapt 0 @dim 32 24 @filter none | jit.gl.texture fa @adapt 0 @dim 320 240 | happines
      -nesa ps. I missed you guys as well, and once again THANKS!
    • Jan 14 2008 | 5:00 am
      > jit.slab @dimscale 0.1 0.1 > | > jit.slab @dimscale 10. 10.
      Scrubbing the dimscale, i.e., changing it quickly, blanks out the texture and/or hangs Max momentarily on my machine. According to vade, jit.gl.slab does a render-to-texture internally, so changing the dimscale is actually destroying and re-creating that internal render context, which is an expensive (and apparently error-prone) operation. Pixelating in a shader is definitely the way to go, even if you have to mod the shader to make it work on your hardware (sounds like Wes's advice to Oliver has already pointed him in that direction).
    • Jan 14 2008 | 5:30 am
      I should note, I was GUESS as to that being the case, since I also so flashes of white with playing with dimscale while rendering.
      you can use a pixelate shader, I have one, you can download it at http://001.vade.info
      On Jan 14, 2008, at 12:00 AM, Dan Winckler wrote:
      >> jit.slab @dimscale 0.1 0.1 >> | >> jit.slab @dimscale 10. 10. > > Scrubbing the dimscale, i.e., changing it quickly, blanks out the > texture and/or hangs Max momentarily on my machine. According to > vade, jit.gl.slab does a render-to-texture internally, so changing > the dimscale is actually destroying and re-creating that internal > render context, which is an expensive (and apparently error-prone) > operation. Pixelating in a shader is definitely the way to go, even > if you have to mod the shader to make it work on your hardware > (sounds like Wes's advice to Oliver has already pointed him in that > direction). >
    • Jan 14 2008 | 6:21 pm
      true, true
      On Jan 14, 2008, at 6:00 AM, Dan Winckler wrote:
      >> jit.slab @dimscale 0.1 0.1 >> | >> jit.slab @dimscale 10. 10. > > Scrubbing the dimscale, i.e., changing it quickly, blanks out the > texture and/or hangs Max momentarily on my machine. According to > vade, jit.gl.slab does a render-to-texture internally, so changing > the dimscale is actually destroying and re-creating that internal > render context, which is an expensive (and apparently error-prone) > operation. Pixelating in a shader is definitely the way to go, > even if you have to mod the shader to make it work on your hardware > (sounds like Wes's advice to Oliver has already pointed him in that > direction).
    • Jan 14 2008 | 6:50 pm
      I haven't looked at Vade's shader, but this one should do the job.
      -ab
      distortion based on position map in second inlet
    • Jan 14 2008 | 6:59 pm
      Looks good, but I don't think you need any of the tex(coord)1 variables. wes
      On Jan 14, 2008 10:50 AM, Andrew Benson wrote: > I haven't looked at Vade's shader, but this one should do the job. > > -ab > > > > distortion based on position map in second inlet > > > > > > > > > > > > > > > >
    • Jan 14 2008 | 7:51 pm
      Ha, Agreed. That's what happens when you start a shader with copy-paste. :)
      Feel free to remove any reference to tex1 or texcoord1 in the code, unless you want to use a second texture input for pixelation amount (or something). Hmmm.
      -ab Wesley Smith wrote: > Looks good, but I don't think you need any of the tex(coord)1 variables. > wes > > On Jan 14, 2008 10:50 AM, Andrew Benson wrote: > >> I haven't looked at Vade's shader, but this one should do the job. >> >> -ab >> >> >> >> distortion based on position map in second inlet >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >
    • Sep 18 2012 | 3:55 pm
      I'm a complete rookie on Max5, and I am experimenting same kind of interpolation of the texture with vade's pixelate shader.
      I have two similar patches, but they seems to respond in different ways. v001 patch interpolates while nesa mod's from original patch no interpolates. I think I have same params on my gl.slab and videoplanes in both cases, and I doesn't undestand this different behaviours.
      Could anyone give me idea about what it's happening?
      I attatch a pic, showing the differences
      (edit: I discovered one difference in gl.slab "modificators", in first patch it changes param scale, second example modifies dimscale.)
    • Nov 08 2012 | 8:13 pm
      Is there any reason why one couldn't just adjust the dims of the jit.qt.movie player to something low (15x15) and turn off interpolation on the jit.gl.videoplane to acheive pixellation?