Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // Simple Diffuse lighting Shader
  2. // Fragment Shader
  3. #version 130
  4.  
  5. // INTERPOLOWANE WEJŚCIE z VS (varying)
  6. smooth in vec4 vVaryingColor;
  7.  
  8.  
  9. // PARAMETRY OBIEKTU
  10. uniform vec4 Light0Ambient; // składowa ambient światła 0
  11. uniform vec4 Light0Diffuse; // składowa diffuse światła 0
  12. uniform vec4 Light0Specular; // składowa specular światła 0
  13. uniform vec4 MaterialAmbient; // składowa ambient materiału
  14. uniform vec4 MaterialDiffuse; // składowa diffuse materiału
  15. uniform vec4 MaterialSpecular; // składowa diffuse materiału
  16.  
  17. in vec3 vVaryingNormal;
  18. in vec3 vVaryingLightDir;
  19.  
  20. // WYJŚCIE
  21. out vec4 vFragColor; // kolor fragmentu
  22.  
  23. void main( void )
  24. {
  25. vFragColor = vVaryingColor; // przepisanie interpolowanego koloru
  26.  
  27. vec3 ambientColor = Light0Ambient.rgb * MaterialAmbient.rgb; // składowa ambient
  28.  
  29. float diffuseIntensity = max( 0.0, dot( normalize( vVaryingNormal ), normalize( vVaryingLightDir ) ) ); // intensywność oświetlenia na podstawie prawa Lamberta
  30. vec3 diffuseColor = diffuseIntensity * Light0Diffuse.rgb * MaterialDiffuse.rgb; // kolor światła rozproszonego na obiekcie
  31.  
  32. vFragColor.rgb = ambientColor + diffuseColor;
  33. vFragColor.a = MaterialDiffuse.a;
  34.  
  35. vec3 vReflection = normalize( reflect( -vVaryingLightDir, vVaryingNormal ) );
  36. float specularIntensity = max( 0.0, dot( normalize( vVaryingNormal ), normalize ( vReflection ) ) );
  37. float fSpecular = pow(specularIntensity, 128.0);
  38. vec3 specularColor = fSpecular * Light0Specular.rgb * MaterialSpecular.rgb;
  39.  
  40. if(diffuseIntensity > 0.0)
  41. vFragColor.rgb += specularColor;
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement