How to write a pixelation vertex/fragment or surface shader?

Hey everybody!

Finally I’ve got some spare time again. I tried to get started with shaders about two months ago and managed to create a simple retro effect shader as an imageeffect shader (http://i.imgur.com/VZ1Hy6k.png). But now I’d like to have this effect as a shader that’s put onto objects and creates a world where some objects are “retro” and some are not.

But I don’t quiet see how I would do the pixelation in this case. I don’t need the shader written out for me, just an idea how one could achieve this effect in a vertex/fragment or surface shader (preferably both but I assume it will be quiet similar).
My problem is that I don’t see how I can get the information about the other final pixels. Simply put I have to make some pixels look like other pixels to get a pixelation effect. To make pixel A look like pixel B, I have to know how pixel B looks. In the case of an imageeffect, the whole “normal” rendering process of the object is already done and I have the final picture (that will be displayed on the screen) as a 2D texture to work on. This meant that I already knew how all the pixels looked like (before pixelating, that is) and also made it very easy to access the other pixels by texture coordinates. But as far as my understanding goes, I don’t have this when using the shader on an object in the scene instead of anafter imageeffect and I’m puzzled what’s the way to go about it.

I found this but that only shows how to pixelate an area of the screen and not an actual object and I don’t think it can somehow be adapted to work the way I need it to.

Any idea how I could approach this problem is greatly appreciated!

Thanks in advance!

Hi,

I only dabbled in pixel shader programming, but here’s my idea:

first you write a normal fragment shader with all features you need, like lighting etc.

now for every varying variable that goes into your formula that decides what to render you do some rounding - here’s some pseudocode:

float roundTo = 0.05;
newSomeFloat = roundTo * int(someFloat/roundTo);
newNormal = vec3(
   roundTo * int(normal.x/roundTo),
   roundTo * int(normal.y/roundTo),
   roundTo * int(normal.z/roundTo)
)

you do this with everything… floats, vec3, colors… you get the idea and then you apply your formula that calculates the color on the rounded values, not on the original values

This will make the values change less often and you will get some kind of low resolution effect, but the borders between changing values will probably not be horizontal and vertical, so you wont get big pixels, but it will be blocky in some sense…

Also, you can use different roundTo values for the different variables for different effects.
I’d love a webplayer with sliders for all the different roundTo values to play with.

Please update this question with your results, this sounds interesting.