Path Tracer Reflection Question

Hi,

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!