I've been experimenting with pixel shaders again...
This time, I wanted to make a shader that could create a dithering effect. Unfortunately, I can't figure out any way to handle a full color palette, so I'm limited to greyscale.
Still, if you ever dreamed of making a grainy, atmospheric film-noire style game, but with gameboy style graphics, maybe this could help?
Note: Click on images to see them full size.
Original image:
With ordered dithering:
A Gameboy game with lighting effects? (graphics not by me)
Yeah, it worked out okay, but it's a bit "messy" looking, I think.
It seems to make quite a big difference which patterns you use - in some cases, the pattern becomes far more noticeable, but it also makes the image look "cleaner" somehow.
For example:
I kind of like how it looks a little messy and disorganized.
This one is interesting, too. I think that out of all of them, this one looks the cleanest, but it also texturizes everything. Considering the shader will probably be most useful in a 8-bit grayscale game, the pixel-y look is an advantage. As always, awesome work Sketchy!
Edited by The_Antisony
ChrisD> Employer: Say, wanna see a magic trick?
ChrisD> Employee: Uhh… sure, boss.
ChrisD> Employer: Your job! It just disappeared! Pack your things and leave! Pretty good trick, huh?
I've made another shader...
This time, it simulates alpha channel transparency using uniform dithering - potentially useful if you want quick and easy fading/transparency effects in a retro styled game, where the real thing would look too modern and out of place.
Opacity can vary in increments of 1/8th, and can use the object's own alpha channel (eg. if the object is to fade gradually at the edges), or a single adjustable value (eg. if the whole object is to fade over time), or a combination of the two.
Thanks
Yes, it works in basically the same way, except that the old dithering shader got the pattern by sampling from an image, while this version just stores the pattern as an array inside the shader itself, which is simpler and ought to be much more efficient. And of course, the pattern is selected based on the source alpha rather than its lightness.
Each "int4x4" (or "float4x4" in previous versions) is an array representing a 4x4 pattern of pixels, where 0 = transparent, and 1 = opaque.
The 50% pattern is handled a little differently, just because the limitations of pixel shaders in MMF2 made it impossible to have that many arrays, and a 50% pattern is the easiest to calculate using just maths.
I have a feeling there is still room to simplify it quite a bit...
Ah, that makes sense.
I guess if you wanted to simplify things, you could use a single array that kind of combines the different patterns at different levels. As long as any one pixel only goes from 0 to 1 as opacity changes (and not like, 0 -> 1 -> 0 -> 1), then you can put together something that encompasses all the different opacity levels, and just pick whatever value you're at as a threshold.