Advertisement
Guest User

Untitled

a guest
Apr 1st, 2025
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. vec3 PointLightFunc(PointLight pointLight, vec3 norm, vec3 viewDir){
  2. //ambient part
  3.  
  4. vec3 lightDir = normalize(vec3(pointLight.position) - FragPos);
  5. if(normalMapON == true){
  6. lightDir = normalize(TangentLightPos - TangentFragPos);
  7. }
  8. vec2 texCoords = TexCoords;
  9. if(parallaxmappingEnabled == true){
  10. texCoords = ParallaxMapping(TexCoords, viewDir);
  11. }
  12. if(texCoords.x > 1.0 || texCoords.y > 1.0 || texCoords.x < 0.0 || texCoords.y < 0.0){
  13. discard;
  14. }
  15. vec3 ambient = 0.1 * vec3(pointLight.color) * vec3(texture(texture_diffuse1, texCoords).rgb);
  16. //diffuse part
  17. float diff = max(dot(norm, lightDir), 0.0);
  18. vec3 diffuse = vec3(pointLight.color) * diff * vec3(texture(texture_diffuse1, texCoords).rgb);
  19.  
  20. //specular part
  21. vec3 reflectDir = reflect(-lightDir, norm);
  22. float spec = pow(max(dot(viewDir, reflectDir), 0.0), material.shininess);
  23. vec3 specular = vec3(pointLight.color) * spec * vec3(texture(texture_specular1, texCoords).rgb);
  24.  
  25. // attenuation
  26. float distance = length(vec3(pointLight.position) - FragPos);
  27. if(normalMapON == true){
  28. distance = length(TangentLightPos - TangentFragPos);;
  29. }
  30. float attenuation = 1.0 / (pointLight.constant + (pointLight.linear * distance) + (pointLight.quadratic * (distance * distance)));
  31.  
  32. ambient *= attenuation;
  33. diffuse *= attenuation;
  34. specular *= attenuation;
  35.  
  36. float shadow = ShadowCalculation(FragPos);
  37. vec3 lighting = ((ambient + (1.0 - shadow)) * (diffuse + specular));
  38. return lighting;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement