PhongDirectionalLight.glsl 1.0 KB

1234567891011121314151617181920212223242526272829
  1. //! Function computes contribution of directional light source
  2. //! into global variables Diffuse and Specular (Phong shading).
  3. //! @param theId light source index
  4. //! @param theNormal surface normal
  5. //! @param theView view direction
  6. //! @param theIsFront front/back face flag
  7. //! @param theShadow shadow attenuation
  8. void occDirectionalLight (in int theId,
  9. in vec3 theNormal,
  10. in vec3 theView,
  11. in bool theIsFront,
  12. in float theShadow)
  13. {
  14. vec3 aLight = occLight_Position (theId);
  15. vec3 aHalf = normalize (aLight + theView);
  16. vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;
  17. float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
  18. float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
  19. float aSpecl = 0.0;
  20. if (aNdotL > 0.0)
  21. {
  22. aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
  23. }
  24. Diffuse += occLight_Diffuse (theId) * aNdotL * theShadow;
  25. Specular += occLight_Specular (theId) * aSpecl * theShadow;
  26. }