Question

Je tiens à rendre une scène qui contient une boîte et une source lumineuse ponctuelle à l'aide du système d'éclairage Phong. Voici les extraits de code pertinents pour mon calcul:

R3Rgb Phong(R3Scene *scene, R3Ray *ray, R3Intersection *intersection)
{
  R3Rgb radiance;
  if(intersection->hit == 0)
  {
    radiance = scene->background;
    return radiance;
  }

  ...
  // obtain ambient term
  ... // this is zero for my test

  // obtain emissive term
  ... // this is also zero for my test

  // for each light in the scene, obtain calculate the diffuse and specular terms
  R3Rgb intensity_diffuse(0,0,0,1);
  R3Rgb intensity_specular(0,0,0,1);
  for(unsigned int i = 0; i < scene->lights.size(); i++)
  {
    R3Light *light = scene->Light(i);
    R3Rgb light_color = LightIntensity(scene->Light(i), intersection->position);
    R3Vector light_vector = -LightDirection(scene->Light(i), intersection->position);

    // check if the light is "behind" the surface normal
    if(normal.Dot(light_vector)<=0)
      continue;

    // calculate diffuse reflection
    if(!Kd.IsBlack())
      intensity_diffuse += Kd*normal.Dot(light_vector)*light_color;

    if(Ks.IsBlack())
      continue;

    // calculate specular reflection
    ... // this I believe to be irrelevant for the particular test I'm doing

  }

  radiance = intensity_diffuse;
  return radiance;
}

R3Rgb LightIntensity(R3Light *light, R3Point position)
{
  R3Rgb light_intensity;
  double distance;
  double denominator;
  if(light->type != R3_DIRECTIONAL_LIGHT)
  {
    distance = (position-light->position).Length();
    denominator = light->constant_attenuation + 
                         (light->linear_attenuation*distance) + 
                         (light->quadratic_attenuation*distance*distance);
  }   

  switch(light->type)
  {
    ...

    case R3_POINT_LIGHT:
      light_intensity = light->color/denominator;
      break;

    ...
  }
  return light_intensity;
}

R3Vector LightDirection(R3Light *light, R3Point position)
{
  R3Vector light_direction;
  switch(light->type)
  {
    ...
    case R3_POINT_LIGHT:
      light_direction = position - light->position;
      break;
    ...
  }
  light_direction.Normalize();
  return light_direction;
}

Je crois que l'erreur doit être quelque part dans les deux LightDirection(...) ou fonctions LightIntensity(...) parce que quand je lance mon code à l'aide d'une source de lumière directionnelle, j'obtenir l'image rendue souhaitée (donc cela me conduit à croire que l'équation d'éclairage Phong est correct) . En outre, dans Phong (...), quand j'ai calculé le intensity_diffuse et pendant le débogage, je partageais light_color 10, j'obtenir une image résultante qui ressemblait plus à ce que je dois. Suis-je calculais correctement le light_color?

Merci.

Était-ce utile?

La solution

Retourné je n'avais aucune erreur. La « image finale » Je comparait mes résultats n'a pas été calculé correctement.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top