Advertisement
Guest User

Untitled

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