Skip to content

Instantly share code, notes, and snippets.

@ainsleyrutterford
Created April 27, 2019 19:06
Show Gist options
  • Save ainsleyrutterford/9e9cee2c978439029efbdda09b012b81 to your computer and use it in GitHub Desktop.
Save ainsleyrutterford/9e9cee2c978439029efbdda09b012b81 to your computer and use it in GitHub Desktop.
Anti aliasing code for a rasteriser created using C++.
vec3 aliasing_buffer[SCREEN_HEIGHT][SCREEN_WIDTH];
screen *screen = InitializeSDL(SCREEN_WIDTH/3, SCREEN_HEIGHT/3, FULLSCREEN_MODE);
memset(screen->buffer , 0, screen->height * screen->width * sizeof(uint32_t));
memset(depth_buffer , 0, SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(float ));
memset(aliasing_buffer, 0, SCREEN_HEIGHT * SCREEN_WIDTH * sizeof(vec3 ));
void draw_screen(screen* screen) {
for (int y = 0; y < SCREEN_HEIGHT; y+=3) {
for (int x = 0; x < SCREEN_WIDTH; x+=3) {
vec3 average = (aliasing_buffer[y][x ] + aliasing_buffer[y+1][x ] + aliasing_buffer[y+2][x ]
+ aliasing_buffer[y][x+1] + aliasing_buffer[y+1][x+1] + aliasing_buffer[y+2][x+1]
+ aliasing_buffer[y][x+2] + aliasing_buffer[y+1][x+2] + aliasing_buffer[y+2][x+2]) / 9.f;
PutPixelSDL(screen, int(x/3), int(y/3), average);
}
}
}
if (x >= 0 && x < SCREEN_WIDTH && y >= 0 && y < SCREEN_HEIGHT) {
if (p.z_inv > depth_buffer[y][x]) {
depth_buffer[y][x] = p.z_inv;
aliasing_buffer[y][x] = R;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment