Advertisement
Guest User

fStart.glsl

a guest
May 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform float texScale;
  2. varying vec4 color;
  3. varying vec2 texCoord;  // The third coordinate is always 0.0 and is discarded
  4. varying vec4 position;
  5.  
  6.  
  7. uniform sampler2D texture;
  8.  
  9. uniform mat4 ModelView;
  10. uniform vec4 light1Pos;
  11. uniform vec3 AmbientProduct, DiffuseProduct, SpecularProduct;
  12. uniform float Shininess;
  13. uniform vec4 light2Pos;
  14. uniform vec3 light1Brightness;
  15. uniform vec3 light2Brightness;
  16. uniform float spread;
  17. uniform vec4 lightVec;
  18.  
  19.  
  20. void main()
  21. {
  22.     vec3 eyePos = (ModelView * position).xyz;
  23.  
  24.     vec3 Lvec = light1Pos.xyz - pos;
  25.  
  26.     vec3 L = normalize (Lvec);
  27.     vec3 L2 = normalize(light2Pos.xyz);
  28.     vec3 E = normalize (-eyePos);
  29.     vec3 H = normalize( L + E );
  30.     vec3 H2 = normalize( L2 + E);
  31.  
  32.  
  33.     vec3 N = normalize((ModelView*vec4(normal, 0.0)).xyz);
  34.  
  35.     vec3 ambient = light1Brightness * AmbientProduct;
  36.     vec3 ambient2 = light2Brightness * AmbientProduct;
  37.     float Kd = max(dot(L,N), 0.0);
  38.     vec3 diffuse = light1Brightness * Kd*DiffuseProduct;
  39.     float Kd2 = max(dot(L2, N), 0.0);
  40.     vec3 diffuse2 = light2Brightness * Kd2*DiffuseProduct;
  41.  
  42.  
  43.     float Ks = pow(max(dot(N,H), 0.0), Shininess);
  44.     vec3 specular = light1Brightness * Ks * SpecularProduct;
  45.     float Ks2 = pow(max(dot(N,H2), 0.0), Shininess);
  46.     vec3 specular2 = light2Brightness * Ks2 * SpecularProduct;
  47.  
  48.     if(dot(L,N) < 0.0) {
  49.     specular = vec3(0.0, 0.0, 0.0);
  50.     }
  51.     if(dot(L2,N) < 0.0) {
  52.     specular2 = vec3(0.0, 0.0, 0.0);
  53.     }
  54.  
  55.  
  56.  
  57.     vec3 globalAmbient = vec3(0.1, 0.1, 0.1);
  58.     float dropoff = sqrt(dot(Lvec, Lvec))/15 + 1;
  59.     color = vec4(globalAmbient + ((ambient1 + diffuse1) / len) + ambient2 + diffuse2, 1.0);
  60.  
  61.     //gl_FragColor = color * texture2D( texture,  texCoord * texScale );
  62.     gl_FragColor = color * texture2D( texture,  texCoord) + vec4((specular1 / len) + specular2, 1.0) ;
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement