コード例 #1
0
ファイル: fs-mesh.c プロジェクト: ifjorissen/mesh_refinement
void main() {

  
  vec3 diff = fwidth(bcoord);

  bool edge = (bcoord[0] < diff[0]*0.5 
	       || bcoord[1] < diff[1]*0.5 
	       || bcoord[2] < diff[2]*0.5);

  if (wires==1 && edge) {

    gl_FragColor = vec4(0.8,0.8,0.3,1.0);

  } else {

    float gloss = 0.5;     // brightness of highlight
    float shininess = 10;  // sharpness of highlight
    
    vec3 light_c = vec3(0.75, 0.7, 0.8);     // light color
    vec3 ambient_c = vec3(0.5, 0.6, 0.55);   // ambient scene color
    
    vec3 l = normalize(light - P);
    vec3 e = normalize(eye - P);
    vec3 r = -l + 2.0 * dot(l,n) * n;
    float p = shininess;
    float s = gloss;
    
    vec3 ambient = ambient_c * material_c;
    vec3 diffuse = light_c * material_c * max(dot(l,n),0.0);
    vec3 specular = light_c * s * max(dot(l,n),0.0) * pow(max(dot(e,r),0.0),p);
  
    gl_FragColor = vec4(ambient+diffuse+specular,1.0);
  }
}
コード例 #2
0
/*
rectanglular neighborhood of an arbitrary size
*/
vector<int>
MakeNeighborhood(const int* width,
				 int ndim,
				 const int* dims) 
{
	int i, j;
	vector<int> fwidth(ndim);
	int n = 1;
	for(i=0; i<ndim; ++i)
	{
		fwidth[i] = 2*width[i]+1;
		n *= fwidth[i];
	}
	vector<int> vindex;
	vector<int> vsub(ndim);
	for(i=0; i<n; ++i)
	{
		int m = i;
		bool bSelf = true;
		for(j=0; j<ndim; ++j)
		{
			vsub[j] = m % fwidth[j] - width[j];
			m /= fwidth[j];
			if(vsub[j] != 0)
			{
				bSelf = false;
			}
		}
		if(bSelf)
		{
			//self is not its neighbor
			continue;
		}

		int index=Sub2IndCentered(vsub,ndim,dims);
		if(index != 0)
		{
			vindex.push_back(index);
		}
	}
	return vindex;
}