Lights scene went too dark in my program. #1653
-
Hello. I'm working on emissive materials in book 2, chapter 7. I got some similar results as the book's from the simple light scene and the Cornell box scene, but the result is very dark. My simple light scene:My Cornell box:
Both results were rendered at 100 samples and max ray depth of 50. Because I wrote the code in GLSL, I tried to use iteration rather than recursion to trace rays. I don't know if my implementation was right, but I do get correct results from the previous scenes that didn't include emissive materials. vec3 get_color(Ray ray) {
vec3 final_color = vec3(0.0);
vec3 accumulated_attenuation = vec3(1.0); // Start with no attenuation
HitRecord hit_record;
// Loop until we either reach the maximum recursion depth or stop scattering.
for (int i = 0; i < max_depth; i++) {
if (!trace_through_bvh(ray, Interval(0.001, INFINITY), hit_record)) {
final_color = accumulated_attenuation * background;
break;
}
if(!scatter(ray.dir, hit_record.normal, hit_record.is_front_face, material)) {
final_color = accumulated_attenuation * color_from_emission;
break;
}
// Update ray origin.
ray.o = hit_record.p;
accumulated_attenuation *= albedo;
}
return linear_to_gamma(final_color);
} In the code, I'm confused because rays actually had a low chance to reach the light source, which would in turn produce a dark scene just like mine. So I suppose that my understanding may somehow be wrong. My repository is available here. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You might find it helpful to compare your debug flow against that of our "progression" branches, where we commit increments along with the code progression in the books. If you look at branch "progression/2024-0405" (our latest progression), you'll find commit 68f312d, which is our reference code immediately after book 2 listing 60. Other readers have found this to be a very helpful debug tool. |
Beta Was this translation helpful? Give feedback.
-
I found the problem! It’s related to gamma correction. I think there’s a bug in my gamma correction GLSL code. To resolve it, I used the OpenGL built-in method to enable gamma correction, which applies a gamma value of 2.2. |
Beta Was this translation helpful? Give feedback.
I found the problem! It’s related to gamma correction. I think there’s a bug in my gamma correction GLSL code. To resolve it, I used the OpenGL built-in method to enable gamma correction, which applies a gamma value of 2.2.