Git Product home page Git Product logo

computer-graphics-from-scratch's People

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

computer-graphics-from-scratch's Issues

When culling back faces, we can avoid calculating the center of the triangle.

var centre = Multiply(-1.0/3.0, Add(Add(vertices[triangle.indexes[0]], vertices[triangle.indexes[1]]), vertices[triangle.indexes[2]]));

As we want to optimize performance, using any triangle vertex instead of the center seems more desirable. Moreover, using a triangle vertex is more in line with the description in the book and less confusion.


Incidentally, if we wrote

if (Dot(centre, normal) < 0) {

as if (Dot(centre, normal) <= 0), it would fit the description better.

Specular reflection and Phong shading

In both the chapter on specular reflection (Raytracing, Light) and Phong shading (Rasterization, Shading), you apply the specular intensity to the object color to get the final color.

However, specular intensity is usually applied to the light color (and lights are usually white, which is why specular highlights are usually white) and added to the diffuse color to get the final color, as quite nicely visually illustrated on the wikipedia page for Phong Shading.

I assume that this might have been a simplification done for educational reasons, but it does mean the shading model you describe in the Phong Shading chapter isn't actually using the Phong reflection model.

I would suggest changing things around to do it the more common way (the changes for the raytracer aren't too bad, but I admit haven't worked through the rasterizer yet), but if you feel this would complicate the code or explanation too much, perhaps just don't call the shading model "Phong".

No License Info

There does not appear to be any license information in the repo as a whole or in the text of the book.

Please add a license or public domain release (eg: CC0, Unlicense, etc) when you get the chance. Some sort of public domain option seems simplest, since the book is free anyway.

Considered publishing platform?

The content seems to be super interesting. However it's not in the most reader-friendly format (IMO). Have you considered something like:

I'm not in any way affiliated (nor have been) with either. I know GitBook does have a free tier (0 private books, 0 collaborators).

Comparing distance and radius

var distance2 = Dot(clipping_planes[p].normal, center) + clipping_planes[p].distance;

You computate unnormalized distance and compare it with square radius. For example, let's take surface Z - 1 = 0 and circle (0, 0, 1 + sqrt(3)) with raadius sqrt(3). Distance from the surface to the circle's center is sqrt(3) and program should detect that there is an intersection, but you compare it not whith radius(sqrt(3)) but with square radius(3).
image

Incorrect calculation of directional lighting in `ComputeLighting`

Hello, I noticed the wrong behavior in directional lighting.

My scene in pseudocode:

light {
    type = directional
    intensity = 1
    direction = (0, 0, 1)
}

sphere {
    center = (0, -1, 3)
    radius = 1
    color = (255, 0, 0) 
}
sphere {
    center = (2, 0, 4)
    radius = 1
    color = (0, 0, 255) 
}
sphere {
    center = (-2, 0, 4)
    radius = 1
    color = (0, 255, 0) 
}

I get a scene like this:
image

vector OC.

Hi,

Firstable, thank you for this very precise tutorial.

I may be wrong because this is the first time I m doing this kind of maths, but would not be more accurate to say that vector CO = O−C instead of vector OC = O−C ? (Cf. chapter "Basic ray tracing", title "Rays meet sphere") ?

A minor math mistake

In the Basic ray tracing chapter.

In general, using a 60 FOV in the horizontal and vertical directions produces reasonable images; this is achieved with Vw = Vh = d = 1.

here if the FOV is 60, d should not equal 1. draw the triangle.

Screen Shot 2019-03-13 at 3 50 48 PM

A great book, thanks for sharing.

viewport_size and projection_plane_z cannot be both 1 if we need a 90 degree FOV

var viewport_size = 1;
var projection_plane_z = 1;

it contradicts with

var s2 = 1.0 / Math.sqrt(2);
camera.clipping_planes = [
  Plane(Vertex(0, 0, 1), -1), // Near
  Plane(Vertex(s2, 0, s2), 0), // Left
  Plane(Vertex(-s2, 0, s2), 0), // Right
  Plane(Vertex(0, -s2, s2), 0), // Top
  Plane(Vertex(0, s2, s2), 0), // Bottom
];

Wrong plane normals on clipping demo?

The text points 1/sqrt(2) as a constant that repeats on most clipping plane normals:

In summary, our clipping volume is defined by the following five planes:
$$(near) \langle (0, 0, 1), P \rangle - d = 0$$ $$(left) \langle ({1 \over \sqrt{2}}, 0, {1 \over \sqrt{2}}), P \rangle = 0$$ $$(right) \langle ({-1 \over \sqrt{2}}, 0, {1 \over \sqrt{2}}), P \rangle = 0$$ $$(bottom) \langle (0, {1 \over \sqrt{2}}, {1 \over \sqrt{2}}), P \rangle = 0$$ $$(top) \langle (0, {-1 \over \sqrt{2}}, {1 \over \sqrt{2}}), P \rangle = 0$$

However the code uses sqrt(2) instead:

var s2 = Math.sqrt(2);
camera.clipping_planes = [
Plane(Vertex(0, 0, 1), -1), // Near
Plane(Vertex(s2, 0, s2), 0), // Left
Plane(Vertex(-s2, 0, s2), 0), // Right
Plane(Vertex(0, -s2, s2), 0), // Top
Plane(Vertex(0, s2, s2), 0), // Bottom
];

Is that correct?

Figures not loading in .md chapters

I am using the Google Chrome browser to read the chapters. I have no installed extensions that would affect the loading of the figures. This is what I see right now:
image

Are the chapters still a work in progress? If so, please ignore this issue. I can close it.

The text doesn't appear to be available

I was considering proof reading some of the text and making a pull request, but the text doesn't appear to be in the repository... Unless I'm going blind haha.

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.