Path Tracer Reflection Question

Hi I’m working on the Optix Path Tracer sample that came with SDK 4.0 and I have few questions.

  1. First off I noticed path tracer in 3.9 and 4.0 are vastly different in the way the host programs are written. And there is no timeout option to be set (atleast very obviously) in the 4.0 version. Or is it set somewhere else unlike in the host program in 3.9 ?? Morever even in 3.9 when I change the time out from 2.0 to 10.0 to 100.0 to 200.0 to 1000.0 I don’t see big difference in any of the renders. Can someone point out to me if I’m missing something or how does it work? Please answer with respect to both 3.9 and 4.0!

2.Reflections in Path Tracer.
I just added another closest_hit_program to add a reflective material in 4.0 path tracer. It works fine with reflecting objects except that it wouldnt reflect emissive materials. I’m attaching the image here for reference! Please let me know if I’m missing something here as well and if I should do something else to get the reflection of the light as well on the reflective object!

Here as you can see the reflection of the illumination on the rectangle is seen on the sphere, but the reflection of the emissive material itself is not seen.

Thanks in advance!

  1. I think you may have misunderstood the purpose of the timeout. It’s primarily a defense against TDR (timeout detection and recovery), and it does this by periodically pausing work on the graphics card. It should have no effect on the appearance of your rendering. According to the documentation, rtContextSetTimeoutCallback is currently not implemented in OptiX 4.0.

  2. Can you show us your new closest hit program?


Thank you so much for your very quick reply!

Here’s the code for the reflective material!

RT_PROGRAM void Reflective()
float3 world_shading_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, shading_normal));
float3 world_geometric_normal = normalize(rtTransformNormal(RT_OBJECT_TO_WORLD, geometric_normal));
float3 ffnormal = faceforward(world_shading_normal, -ray.direction, world_geometric_normal);

float3 hitpoint = ray.origin + t_hit * ray.direction;

// Generate a reflection ray.  This will be traced back in ray-gen.
current_prd.origin = hitpoint;
float3 R = reflect(ray.direction, ffnormal);
current_prd.direction = R;

// NOTE: f/pdf = 1 since we are perfectly importance sampling lambertian
// with cosine density.
current_prd.attenuation = current_prd.attenuation * diffuse_color;
current_prd.countEmitted = false;

// Next event estimation (compute direct lighting).
unsigned int num_lights = lights.size();
float3 result = make_float3(0.0f);

for (int i = 0; i < num_lights; ++i)
	// Choose random point on light
	ParallelogramLight light = lights[i];
	const float z1 = rnd(current_prd.seed);
	const float z2 = rnd(current_prd.seed);
	const float3 light_pos = light.corner + light.v1 * z1 + light.v2 * z2;

	// Calculate properties of light sample (for area based pdf)
	const float  Ldist = length(light_pos - hitpoint);
	const float3 L = normalize(light_pos - hitpoint);
	const float  nDl = dot(ffnormal, L);
	const float  LnDl = dot(light.normal, L);

	// cast shadow ray
	if (nDl > 0.0f && LnDl > 0.0f)
		PerRayData_pathtrace_shadow shadow_prd;
		shadow_prd.inShadow = false;
		// Note: bias both ends of the shadow ray, in case the light is also present as geometry in the scene.
		Ray shadow_ray = make_Ray(hitpoint, L, pathtrace_shadow_ray_type, epsilon, Ldist - epsilon);
		rtTrace(top_object, shadow_ray, shadow_prd);

		if (!shadow_prd.inShadow)
			const float A = length(cross(light.v1, light.v2));
			// convert area based pdf to solid angle
			const float weight = nDl * LnDl * A / (M_PIf * Ldist * Ldist);
			result += light.emission * weight;

current_prd.radiance = result;


Here’s the code for the emissive material!

RT_PROGRAM void diffuseEmitter()
current_prd.radiance = current_prd.countEmitted ? emission_color : make_float3(0.f);
current_prd.done = true;

Thanks in advance again!


OK. So I made a change to the closest_hit_program of the emissive material and I got the reflection of it working!

This is how the code looks now!

RT_PROGRAM void diffuseEmitter()
current_prd.radiance = emission_color;
current_prd.done = true;

Can you tel if this is the right way of getting the reflection of the light?

Thanks again!