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 2598
2598
viewer can more accurately display our image. As a simple approximation, we can use “gamma 2” as our
2599
2599
transform, which is the power that you use when going from gamma space to linear space. We need to
2600
2600
go 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.
2602
2603
2603
2604
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2604
2605
inline double linear_to_gamma(double linear_component)
2605
2606
{
2606
- return sqrt(linear_component);
2607
+ if (linear_component > 0)
2608
+ return sqrt(linear_component);
2609
+
2610
+ return 0;
2607
2611
}
2608
2612
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2609
2613
3173
3177
3174
3178
</ div>
3175
3179
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
+
3176
3183
< div class='together'>
3177
3184
And the dielectric material that always refracts is:
3178
3185
Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ using color = vec3;
19
19
20
20
inline double linear_to_gamma (double linear_component)
21
21
{
22
- return sqrt (linear_component);
22
+ if (linear_component > 0 )
23
+ return sqrt (linear_component);
24
+
25
+ return 0 ;
23
26
}
24
27
25
28
void 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;
19
19
20
20
inline double linear_to_gamma (double linear_component)
21
21
{
22
- return sqrt (linear_component);
22
+ if (linear_component > 0 )
23
+ return sqrt (linear_component);
24
+
25
+ return 0 ;
23
26
}
24
27
25
28
void 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;
19
19
20
20
inline double linear_to_gamma (double linear_component)
21
21
{
22
- return sqrt (linear_component);
22
+ if (linear_component > 0 )
23
+ return sqrt (linear_component);
24
+
25
+ return 0 ;
23
26
}
24
27
25
28
void write_color (std::ostream &out, color pixel_color, int samples_per_pixel) {
You can’t perform that action at this time.
0 commit comments