Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: Fonix on Sep 4th, 2012  |  syntax: OpenGL Shading  |  size: 2.31 KB  |  views: 39  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //Normal texture and lighting shader
  2. //vert
  3. attribute vec4 position;
  4. attribute vec3 normal;
  5.  
  6. varying vec3 vertexNormal;
  7.  
  8. uniform mat4 modelViewProjectionMatrix;
  9. uniform mat3 normalMatrix;
  10.  
  11. uniform vec3 lightPosition;
  12. uniform vec4 lightDiffuseColour;
  13. uniform vec4 lightSpecularColour;
  14. uniform vec4 lightlightAmbientColour;
  15.  
  16. uniform vec3 lightHalfVector;
  17.  
  18. attribute vec2 TexCoordIn;
  19. varying vec2 TexCoordOut;
  20.  
  21. uniform vec4 numberColour;
  22. uniform vec4 faceColour;
  23.  
  24. void main()
  25. {
  26.     vec3 eyeNormal = normalize(normalMatrix * normal);
  27.    
  28.     float nDotVP = max(0.0, dot(eyeNormal, normalize(lightPosition)));
  29.    
  30.     vertexNormal = normalize(normalMatrix * normal);
  31.    
  32.     TexCoordOut = TexCoordIn;
  33.    
  34.     gl_Position = modelViewProjectionMatrix * position;
  35. }
  36.  
  37. //##################################
  38. //frag
  39.  
  40. varying highp vec3 vertexNormal;
  41.  
  42. uniform highp vec3 lightPosition;
  43. uniform highp vec4 lightDiffuseColour;
  44. uniform highp vec4 lightSpecularColour;
  45. uniform highp vec4 lightAmbientColour;
  46.  
  47. uniform highp vec3 lightHalfVector;
  48.  
  49. varying lowp vec2 TexCoordOut;
  50. uniform sampler2D Texture;
  51.  
  52. uniform highp vec4 numberColour;
  53. uniform highp vec4 faceColour;
  54.  
  55. void main()
  56. {
  57.    
  58.     highp float diffuseValue0 = max(dot(vertexNormal, normalize(lightPosition)), 0.0);
  59.     highp vec4 diffuse_color0 = lightDiffuseColour;
  60.    
  61.     highp vec4 specular_material = vec4(1.0,1.0,1.0,1.0);
  62.    
  63.     highp vec4 specular_color0 = lightSpecularColour * pow(max(dot(vertexNormal, lightHalfVector), 0.0) , 15.0);
  64.    
  65.     lowp vec3 white = vec3(0.8, 0.8, 0.8);
  66.    
  67.     if(all(greaterThan(texture2D(Texture, TexCoordOut).rgb , white))){
  68.        
  69.         gl_FragColor = faceColour * (diffuseValue0 * diffuse_color0) + specular_color0 + lightAmbientColour;
  70.     }
  71.     else {
  72.        
  73.         gl_FragColor = numberColour * (diffuseValue0 * diffuse_color0) + specular_color0 + lightAmbientColour;
  74.     }
  75. }
  76.  
  77. //###############################
  78. //Outline vert Shader
  79.  
  80. attribute vec4 position;
  81. uniform mat4 modelViewProjectionMatrix;
  82. uniform vec4 outlineColour;
  83.  
  84. void main()
  85. {
  86.     vec4 scaled = position*1.15;
  87.    
  88.     gl_Position = modelViewProjectionMatrix * scaled;
  89. }
  90.  
  91.  
  92. //##############################
  93. //frag
  94.  
  95. uniform highp vec4 outlineColour;
  96.  
  97. void main()
  98. {
  99.     gl_FragColor = outlineColour;
  100. }