Skip to content

The Rest: Listing 12, superfluous addition and subtraction rec.p #604

@D-K-E

Description

@D-K-E

Listing 12 of the book The Rest of Your Life contains a superfluous addition and subtraction operation for hit record point in the lambertian scattering method. It is given as:

        virtual bool scatter(...) const {
            point3 target = rec.p + rec.normal + random_unit_vector();
            scattered = ray(rec.p, unit_vector(target-rec.p), r_in.time());
            ...
        }

I think what is being intended is

point3 target = rec.normal + random_unit_vector();
scattered = ray(rec.p, unit_vector(target), r_in.time());

which avoids adding and subtracting the rec.p.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions