示例#1
0
文件: radiosity.c 项目: mattjakob/s3d
static Real formfactor(int i, int j, int n, Poly **p, Real *a)
{
  Vector3 vi, vj, vji, d;
  Real r2, ci, cj;
 
  vi = poly_centr(p[i]);
  vj = poly_centr(p[j]);
  vji = v3_sub(vi, vj);
  if ((r2 = v3_sqrnorm(vji)) < REL_EPS)
    return 0;    
  d = v3_scale(1.0/sqrt(r2), vji);
  if ((cj =  v3_dot(poly_normal(p[j]), d)) < REL_EPS)
    return 0;
  if ((ci = -v3_dot(poly_normal(p[i]), d)) < REL_EPS)
    return 0;
  if (vis_flag  && visible(n, p, vj, vji) < REL_EPS)
    return 0;
  return a[i] * ((cj * ci) / (PI * r2 + a[i])); 
}
示例#2
0
void SCANLINE::Compute_Poly_Normal()
{
    vector< vector<float> > temp_vertex_normal(world_vertex.size(),vector<float>(3));

    vector <float> temp_I_light(3);//light intensity
    I_light = temp_I_light;
    I_light[0] = 1.0;//R
    I_light[1] = 0.64;//G
    I_light[2] = 0;//B

    vector <float> poly_vector_1(3);
    vector <float> poly_vector_2(3);
    vector <float> poly_normal(3);
    vector <float> temp_H(3);
    //calculus H
    vector_summation(temp_H, vec_light,vec_view);
    for (int j=0; j<3 ;j++ )
        H_specular.push_back(temp_H[j]/vector_length(temp_H));
    ///---Intensity ambient----Ka*I
    for (int j=0; j<3 ;j++ )
        Intensity_ambient.push_back(K_ambient*I_light[j]);
    for(int i=0; i<(int)Poly.size(); i++)
    {//compute polygon normal
        vector_subtraction(poly_vector_1,
                           world_vertex[Poly[i][2]-1],
                           world_vertex[Poly[i][1]-1]);
        vector_subtraction(poly_vector_2,
                           world_vertex[Poly[i][2]-1],
                           world_vertex[Poly[i][3]-1]);
        //compute 2 vector on one polygon
        cross_product3D(poly_normal, poly_vector_1, poly_vector_2);
        //calculus cross product

        for(int j=1; j<(int)Poly[i][0]+1 ;j++)
        {//add normal of neibor polygon to vertex
            for (int p=0; p<3 ;p++ )
                temp_vertex_normal[Poly[i][j]-1][p] += poly_normal[p];
        }

    }
    for(int i=0; i<(int)temp_vertex_normal.size() ;i++ )
    {
        float temp_length = vector_length(temp_vertex_normal[i]);
        for (int j=0; j<3 ;j++ )
        {   //normalize the normal on vertex
            temp_vertex_normal[i][j] = temp_vertex_normal[i][j] / temp_length;

        }
    }
    vertex_normal = temp_vertex_normal;
    //vertex normals as average of surrounding neibor polygon's normal


}
示例#3
0
void SCANLINE::Compute_Poly_Normal()
{//compute polygon normal, vertices normal and illumination model
    vector< vector<float> >vertex_normal(world_vertex.size(),vector<float>(3));
    vector< vector<float> >temp_Light_Intensity//vertex intensity
            (world_vertex.size(),vector<float>(3));
    vector <float> I_light(3);//light intensity
    I_light[0] = 0.8;//R
    I_light[1] = 0.0;//G
    I_light[2] = 0.0;//B

    vector <float> Intensity_diffuse(3);
    vector <float> Intensity_specular(3);
    vector <float> Intensity_ambient(3);
    vector <float> poly_vector_1(3);
    vector <float> poly_vector_2(3);
    vector <float> poly_normal(3);
    vector <float> H(3);
    vector <float> temp_H(3);
    //calculus H
    vector_summation(temp_H, vec_light,vec_view);
    for (int j=0; j<3 ;j++ )
        H[j] = temp_H[j]/vector_length(temp_H);
    ///---Intensity ambient----Ka*I
    for (int j=0; j<3 ;j++ )
        Intensity_ambient[j] = K_ambient*I_light[j];
    for(int i=0; i<(int)Poly.size(); i++)
    {//compute polygon normal
        vector_subtraction(poly_vector_1,
                           world_vertex[Poly[i][2]-1],
                           world_vertex[Poly[i][1]-1]);
        vector_subtraction(poly_vector_2,
                           world_vertex[Poly[i][2]-1],
                           world_vertex[Poly[i][3]-1]);
        //compute 2 vector on one polygon
        cross_product3D(poly_normal, poly_vector_1, poly_vector_2);
        //calculus cross product
//        float temp_length = vector_length(poly_normal);
//        for (int j=0; j<3 ;j++ )//(normalized)
//        	poly_normal[j] = poly_normal[j]/ temp_length;

        for(int j=1; j<(int)Poly[i][0]+1 ;j++)
        {//add normal of neibor polygon to vertex
            for (int p=0; p<3 ;p++ )
                vertex_normal[Poly[i][j]-1][p] += poly_normal[p];
        }

    }
    for(int i=0; i<(int)vertex_normal.size() ;i++ )
    {
        float temp_length = vector_length(vertex_normal[i]);
        for (int j=0; j<3 ;j++ )
        {   //normalize the normal

            vertex_normal[i][j] = vertex_normal[i][j] / temp_length;
            ///----------Intensity diffuse----Kd*I*(NL)
            Intensity_diffuse[j] =
                K_diffuse*I_light[j]*dot_product3D(vertex_normal[i],vec_light);
            ///----------Intensity specular----Ks*I*(NH)^n
            Intensity_specular[j] =
                K_specular*I_light[j]*pow(dot_product3D(vertex_normal[i],H),8);

            //---------------sum of all intensity
            temp_Light_Intensity[i][j]= Intensity_diffuse[j] +
                Intensity_specular[j] + Intensity_ambient[j];
        }

    }
    Light_Intensity = temp_Light_Intensity;
    //Light_Intensity match to vertex index

}