Logo Search packages:      
Sourcecode: yafray version File versions

color_t areaLight_t::illuminate ( renderState_t &  state,
const scene_t &  s,
const surfacePoint_t  sp,
const vector3d_t &  eye 
) const [virtual]

See also:
light_t

Implements light_t.

Definition at line 93 of file arealight.cc.

References color, direction, from, surfacePoint_t::getOrigin(), surfacePoint_t::getShader(), guessLight(), jit, surfacePoint_t::N(), surfacePoint_t::Ng(), surfacePoint_t::P(), points, pow, and samples.

{
      vector3d_t cdir=from-sp.P();
      color_t resul(0,0,0);
      if(dummy) return resul;
      vector3d_t dir,L;
      vector3d_t edir=eye;
      edir.normalize();
      vector3d_t N=FACE_FORWARD(sp.Ng(),sp.N(),edir);
      const shader_t *sha= sp.getShader();
      
      dir=sp.P()-from;
      dir.normalize();
      PFLOAT plane_at=(sp.P()-from)*direction;

      if(plane_at<=0)
      {
            energy_t ene(direction, 0*color);
            return sha->fromLight(state,sp,ene,eye);
      }
      
      const void *oldorigin=state.skipelement;
      state.skipelement=sp.getOrigin();
      
      if (samples==1) {
            point3d_t sampleP = corner + toX*ourRandom() + toY*ourRandom();
            L = sampleP-sp.P();
            if ((L*N)<0) return color_t(0.0);
            if (!s.isShadowed(state, sp, sampleP)) {
                  dir = L;
                  dir.normalize();
                  energy_t ene(dir, (pow*color)/(L*L));
                  resul += sha->fromLight(state, sp, ene, eye);
            }
            state.skipelement = oldorigin;
            return (plane_at*resul);
      }
      
      int status=guessLight(state,s,sp,N);
      switch(status)
      {
            case PENUMBRA:
                  for(int i=0;i<samples;++i)
                  {
                        PFLOAT dish=ourRandom()-0.5;
                        PFLOAT disv=ourRandom()-0.5;
                        point3d_t sampleP=points[i]+jit[i].first*dish+jit[i].second*disv;
                        L=sampleP-sp.P();
                        if((L*N)<0) continue;
                        if(!s.isShadowed(state,sp,sampleP))
                        {
                              dir=L;
                              dir.normalize();
                              energy_t ene(dir, (pow*color)/(L*L));
                              resul=resul+sha->fromLight(state,sp,ene,eye);
                        }
                  }
                  state.skipelement=oldorigin;
                  return (plane_at*resul/ ((CFLOAT)samples));
            case LIGHT:
                  for(int i=0;i<samples;++i)
                  {
                        L=points[i]-sp.P();
                        dir=L;
                        dir.normalize();
                        energy_t ene(dir, (pow*color)/(L*L));
                        resul=resul+sha->fromLight(state,sp,ene,eye);
                  }
                  state.skipelement=oldorigin;
                  return (plane_at*resul/ ((CFLOAT)samples));
            case SHADOW:
                  energy_t ene(direction, 0*color);
                  state.skipelement=oldorigin;
                  return sha->fromLight(state,sp,ene,eye);
      }
      state.skipelement=oldorigin;
      energy_t ene(direction, 0*color);
      return sha->fromLight(state,sp,ene,eye);
}


Generated by  Doxygen 1.6.0   Back to index