PhongPointLight.glsl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. //! Function computes contribution of isotropic point 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 thePoint 3D position (world space)
  7. //! @param theIsFront front/back face flag
  8. void occPointLight (in int theId,
  9. in vec3 theNormal,
  10. in vec3 theView,
  11. in vec3 thePoint,
  12. in bool theIsFront)
  13. {
  14. vec3 aLight = occLight_Position (theId) - thePoint;
  15. float aDist = length (aLight);
  16. float aRange = occLight_Range (theId);
  17. float anAtten = occPointLightAttenuation (aDist, aRange, occLight_LinearAttenuation (theId), occLight_ConstAttenuation (theId));
  18. if (anAtten <= 0.0) return;
  19. aLight /= aDist;
  20. vec3 aHalf = normalize (aLight + theView);
  21. vec3 aFaceSideNormal = theIsFront ? theNormal : -theNormal;
  22. float aNdotL = max (0.0, dot (aFaceSideNormal, aLight));
  23. float aNdotH = max (0.0, dot (aFaceSideNormal, aHalf ));
  24. float aSpecl = 0.0;
  25. if (aNdotL > 0.0)
  26. {
  27. aSpecl = pow (aNdotH, occMaterial_Shininess (theIsFront));
  28. }
  29. Diffuse += occLight_Diffuse (theId) * aNdotL * anAtten;
  30. Specular += occLight_Specular(theId) * aSpecl * anAtten;
  31. }