www.pudn.com > AndreasHalm-src.zip > cube_edges.fragmentshader


// simple shader 
// uses the varyings below to calculate specular reflection 
// doesn't use the texture 0 at all, no bumpmapping 
// the cube map is multiplied into the diffuse channel 
 
// problem with ati (as of catalyst 4.6): if texture coordinates 
// are specified in the vertex shader but not referenced 
// in the fragment shader, the output will go mad. so we 
// just reference them (without doing anything with them) 
// and everything is allright. 
 
const vec4 AMBIENT = vec4( 0.1, 0.1, 0.1, 1.0 ); 
const vec4 SPECULAR = vec4( 1.0, 1.0, 1.0, 1.0 ); 
 
varying vec4 Cd; 
varying vec4 V_eye; 
varying vec4 L_eye; 
varying vec4 N_eye; 
varying vec3 eyespace_position; 
 
uniform samplerCube texCube; 
 
void main(void) 
{ 
  vec3 V = normalize(vec3(V_eye)); 
  vec3 L = normalize(vec3(L_eye)); 
  vec3 N = normalize(vec3(N_eye)); 
  float diffuse = clamp(dot(L, N), 0.0, 1.0); 
  vec3 H = normalize(L + V); 
  float specular = clamp(pow(dot(N, H), 20.0), 0.0, 1.0); 
  // cubemap stuff 
  vec3 u = normalize(eyespace_position); 
  vec3 texcube_coord = reflect(u,vec3(N_eye)); 
  vec4 texture_cubemap = textureCube(texCube,texcube_coord); 
  // the cubemap affects the diffuse lighting 
  vec4 color = AMBIENT + (Cd*diffuse*texture_cubemap) + (SPECULAR*specular); 
  // ati hack: access the texture coordinates 
  vec2 ati_hack = gl_TexCoord[0].st; 
  gl_FragColor = color; 
}