diffuse skylight
This commit is contained in:
parent
10aa24acbe
commit
3e41274f45
21
src/main.cu
21
src/main.cu
@ -488,10 +488,10 @@ get_sample_color(RayF32 ray, Entity *entities, curandState *local_rand_state)
|
||||
Vec3F32 out = {0};
|
||||
|
||||
F32 current_attenuation = 1.0f;
|
||||
F32 attenuation_factor = 0.5f;
|
||||
Vec3F32 sample_pixel_color = vec3F32(0.0f, 0.0f, 0.0f);
|
||||
for(U32 bounce_idx = 0;
|
||||
//bounce_idx < MAX_DIFFUSE_DEPTH;
|
||||
bounce_idx < 1;
|
||||
bounce_idx < MAX_DIFFUSE_DEPTH;
|
||||
bounce_idx += 1)
|
||||
{
|
||||
|
||||
@ -524,14 +524,18 @@ get_sample_color(RayF32 ray, Entity *entities, curandState *local_rand_state)
|
||||
|
||||
if(hit_rec.hit)
|
||||
{
|
||||
// Paint entity
|
||||
// "Paint entity"
|
||||
// For a diffuse color we actually just update the attenuation here and
|
||||
// bounce rays around... Then when we are not hitting anything anymore we will sample
|
||||
// the background gradient and use the computed attenuation. Since the rays are
|
||||
// bouncing diffusely this will shade nicely.
|
||||
Vec3F32 rand_dir = rand_unit_vector_on_hemisphere_F32(local_rand_state, hit_rec.normal);
|
||||
current_attenuation = current_attenuation * 0.5f;
|
||||
current_attenuation = current_attenuation * attenuation_factor;
|
||||
|
||||
current_ray.origin = hit_rec.point;
|
||||
current_ray.direction = rand_dir;
|
||||
sample_pixel_color = add_V3F32(hit_rec.normal, vec3F32(1.0f, 1.0f, 1.0f));
|
||||
sample_pixel_color = scale_V3F32(0.5f, sample_pixel_color);
|
||||
//sample_pixel_color = add_V3F32(hit_rec.normal, vec3F32(1.0f, 1.0f, 1.0f));
|
||||
//sample_pixel_color = scale_V3F32(0.5f, sample_pixel_color);
|
||||
// debug
|
||||
//sample_pixel_color = vec3F32(1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
@ -547,6 +551,7 @@ get_sample_color(RayF32 ray, Entity *entities, curandState *local_rand_state)
|
||||
F32 blend = 0.5f*(unit_dir.y + 1.0f);
|
||||
|
||||
sample_pixel_color = lerp_V3F32(blend, white, light_blue);
|
||||
// Scale by the current attenuation for diffuse shading using background color
|
||||
sample_pixel_color = scale_V3F32(current_attenuation, sample_pixel_color);
|
||||
break;
|
||||
}
|
||||
@ -568,7 +573,11 @@ cuda_main(Entity *entities, Vec3F32 *pixelbuffer, curandState *rand_state)
|
||||
if(x < image.width && y < image.height)
|
||||
{
|
||||
|
||||
// NOTE! We need to pass this as a pointer to subsequent usage functions, in order
|
||||
// to update the random state on this thread, after each call to a distribution function.
|
||||
curandState local_rand_state = rand_state[idx];
|
||||
|
||||
|
||||
// We are adding all samples and then dividing by num samples to get the mean, so
|
||||
// we initialise the color for this pixel to black.
|
||||
// Loop over all pixel samples
|
||||
|
||||
BIN
timeBuild.ctm
BIN
timeBuild.ctm
Binary file not shown.
Loading…
Reference in New Issue
Block a user