Giter VIP home page Giter VIP logo

zauonlok / renderer Goto Github PK

View Code? Open in Web Editor NEW
2.4K 2.4K 273.0 131.5 MB

A shader-based software renderer written from scratch in C89

Home Page: https://zauonlok.github.io/renderer/

License: MIT License

Batchfile 0.32% C 68.87% Shell 0.14% Objective-C 2.81% Python 26.04% C++ 0.60% CMake 1.22%
3d 3d-graphics c cross-platform from-scratch graphics graphics-programming ibl pbr rendering shaders software-rendering

renderer's Introduction

Software Renderer

This is a shader-based software renderer written from scratch in C89 with minimal dependencies, available for Windows, macOS, and Linux.

Features

  • Cross platform
  • Minimal dependencies
  • Shader based
  • Homogeneous clipping
  • Back-face culling
  • Perspective correct interpolation
  • Depth testing
  • Alpha testing
  • Alpha blending
  • Cubemapped skybox
  • Skeletal animation
  • Tangent space normal mapping
  • Shadow mapping
  • ACES tone mapping
  • Blinn–Phong reflection model
  • Physically based rendering (PBR)
  • Metallic-roughness workflow
  • Specular-glossiness workflow
  • Image-based lighting (IBL)
  • Orbital camera controls
  • PBR material inspector

Download

Pre-built binaries for Windows, macOS, and Linux are available for download from the Releases page.

Build

To build the software renderer from source, a C89 compiler and development files for your window system are required.

Windows

Install Visual Studio with C++ support and run build_win32.bat.

macOS

Install Command Line Tools for Xcode with the command below and run build_macos.sh.

xcode-select --install

Linux

Install GCC and Xlib with the following commands and run build_linux.sh.

Ubuntu / Debian

sudo apt install gcc libx11-dev

Fedora / RHEL

sudo dnf install gcc libX11-devel

openSUSE / SUSE

sudo zypper install gcc libX11-devel

Bonus

A CMakeLists.txt file is provided for generating project files using CMake (see examples below).

Visual Studio

mkdir build
cd build
cmake -G "Visual Studio 16 2019" ..
start Renderer.sln

Xcode

mkdir build
cd build
cmake -G Xcode ..
open Renderer.xcodeproj

Makefile

mkdir build
cd build
cmake -G "Unix Makefiles" -D CMAKE_BUILD_TYPE=Release ..
make

Usage

Launch

If the software renderer is launched without arguments, one of the available scenes will be chosen randomly. To display a specific scene (see below), additional arguments should be supplied. The command line syntax is:

Viewer [test_name [scene_name]]

Controls

  • Orbit: left mouse button
  • Pan: right mouse button
  • Zoom: mouse wheel
  • Rotate lighting: A D S W
  • Reset everything: Space

Inspector

For PBR scenes, a material inspector that is very similar to the layers view of Marmoset Viewer is provided. Double click to bring it up.

Screenshots

Scene Command
Viewer blinn azura
Viewer blinn centaur
Viewer blinn craftsman
Viewer blinn elfgirl
Viewer blinn kgirl
Viewer blinn lighthouse
Viewer blinn mccree
Viewer blinn nier2b
Viewer blinn phoenix
Viewer blinn vivi
Viewer blinn whip
Viewer blinn witch
Viewer pbr assassin
Viewer pbr buster
Viewer pbr crab
Viewer pbr dieselpunk
Viewer pbr drone
Viewer pbr helmet
Viewer pbr horse
Viewer pbr junkrat
Viewer pbr ornitier
Viewer pbr ponycar
Viewer pbr robot
Viewer pbr sphere
Viewer pbr spheres

References

Rendering pipeline

Physically based rendering

File formats

Miscellaneous

License

MIT License

renderer's People

Contributors

rneatherway avatar zauonlok avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

renderer's Issues

A mistake about orbit camera

function calculate_pan in camera.c:

