Advertisement
Smiechu

Untitled

Mar 30th, 2023
996
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #version 330 core
  2. out vec4 FragColor;
  3.  
  4. uniform vec4 ourColor;
  5. in vec2 TexCoord;
  6.  
  7. uniform sampler2D texture1;
  8. uniform sampler2D texture2;
  9. uniform float mixer;
  10.  
  11. uniform vec3 eyePos;
  12. uniform vec3 lightDir;
  13. vec3 lightPos = vec3(-500.0, 0.0, 0.0);
  14.  
  15. in vec3 normal;
  16. in vec3 position;
  17.  
  18. float directionalLight(vec3 lightDir, vec3 normal) {
  19.     float f = dot(normalize(normal), -lightDir);
  20.     if (f > 0)
  21.         return f;
  22.     else
  23.         return 0.0;
  24. }
  25.  
  26. float pointLight(vec3 lightPos, vec3 normal, vec3 position) {
  27.     vec3 lightDelta = position - lightPos;
  28.     vec3 lightDir = normalize(lightDelta);
  29.  
  30.     return directionalLight(lightDir, normal);
  31.  
  32.     // fajne rzeczy
  33.     // vec3 distance = length(lightDelta);
  34.     //  float attenuation = 0.1 * distance + 0.001 * distance * distance;
  35.     // return directionalLight(lightDir, normal) / attenuation;
  36. }
  37.  
  38. float specularLight(vec3 lightPos, vec3 normal, vec3 position, vec3 eyePos, float shininess) {
  39.     vec3 lightDelta = position - lightPos;
  40.     vec3 lightDir = normalize(lightDelta);
  41.  
  42.     float f = dot(normalize(normal), -lightDir);
  43.     if (f < 0)
  44.         return 0.0;
  45.  
  46.     vec3 viewDir = -normalize(eyePos - position);
  47.     vec3 reflectDir = reflect(-lightDir, normal);
  48.  
  49.     float s = pow(
  50.         max(0.0, dot(viewDir, reflectDir)),
  51.         shininess
  52.     );
  53.     return s;
  54. }
  55.  
  56. void main()
  57. {
  58.     float light = directionalLight(lightDir, normal);
  59.     vec3 color = vec3(light, 0.0, 0.0);
  60.  
  61.     float light2 = pointLight(lightPos, normal, position);
  62.     vec3 color2 = vec3(0.0, light2, 0.0);
  63.  
  64.     float light3 = specularLight(lightPos, normal, position, eyePos, 256.0);
  65.     vec3 color3 = vec3(light3, light3, light3);
  66.  
  67.     //FragColor = vec4(1.0, 0.0, 0.0, 1.0);
  68.     FragColor = vec4(color3 + color2 * 0.5, 1.0);
  69.     //FragColor = mix(texture(texture1, TexCoord),
  70.     //              texture(texture2, vec2(TexCoord.x, TexCoord.y)), mixer);
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement