Guest User

Untitled

a guest
Apr 11th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Default.vert
  2.  
  3. #version 330 core
  4.  
  5. uniform mat4 matModelView;
  6. uniform mat4 matProjection;
  7. uniform mat4 matWorld;
  8. uniform mat4 matModelWorld;
  9. uniform mat4 matFullTransform;
  10. uniform mat3 matNormal;
  11.  
  12. uniform vec3 uniLight0Position;
  13. uniform vec3 uniLight0Color;
  14.  
  15. in vec3 inPosition;
  16. in vec2 inTexCoord;
  17. in vec3 inNormal;
  18.  
  19. out mat3 vertObjectTransform;
  20.  
  21. out vec4 vertPosition;
  22. out vec2 vertTexCoord;
  23. out vec3 vertNormal;
  24. out vec3 vertEye;
  25. out vec3 vertLight;
  26.  
  27. void main()
  28. {
  29.     vec4 vertex = vec4(inPosition, 1.0);
  30.    
  31.     vertNormal      = normalize(matNormal * inNormal);
  32.    
  33.     //vertLight      = uniLight0Position.xyz;
  34.     vertLight      = vec3(0.0, 0.0, 1.0);
  35.     vertEye        = (matModelWorld * vertex).xyz; 
  36.    
  37.     vertTexCoord   = inTexCoord;
  38.    
  39.     gl_Position    = matFullTransform * vertex;
  40. }
  41.  
  42. // Default.frag
  43.  
  44. #version 330 core
  45.  
  46. in mat3 vertObjectTransform;
  47. in vec4 vertPosition;
  48. in vec2 vertTexCoord;
  49. in vec3 vertNormal;
  50. in vec3 vertEye;
  51. in vec3 vertLight;
  52.  
  53. uniform vec4 u_ColorAmbient;
  54. uniform vec4 u_ColorDiffuse;
  55. uniform vec4 u_ColorSpecular;
  56. uniform vec4 u_Specular;
  57.  
  58. uniform sampler2D uniTexDiffuse;
  59. uniform sampler2D uniTexNormal;
  60.  
  61. out vec4 fragColor;
  62.  
  63. vec4 Lighting(vec3 a_Normal, vec3 a_LightPos, vec3 a_Eye, vec3 a_Attenuation, float a_LightIntensity, float a_Shininess)
  64. {
  65.     vec3 N = normalize(a_Normal);
  66.     vec3 L = normalize(a_LightPos - a_Eye);
  67.     vec3 E = normalize(-a_Eye);
  68.     vec3 R = normalize(-reflect(L, N));
  69.  
  70.     float diffuse = max(dot(N, L), 0.0);
  71.    
  72.     float specular = pow(max(dot(R, E), 0.0), a_Shininess);
  73.    
  74.     float attenuation = a_LightIntensity;
  75.    
  76.     return (vec4(1.0, 1.0, 1.0, 1.0) * diffuse) + (vec4(1.0, 1.0, 1.0, 1.0) * specular * attenuation);
  77. }
  78.  
  79. vec4 NormalToColor(vec3 a_Normal)
  80. {
  81.     return vec4((a_Normal / 2.0) + 0.5, 1.0);
  82. }
  83.  
  84. vec3 ColorToNormal(vec4 a_Color)
  85. {
  86.     return (((a_Color - 0.5) * 2.0).xyz);
  87. }
  88.  
  89. void main()
  90. {
  91.     vec4 texel_diff = texture2D(uniTexDiffuse, vertTexCoord);
  92.     vec4 texel_normal = texture2D(uniTexNormal, vertTexCoord);
  93.    
  94.     //vec3 N = vertObjectTransform * vertNormal;
  95.     vec3 N = vertNormal;
  96.  
  97.     vec4 Final = Lighting(
  98.         N,
  99.         vertLight,
  100.         vertEye,
  101.         vec3(0.1, 0.1, 0.0),
  102.         1.0,
  103.         10.0
  104.     );
  105.  
  106.     fragColor = Final * texel_diff;
  107.     //fragColor = texel_diff;
  108. }
Add Comment
Please, Sign In to add comment