static vec3_t calculate_pan(vec3_t from_camera, motion_t motion) {
    vec3_t forward = vec3_normalize(from_camera);
    vec3_t left = vec3_cross(UP, forward);
    vec3_t up = vec3_cross(forward, left);

    float distance = vec3_length(from_camera);
    float factor = distance * (float)tan(FOVY / 2) * 2;
    vec3_t delta_x = vec3_mul(left, motion.pan.x * factor);
    vec3_t delta_y = vec3_mul(up, motion.pan.y * factor);
    return vec3_add(delta_x, delta_y);
}

vector left and vector up are not normalize.
This error causes the camera's motion speed to shrink as the Angle between the forward vector and the UP vector changes.
Specifically, the less close the angle between the forward vector and the UP vector is to 90 degrees, the slower the camera moves and will not move at all in extreme cases (when forward is on the same line as UP).
The correct code should look like this:

static vec3_t calculate_pan(vec3_t from_camera, motion_t motion) {
    vec3_t forward = vec3_normalize(from_camera);
    vec3_t left = vec3_cross(UP, forward);
    left = vec3_normalize(left);
    vec3_t up = vec3_cross(forward, left);
    up = vec3_normalize(up);

    float distance = vec3_length(from_camera);
    float factor = distance * (float)tan(FOVY / 2) * 2;
    vec3_t delta_x = vec3_mul(left, motion.pan.x * factor);
    vec3_t delta_y = vec3_mul(up, motion.pan.y * factor);
    return vec3_add(delta_x, delta_y);
}

Questions about your modle format

Dear author, I have been studying your project recently.How are the .scn files in your model files generated?Can I export from .3DS or other 3D files?

The code is great!

I love how minimal and clean this code is. Do you have any other open source projects? I'd love to take a look.

Please add a basic triangle example

I'm trying to learn OpenGL but I'm finding the guides to be lacking in the key points so I'm now trying to learn from existing code, I'd like you to add a basic triangle example so I can follow the code back to it's roots and see how new vertices are passed after movement of the triangle via the AWSD keys. It would helpful if the triangle had 3 modes, the first being a flat colour, the 2nd being changeable colours from the arrow keys with/without the shift or control key pressed along side (the 2 modifiers deciding which point to effect) and the 3rd mode having a texture applied instead of modifiable colours, if you can add modes for lighting as well that would be appreciated. You don't need to add a lot of comments, just 1 for each mode branch so that I know where to start analysing from.

Edit: Pure C would be easier for me to read than C++ so that would also be appreciated

Edit 2: I should mention that what I'm having most difficulty with is indexed buffers, I've been able to manipulate positions with uniforms and I've also been able to change vertices by just destroying previous buffers in favour of a new buffer.

Edit 3: Actually could you add a 2nd triangle that moves independently of the 1st, the numpad should be fine for moving it about, the goal isn't an actual game after all, just an example of utilising vertex arrays with vertex & index buffers on multiple objects

Performance ideas.

Hey, this renderer is really a great job, I like the 3D and its algorithms (it's all illusions), and I personally made a simple one using pure javascript running on the browser:
https://github.com/medram/3Din2DCanvas

any way, about your renderer, I've noticed that when I zoom closer to the 3D object the renderer get suffering and the frame rate tremendously get low, and I guess it caused by the clipping, and to fix this issue I suggest the following:

  • The clipping is costly, so don't do the clipping at all (except Near and Far plains).
  • Don't render/calculate the 3D object if it was out of the scene.
  • Try improving the clipping algorithm.
  • or don't clip the triangles that should be clipped, and just render the triangles that are in the scene and those that needs the clipping (but don't clip it), and don't render/calculate the triangles that are outside of the scene.

I hope that make sense (my English is a little bit broken).

and all of the mentioned ideas/algorithms has been implemented in my Javascript renderer and it helps a lot in the performance.

One last thing please, I'm a python expert, but I didn't know how and where did you connect C code with Python code? and did you use Python "ctype"?

Thanks.

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.