File tree Expand file tree Collapse file tree 4 files changed +21
-5
lines changed
Expand file tree Collapse file tree 4 files changed +21
-5
lines changed Original file line number Diff line number Diff line change 25982598viewer can more accurately display our image. As a simple approximation, we can use “gamma 2” as our
25992599transform, which is the power that you use when going from gamma space to linear space. We need to
26002600go from linear space to gamma space, which means taking the inverse of "gamma 2", which means an
2601- exponent of $1/\mathit{gamma}$, which is just the square-root.
2601+ exponent of $1/\mathit{gamma}$, which is just the square-root. We'll also want to ensure that we
2602+ robustly handle negative inputs.
26022603
26032604 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
26042605 inline double linear_to_gamma(double linear_component)
26052606 {
2606- return sqrt(linear_component);
2607+ if (linear_component > 0)
2608+ return sqrt(linear_component);
2609+
2610+ return 0;
26072611 }
26082612 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
26092613
31733177
31743178</ div>
31753179
3180+ (Note here that we use the C++ standard function `fmin()`, which returns the minimum of the two
3181+ arguments. Similarly, we will later use `fmax()`, which returns the maximum of the two arguments.)
3182+
31763183< div class='together'>
31773184And the dielectric material that always refracts is:
31783185
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ using color = vec3;
1919
2020inline double linear_to_gamma (double linear_component)
2121{
22- return sqrt (linear_component);
22+ if (linear_component > 0 )
23+ return sqrt (linear_component);
24+
25+ return 0 ;
2326}
2427
2528void write_color (std::ostream &out, color pixel_color, int samples_per_pixel) {
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ using color = vec3;
1919
2020inline double linear_to_gamma (double linear_component)
2121{
22- return sqrt (linear_component);
22+ if (linear_component > 0 )
23+ return sqrt (linear_component);
24+
25+ return 0 ;
2326}
2427
2528void write_color (std::ostream &out, color pixel_color, int samples_per_pixel) {
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ using color = vec3;
1919
2020inline double linear_to_gamma (double linear_component)
2121{
22- return sqrt (linear_component);
22+ if (linear_component > 0 )
23+ return sqrt (linear_component);
24+
25+ return 0 ;
2326}
2427
2528void write_color (std::ostream &out, color pixel_color, int samples_per_pixel) {
You can’t perform that action at this time.
0 commit comments