Skip to content

Commit

Permalink
polishing + more readable barycentric coordinates computation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssloy committed Aug 25, 2020
1 parent 0f21c22 commit 1db67e7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tiny Renderer or how OpenGL works: software rendering in 500 lines of code

<font size="6">**Check [the wiki](https://github.com/ssloy/tinyrenderer/wiki) for the detailed lessons.**</font>
# Check [the wiki](https://github.com/ssloy/tinyrenderer/wiki) for the detailed lessons.

## compilation
```sh
Expand All @@ -20,11 +20,11 @@ You can open the project in Gitpod, a free online dev evironment for GitHub:
On open, the editor will compile & run the program as well as open the resulting image in the editor's preview.
Just change the code in the editor and rerun the script (use the terminal's history) to see updated images.

## Principles
## The main idea

**My source code is irrelevant. Read the wiki and implement your own renderer. Only when you suffer through all the tiny details you will learn what is going on.**

In this series of articles, I want to show the way OpenGL works by writing its clone (a much simplified one). Surprisingly enough, I often meet people who cannot overcome the initial hurdle of learning OpenGL / DirectX. Thus, I have prepared a short series of lectures, after which my students show quite good renderers.
In [this series of articles](https://github.com/ssloy/tinyrenderer/wiki), I want to show the way OpenGL works by writing its clone (a much simplified one). Surprisingly enough, I often meet people who cannot overcome the initial hurdle of learning OpenGL / DirectX. Thus, I have prepared a short series of lectures, after which my students show quite good renderers.

So, the task is formulated as follows: using no third-party libraries (especially graphic ones), get something like this picture:

Expand Down
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ struct Shader : IShader {

double diff = std::max(0., n*l); // diffuse light intensity
vec3 r = (n*(n*l)*2 - l).normalize(); // reflected light direction
double spec = std::pow(std::max(r.z, 0.), 5+model.specular(uv)); // specular intensity
double spec = std::pow(std::max(r.z, 0.), 5+model.specular(uv)); // specular intensity, note that the camera lies on the z-axis (in ndc), therefore simple r.z

TGAColor c = model.diffuse(uv);
for (int i=0; i<3; i++)
Expand Down
11 changes: 2 additions & 9 deletions our_gl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ mat<4,4> Viewport;
mat<4,4> Projection;

void viewport(const int x, const int y, const int w, const int h) {
Viewport = mat<4,4>::identity();
Viewport[0][3] = x+w/2.;
Viewport[1][3] = y+h/2.;
Viewport[2][3] = 1.;
Viewport[0][0] = w/2.;
Viewport[1][1] = h/2.;
Viewport[2][2] = 0;
Viewport = {{{w/2., 0, 0, x+w/2.}, {0, h/2., 0, y+h/2.}, {0,0,1,0}, {0,0,0,1}}};
}

void projection(const double coeff) {
Projection = mat<4,4>::identity();
Projection[3][2] = coeff;
Projection = {{{1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,coeff,1}}};
}

void lookat(const vec3 eye, const vec3 center, const vec3 up) {
Expand Down

0 comments on commit 1db67e7

Please sign in to comment.