4 ms·
The aliasing in this was driving me insane, fortunately it's really easy to implement anti aliasing. Change the function signature of the current main function
by gpm 9y ago
The aliasing in this was driving me insane, fortunately it's really easy to implement anti aliasing.
Change the function signature of the current main function to
vec3 getColor(in vec2 fragCoord ) {
And the last line to
return col
Then just call it a bunch of times with nearby points in a new main function
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec3 c1 = getColor(fragCoord + vec2( 0.25, 0.25));
vec3 c2 = getColor(fragCoord + vec2( 0.25, -0.25));
vec3 c3 = getColor(fragCoord + vec2(-0.25, 0.25));
vec3 c4 = getColor(fragCoord + vec2(-0.25, -0.25));
fragColor = vec4((c1 + c2 + c3 + c4) / 4., 1.0);
}
Obviously this does 4x the amount of work as without antialiasing, but with modern hardware you don't notice it and it looks way better.
- pjc50 9y agoThe aliasing is highly authentic for the original 320x200 render mode :)
- gpm 9y agoTrue
- organsnyder 9y agoIt would have been softened by the CRTs of the time, though (or, at least, the CRTs I had...).
- msla 9y agoCRTs in general are complex pieces of machinery which do odd, hard-to-emulate things to graphics. Here's an interesting post on the topic: http://ascii.textfiles.com/archives/3786 http://ascii.textfiles.com/archives/3786 And one with more detail: http://bogost.com/games/a_television_simulator/ http://bogost.com/games/a_television_simulator/
- dahart 9y ago> CRTs in general are complex pieces of machinery which do odd, hard-to-emulate things to graphics. True, but that doesn't stop the smart guys on Shadertoy from trying... ;) https://www.shadertoy.com/view/4dlyWX https://www.shadertoy.com/view/4dlyWX https://www.shadertoy.com/view/ldSfWV https://www.shadertoy.com/view/ldSfWV
- Pxtl 9y agoMaybe yours, but I remember big bulky pixels at anything below 800x600 back then.
- astrodust 9y agoVGA seemed downright HD compared to CGA.
- entropicdrifter 9y agoFigured out how to do Multi-Frame style Anti-Aliasing for a much lower performance hit, looks nearly as good in motion: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float h1 = (hash(time + fragCoord.x) + hash(time + fragCoord.y)) / 4.0; float h2 = (hash(time - fragCoord.x) + hash(time -fragCoord.y)) / 4.0; vec3 c1 = getColor(fragCoord + vec2(h1, h2)); fragColor = vec4(c1, 1.0); } Or if you want it to look pretty much exactly as good as 4x MSAA (which is what you're doing) for a little more than half the cost: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { float h1 = (hash(time + fragCoord.x) + hash(time + fragCoord.y)) / 4.0; float h2 = (hash(time - fragCoord.x) + hash(time -fragCoord.y)) / 4.0; vec3 c1 = getColor(fragCoord + vec2(h1, h2)); vec3 c2 = getColor(fragCoord + vec2(-h1, -h2)); fragColor = vec4((c1 + c2)/2., 1.0); } EDIT: Changed per suggestions from reply Edit2: Found another way to cut down on cost with even less sacrifice of quality (no under-water feeling while holding still), you can do a 2x version of the original 4x method, but flip-flop the x coordinates every frame, like so: void mainImage( out vec4 fragColor, in vec2 fragCoord ) { bool even = mod(float(iFrame), 2.) == 0.; float x; float y = 0.25; if(even) { x = -0.25; } else { x = 0.25; } vec3 c1 = getColor(fragCoord + vec2(x, y)); vec3 c2 = getColor(fragCoord + vec2(-x, -y)); fragColor = vec4((c1 + c2)/2., 1.0); }
- mkhalil 9y agoshould the last line of the second function be fragColor = vec4(c1, c2)? I just see an unused c2.
- entropicdrifter 9y agoThanks! Fixed it.
- gpm 9y agoThis (edit: the first one) works way better than I expected! Your h1 and h2 are always the same since hash is deterministic when I assume you want them to be distinct, and they're in the range [-1, 1] instead of [0.5, -0.5] which I think makes more sense. I'm also not sure why you made r instead of just hashing fragCoord directly? I also think adding time to the hash makes it look better, though if you stand still it's somewhat nauseating (switch all time variables in getColor to 0.0). Anyways I ended up with the following which I think looks great :) float h1 = (hash(time + fragCoord.x) + hash(time + fragCoord.y)) / 4.0; float h2 = (hash(time - fragCoord.x) + hash(time -fragCoord.y)) / 4.0;