Code Monkey home page Code Monkey logo

simplesoftwarerenderer's Introduction

img

How To Use:

  1. Run the Program (Model files are big, so please wait...).
  2. Click "Beethoven" or "Cube Icosahedron" or "Bunny" to switch models.
  3. Click "Toon Shading" "Half-Tone Shading" "Gourand Shading" or "Phong Shading" to switch shading.
  4. Enjoy!

You can see the results in ./imgs folder
You can find a runnable version in ./Debug

How it works:

For each frame: I used three 2d arrays to stroe the result of rendering, like this:
int frameBufferR[width][height] = { 0 };
int frameBufferG[width][height] = { 0 };
int frameBufferB[width][height] = { 0 };
Then render these frameBuffers only when a mouse click event is called.

For basic structures:

I created: struct Vertex // store and calculate vertex
struct Face // store face index
struct Color // store color in (0-255) format
struct Colorf // stroe color in (0-1) format
struct Geometry // stroe vertices, faces, colors, specular
class Model // load and stroe all geometries that a model file contains
class Zone // store a scene with 3 perspectives
struct IShader // basic structure of a shader
struct Button // stroe location, color, and string of a button
enum BtnState // states of a button

For triangle rasterizing:

I used Barycentric Coordinate method, and implement it in these functions:
Vertex barycentric(Vertex A, Vertex B, Vertex C, Vertex P);
void draw_triangle_barycentric(Vertex* pts, IShader& shader);

For shaders:

I created 4 shaders:
GourandShader, ToonShader, PhongShader, and HalfToneShader
For Phong Shading, I added a bluish environment color, so models looks a little bit "Bluer"
And some basic shader functions for convinent:
step(float threshould, float val)
frac(float v)
saturate(float x)
smoothstep(float a, float b, float x)
circle(Vertex _st, float _radius)

simplesoftwarerenderer's People

Contributors

elementmo avatar

Watchers

 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.