-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to understand hit function in Chapter 8 Volumes #22
Comments
Man, that whole function needs some love. The formatting is totally mangled, and there are several Existing Code
Properly Formatted Code
In conjunction with addressing Kris's original question, the code needs to be cleaned up. |
The bool The code here means that for every ray in a volume, it creates a random number. If that random number is 1/10000 then it will print that rays data. In this way, 10s of ray data will dumped rather than 100,000s. However it was set to always false with the assumption that reader would comment out one of the two instantiations. This is probably worth keeping, as volumes are crazy hard to debug, but it should be removed from the "beauty code block" and placed into its own code block. |
Hah! I was puzzled by the meaning, then realized that the formatting was totally bogus, then reformatted it, then forgot to ask the original question while reading the reformatted code. Duh. Yes, seems obvious now in retrospect. What do you mean by "beauty code block"? Also, a simple periodic sampling would accomplish the same throttling without incurring the hit of generating a new random number, and would be easier to understand (and of course, fix the name in the process):
|
I was tongue-in-cheekily referring to the fact that final raytracing images are referred to as "Beauty Images". One potential problem with the above code is that it samples exactly every 10,000 samples. You could potentially get into problems of aliasing the data, versus the random sampling above. The sample rate is so outrageously sparse that this shouldn't be a problem is practice. Controlling how often samples are printed is that bit much more intuitive. So, this gets my vote |
Thinking about this a bit more, this would be better:
The fastest code is code that's not there. :D (The |
Since when have we cared about speed?
I'm not a fan of this method. We don't use the preprocessor in this manner
any where else in the codebase
…On Wed, Aug 21, 2019, 15:39 Steve Hollasch ***@***.***> wrote:
Thinking about this a bit more, this would be better:
#if 0 // 0 = debug off, 1 = debug on
bool debug = drand48() < 0.00001;
#else
const bool debug = false;
#endif
...
if (debug) std::cerr << "hit_distance = " << hit_distance << "\n";
...
The fastest code is code that's not there. :D
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/RayTracing/TheNextWeek/issues/44?email_source=notifications&email_token=ACNZVKGTHCOBWO6W6UE2EQTQFW72PA5CNFSM4IOHUW2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD43KZBQ#issuecomment-523676806>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACNZVKDB5KIZE274RRV2ED3QFW72PANCNFSM4IOHUW2A>
.
|
The point was that we certainly could illustrate debugging methods and code alongside the raytracing code more, since debugging support helps the inevitable cases where something "looks off". I care about speed because the development iteration cycle is crucial. If you're objecting because it's non-conventional to the codebase, I can fix that. :D If you're objecting because preprocessor control is ugly and too much of a C++ language quirk, I could debate (indeed, I like Simonyi's original idea of moving languages up to ASTs and metalanguages). Despite all that, I think my rebuttals don't have much weight in this context, and all of my alternatives seem to add more complexity than is warranted. Certainly, the name must be fixed. The code would also be more clear as
|
I was objecting to the break from convention.
We could also hook into the existing compiler defines i.e. _DEBUG
If we decided to do this we could go through and add more debug blocks to
other parts of NextWeek.
Not sure how to feel demanding knowledge of compiler defines to the
audience.
I think your solution of adding a debug variable in the code is not a bad
idea. For the purposes of speed, any compiler will deadcode eliminate for a
const bool.
…On Thu, Aug 22, 2019, 10:30 Steve Hollasch ***@***.***> wrote:
The point was that we certainly could illustrate debugging methods and
code alongside the raytracing code more, since debugging support helps the
inevitable cases where something "looks off". I care about speed because
the development iteration cycle is crucial.
If you're objecting because it's non-conventional to the codebase, I can
fix that. :D
If you're objecting because preprocessor control is ugly and too much of a
C++ language quirk, I could debate (indeed, I like Simonyi's original idea
of moving languages up to ASTs and metalanguages).
Despite all that, I think my rebuttals don't have much weight in this
context, and all of my alternatives seem to add more complexity than is
warranted.
Certainly, the name *must* be fixed. The code would also be more clear as
const enableDebug = true;
bool debug = enableDebug && drand48() < 0.00001; // For debug, print occasional samples
if (debug) ...
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<https://github.com/RayTracing/TheNextWeek/issues/44?email_source=notifications&email_token=ACNZVKFD2EKFEWIN4ZUZ4SDQF3EK7A5CNFSM4IOHUW2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD452B7Q#issuecomment-524001534>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACNZVKEYROXFVN5L3VRW4SDQF3EK7ANCNFSM4IOHUW2A>
.
|
- Improve naming of debug control variable. - Improve debug logic. - Fix whack indentation. - Slight code refactor. Changes to both code & book. Resolves #44
- Improve naming of debug control variable. - Improve debug logic. - Fix whack indentation. - Slight code refactor. Changes to both code & book. Resolves #44
This code snippest from Chapter 8 Volumes:
And if
db = false
, then why would bother to write thoseif (db)
s later, thanks.The text was updated successfully, but these errors were encountered: