Giter Site home page Giter Site logo

cuda-rasterizer's Introduction

CUDA Rasterizer

CLICK ME FOR INSTRUCTION OF THIS PROJECT

  • Yi Guo
  • Tested on: Windows 8.1, Intel(R) Core(TM)i5-4200M CPU @ 2.50GHz 8GB, NVIDIA GeForce 840M (Personal Notebook)

Description

This is a rasterizer on GPU. The basic pipeline of vertex shader, primitive assembly, rasterization, fragment shader and frame buffer are implemented. Here are the images and performance analysis of the project.

ScreenShot

Blinning rasterization result

I slight adjust the blinning parameter to make the material some how metallic.

duck.gltf (Blinn-Phong) cow.gltf (Blinn-Phong) CeisumMilkTruck.gltf (Blinn-Phong)

Here are the normal debug mode

duckNormal.gltf cowNormal.gltf CeisumMilkTruckNormal.gltf

Performance Analysis

I use the cuda timer to record the time of each process of the rasterization. Here are the graphs.

From the graph above, we can notice that the rasterization system spends most time on rasterization and fragment shading. The time cost of vertex shading and primitive assembly is related to the number of triangles of the primitive. However, it is not fair to compare the time cost of rasterization and fragment shading of different models based on the number of triangles they have. Since for the rasterization process, each thread renders a single triangle, so the changes on the number of triangles may not cause great difference on the time cost. What really makes a difference here is the time that each thread spends on rendering a single triangle. The graph below can be a good argument.

The graph above shows the time cost of a singel model(here I use the CeisumMilkTruckNormal.gltf) with different z values. The z values here mean the distance between the model and camera. As it shows, the time cost of rasterization and fragment shading will increase dramaticlly when the model get closer and closer to the camera. The reason is when the distance between camera and model decreases, each triangle in the primitive will take up more grids on the screen than before and in each thread we have to scan a larger range to render a triangle.

There are some better solutions for rasterizing a triangle. For each triangle, instead of scanning all the pixels in the bounding box, we can computer the intersection points of each row and triangle's sides and only render the pixel between 2 intersection points. I may implement this algorithm in the future to optimize the rasterization process.

Extra features

Backface Culling

I implment the Backface Culling for the rasterization system. Here is the comparison for the efficiency.

As the graph shows, backface culling may slightly increase the overall efficiency. BackFace culling fliters out the triangles we cannot see, but as we discussed above, the number of triangles is not the main factor of the time cost, thus it cannot cause great difference on the oveall time cost.

SSAA(Super Sample Anti-Aliasing)

Supersampling is used to remove aliasing (jagged and pixelated edges). It is achived by rendering the image at a higher resolution than the one being displayed, then shrinking it to the desired size, using the extra pixels for calculation. The color of a pixel in the desired size image equals to the average color values of the corresponding pixels in the higher resolution image. Since we render a image with higher resolution, the rasterize process will be slower.

SSAA=1.gltf SSAA=2.gltf SSAA=4.gltf

Perspective Correction

checkboard NoPerspective checkboard Perspective

Bilinear Interpolation

No Bilinear Interpolation Bilinear Interpolation

Different Render Mode(triangle, line ,point)

For the line rendering, I use the Bresenham algorithm

duck.gltf (Blinn-Phong) cow.gltf (Blinn-Phong) CeisumMilkTruck.gltf (Blinn-Phong)

Credits

cuda-rasterizer's People

Contributors

shrekshao avatar kainino0x avatar likangning93 avatar pjcozzi avatar ottaviohartman avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.