Advertisement
Guest User

Frag shader

a guest
Apr 7th, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #version 400
  2.  
  3.  
  4. in vec4 vPosition;
  5. in vec3 vNormal;
  6. in vec2 vTexCoord;
  7.  
  8. //uniform float LowThreshold;
  9. //uniform float HighThreshold;
  10.  
  11. uniform sampler2D sampler0; // noise texture
  12.  
  13. layout( location = 0 ) out vec4 FragColor;
  14. layout( location = 1 ) out vec4 BrightColor;
  15.  
  16. vec3 PhongModel(vec4 eyePosition, vec3 eyeNorm)
  17. {
  18. vec3 s = normalize(vec3(vec3(-100,50,-100) - eyePosition)); // Ошибка
  19. vec3 v = normalize(-eyePosition.xyz);
  20. vec3 r = reflect(-s, eyeNorm);
  21. vec3 n = eyeNorm;
  22. vec3 ambient = vec3(0.1,0.5,0.1) * vec3(1,1,1);
  23. float sDotN = max(dot(s, n), 0.0f);
  24. vec3 diffuse = vec3(1.0) * vec3(1.0) * sDotN;
  25. vec3 specular = vec3(0.0f);
  26. float eps = 0.000001f; // add eps to shininess below -- pow not defined if second argument is 0 (as described in GLSL documentation)
  27. if (sDotN > 0.0f)
  28. specular = vec3(1.0) * vec3(1.0) * pow(max(dot(r, v), 0.0f), 15.0f + eps);
  29.  
  30.  
  31. return ambient + diffuse + specular;
  32. }
  33.  
  34. void main()
  35. {
  36. vec4 noise = texture( sampler0, vTexCoord );
  37. vec3 color = PhongModel(vPosition,vNormal);
  38. if(noise.a < 0.1) discard;
  39. if(noise.a > 0.5) discard;
  40. FragColor = vec4(color, 1.0f);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement