Skip to content

Instantly share code, notes, and snippets.

@ainsleyrutterford
Created April 27, 2019 19:06
Show Gist options
  • Select an option

  • Save ainsleyrutterford/9e9cee2c978439029efbdda09b012b81 to your computer and use it in GitHub Desktop.

Select an option

Save ainsleyrutterford/9e9cee2c978439029efbdda09b012b81 to your computer and use it in GitHub Desktop.

Revisions

  1. Ainsley Rutterford created this gist Apr 27, 2019.
    25 changes: 25 additions & 0 deletions anti-aliasing.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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;
    }
    }