title: GLSL shader for glossy specular reflections on an cubemapped surface
body: <p>I wrote a shader for environmental cubemapping</p>
  
  <p><strong>*Vertex shader *</strong></p>
  
  <pre><code>varying vec3 Normal;
  varying vec3 EyeDir;
  uniform samplerCube cubeMap;
  
  void main()
  {
          gl_Position = gl_ModelViewProjectionMatrix*gl_Vertex;
          Normal = gl_NormalMatrix * gl_Normal;
          EyeDir = vec3(gl_ModelViewMatrix * gl_Vertex);
  }
  </code></pre>
  
  <p><strong>*Fragment shader *</strong></p>
  
  <pre><code>varying vec3 Normal;
  varying vec3 EyeDir;
  
  uniform samplerCube cubeMap;
  
   void main(void)
   {
      vec3 reflectedDirection = normalize(reflect(EyeDir, normalize(Normal)));
      reflectedDirection.y = -reflectedDirection.y;
      vec4 fragColor = textureCube(cubeMap, reflectedDirection);
      gl_FragColor = fragColor;
  }
  </code></pre>
  
  <p>This is the classical result:
  <img src="https://i.stack.imgur.com/7suT0.png" alt="http://braintrekking.files.wordpress.com/2012/07/glsl_cubemapreflection.png?w=604&amp;h=466">
  Now I want to add some specular white highlight in order to obtain a more glossy effect, like motherpearl. How is it possible to add this kind of highlight? Like the one in this image Should I sum a specular component to  <code>gl_FragColor</code>?
  A first attempt is to compute specular reflection in vertex shader</p>
  
  <pre><code>vec3 s = normalize(vec3(gl_LightSource[0].position - EyeDir));
  vec3 v = normalize(EyeDir);
  vec3 r = reflect( s, Normal );
  vec3 ambient = vec3(gl_LightSource[0].ambient*gl_FrontMaterial.ambient);
  
  float sDotN = max( dot(s,Normal), 0.0 );
  vec3 diffuse = vec3(gl_LightSource[0].diffuse * gl_FrontMaterial.diffuse * sDotN);
  vec3 spec = vec3(0.0);
  if( sDotN &gt; 0.0 )
      spec = gl_LightSource[0].specular * gl_FrontMaterial.specular * pow( max( dot(r,v), 2.0 ), gl_FrontMaterial.shininess );
  
  LightIntensity = 0*ambient + 0*diffuse +  spec;
  </code></pre>
  
  <p>and to multiply it to <code>gl_FragColor</code> but the effect I obtain is not convincing.</p>
  
  <p>Someone has idea how to do it?</p>